0

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')
Matt Ellen
  • 11,268
  • 4
  • 68
  • 90
Bijan
  • 7,737
  • 18
  • 89
  • 149

1 Answers1

1

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.

chfw
  • 4,502
  • 2
  • 29
  • 32
  • I keep getting `pyexcel.exceptions.UnknownParameters: Please check if there were typos in function parameters: {'file_name': '<>'}. Otherwise unrecognized parameters were given.` – Bijan Feb 21 '18 at 19:08
  • Reproduced here. Checking it – chfw Feb 22 '18 at 22:23
  • 1
    My apologies. I have updated the code above. I, myself was confused about the `source_library` and `library`. `source_library` meant to be the data source library, while `library` meant to be io library. – chfw Feb 22 '18 at 22:59