Bijan
Bijan

Reputation: 8648

Convert XLSX to XLS and Preserve hidden rows

I am using the Python solution from Here to convert an XLSX file to XLS however this ignores the rows I already have hidden. Is there a way to have this only copy the rows that are visible in my source Xlsx file?

Here is my code:

import pyexcel as p
p.save_book_as(file_name='Source.xlsx', dest_file_name='Destination.xls')

Upvotes: 0

Views: 1789

Answers (1)

chfw
chfw

Reputation: 4592

Short Answer

Please use skip_hidden_row_and_column=True as in pyexcel-xlsx test code:

p.save_book_as(file_name='Source.xlsx', 
               library='pyexcel-xlsx',  # <--- note 1
               skip_hidden_row_and_column=True,  # <--- note 2
               dest_file_name='Destination.xls')

To get pyexcel-xlsx, you can use pip:

pip install pyexcel-xlsx

Explanation/Long Answer

  1. pyexcel-xls(xlrd) does not support hidden rows for xlsx format but xls. That's why note 1 ask pyexcel to use pyexcel-xlsx to read the xlsx file instead.

  2. And this flag was noted in pyexcel-xlsx README, True means to ignore hidden rows.

Why library? It is specific for save_as, save_book_as, isave_as and isave_book_as. In these functions, a reader and a writer were involved to finish the function. library tells pyexcel to use a specific library to read a file whereas dest_library tells pyexcel to write a file.

These have been documented, for example save_as and please find library in the page.

Upvotes: 1

Related Questions