0

I have an Excel spreadsheet which is converted to a DataFrame using StyleFrame to keep color formatting. When I convert this DataFrame back to an Excel spreadsheet, a few columns are already hidden by default. This is my code:

import openpyxl
import pandas as pd
from StyleFrame import StyleFrame, Styler, utils  
sf = StyleFrame.read_excel("aaaa\\aaaa\\cdddd .xlsx",sheet_name = 2, read_style=True, header = None)
ew = StyleFrame.ExcelWriter('aaaa\\abbbbbb2.xlsx')
sf.to_excel(excel_writer = ew, header = False, index = False).save()

How do do make sure these columns are not hidden when opening the spreadsheet in Excel.

user2653663
  • 2,818
  • 1
  • 18
  • 22
  • Welcome to StackOverflow. What is your code doing that is unexpected? I'm not sure what your question is. – rajah9 Jan 29 '20 at 11:44
  • Are you sure? what version of StyleFrame are you using? I can't reproduce this. If I'm reading a sheet with hidden columns and immediately saving it, the column is **not** hidden in the new file. – DeepSpace Jan 29 '20 at 15:23

1 Answers1

0

Excel file :

df.to_excel('demofile.xlsx',index=False)

import openpyxl

py = openpyxl.load_workbook('demofile.xlsx')
exlsheet = py.get_sheet_by_name('yoursheetName')

Checking Column

for col in exlsheet.columns:
  if not col[2].value:
    exlsheet.column_dimensions[col[2].column].hidden = True

Save your file

py.save('modifiedfile.xlsx')
Running Rabbit
  • 2,634
  • 15
  • 48
  • 69