Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hidden columns and rows #588

Closed
pascaldls opened this issue Mar 9, 2017 · 6 comments
Closed

Hidden columns and rows #588

pascaldls opened this issue Mar 9, 2017 · 6 comments
Labels

Comments

@pascaldls
Copy link

Hi is there any way i could exclude hidden columns and rows from a workbook.
If options not available is there any way i could know if columns or row is hidden in the workbook.
Thanks for taking the time.

@SheetJSDev
Copy link
Contributor

@pascaldls we just pushed a change, to show up in the next release, that will expose hidden property on row and column objects. So for a given worksheet:

  • !!((worksheet['!rows']||[])[R]||{}).hidden is true if row R is hidden and false otherwise.
  • !!((worksheet['!cols']||[])[C]||{}).hidden is true if col C is hidden and false otherwise.

If you are wondering why the expression looks convoluted, the rows and cols arrays are only generated if the file specifies any row or column metadata. If the given row/column uses the default size and is visible, there will be no object for the corresponding row.

The relevant docs:

@robinmackenzie
Copy link

Hi @SheetJSDev - please can you advise if the change is in v0.10.1 ?

@SheetJSDev
Copy link
Contributor

@robinmackenzie it landed in 0.9.13, so yes :)

On the read side, set the option cellStyles:true in the options argument to XLSX.read or XLSX.readFile. The two (admittedly messy) expressions above should work, but we are going to wrap some of that logic in a utility function.

On the write side, add a '!cols' or '!rows' object to the worksheet to set the visibility:

// to hide row R
if(!worksheet['!rows']) worksheet['!rows'] = [];
if(!worksheet['!rows'][R]) worksheet['!rows'][R] = {};
worksheet['!rows'][R].hidden = true;

// to hide col C
if(!worksheet['!cols']) worksheet['!cols'] = [];
if(!worksheet['!cols'][C]) worksheet['!cols'][C] = {};
worksheet['!cols'][C].hidden = true;

@robinmackenzie
Copy link

@SheetJSDev - I was missing the cellStyles option when reading the book.

The expressions note above are now returning the expected values.

Thanks very much - much appreciated.

@futurist
Copy link
Contributor

I've use below code:

var xlsParseOptions = {
  cellStyles: true, 
  cellFormula: true, 
  cellDates: true,
  cellNF: true,
}
var WB = XLSX.readFile(workbook, xlsParseOptions)

But the WB.Sheets['sheetName']['!cols'] array not contain any hidden info, I've tried several times, the column did hidden in excel, but the hidden info just lost. Anything wrong here?

@Malex
Copy link

Malex commented Feb 5, 2019

Hi, not sure if opening another issue or updating this one.
I am currectly wrinting a !cols object before writing my file, the object is correctly istantiated and valued, and yet my excel file is not formatted corretly.
Is it because I'm using the old 2004 format (xls)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants