I have written a program to download data from an API, and parse the json response into an excel (xlsx) sheet in multiple worksheets.
However, depending on user's choice on what attributes to be saved, there can be empty columns in the excel. Is there any way to delete empty columns from all worksheets in the excel file?
I can do this through pandas, however, that is not possible in this case, as pandas and openpyxl library breaks the GUI based on the python script?
Is there any other way to implement this?
Edit:
Current Output:
+----------+----------+--+----------+----------+
| Column A | Column B | | Column D | Column E |
+----------+----------+--+----------+----------+
| A1 | B1 | | D1 | |
| A2 | | | D2 | |
| A3 | B3 | | | E3 |
+----------+----------+--+----------+----------+
Desired Output:
+----------+----------+----------+----------+
| Column A | Column B | Column D | Column E |
+----------+----------+----------+----------+
| A1 | B1 | D1 | |
| A2 | | D2 | |
| A3 | B3 | | E3 |
+----------+----------+----------+----------+
Current Code for removing blank columns:
excel_file = pd.ExcelFile(path, engine='openpyxl')
df = pd.read_excel(excel_file,header=None, sheet_name=None)
writer = pd.ExcelWriter(finalpath,engine='openpyxl')
for key in df:
sheet= df[key].dropna(how="all").dropna(1,how="all")
sheet.to_excel(writer, key,index=False, header=False )
writer.save()
Need to replace this code with something which don't references pandas library.
question from:
https://stackoverflow.com/questions/65599337/removing-blank-columns-from-an-excel-file 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…