dhatim / fastexcel

Generate and read big Excel files quickly
Other
684 stars 122 forks source link

new feature: name a cell range and few minor fixes #150

Closed dorssar closed 3 years ago

dorssar commented 3 years ago

The new functionality of naming a Range can be used like this:

ws.range(0, 0, 0, 10).setName("header);

IMPORTANT: name of a cell range can only contain letters, numbers and underscore. (This is an external limitation - LibreOffice Calc also doesn't allow any other characters.)

Besides named ranges, there's a fix for LibreOffice Calc to make it recognize the autofilter if it's been set in the generated XLSX document. LibreOffice requires a specifically named range "_xlnm._FilterDatabase" to recognize the autofilter in generated documents. This bug has been reported multiple times to bugzilla, however, many years have passed and no one had changed the way it works.

This way, by defining a named range, fastexcel will be able to generate documents with autofilter that will be opened properly in LibreOffice Calc. The oddly named range will, ofcourse, also exist when opened in Google Sheets and Excel, but it will just be an extra defined named range.

There were a few minor mistakes from my side earlier, where the localSheetId was hardcoded to 0 - now the worksheet index is properly assigned. Also, when sheetname had a space or another non-alphabetical characted, the definitions were not correctly written to xlsx - sheetname needs to be surrounded with \' or - in other words - '