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

Add style to column causes it to be hidden #458

Open
AJamesPhillips opened this issue Dec 15, 2017 · 7 comments
Open

Add style to column causes it to be hidden #458

AJamesPhillips opened this issue Dec 15, 2017 · 7 comments
Labels

Comments

@AJamesPhillips
Copy link
Contributor

Version: 0.8.0

const Excel = require('exceljs')

const workbook = new Excel.stream.xlsx.WorkbookWriter({
    filename: 'demo_hidden_columns_bug.xlsx', useStyles: true
})

const worksheet = workbook.addWorksheet('sheetName')
worksheet.columns = [
    { header: 'Header One' },
    { header: 'Header Two', style: { numFmt: '#,##0' } },
    { header: 'Header Three', style: { numFmt: 'General' }, hidden: false },
    { header: 'Header Four', width: 20 }
]
const dataRow = [ 1, 2, 3, 4 ]
worksheet.addRow(dataRow).commit()
worksheet.commit()

workbook.commit()

console.log('completed')

Columns 1 and 4 will be visible but 2 and 3 will be hidden.

@AJamesPhillips
Copy link
Contributor Author

AJamesPhillips commented Jan 18, 2018

No the "fix" I submitted doesn't actually work. If width is set to undefined but the style attribute is still present this still results in the column being hidden when the file is exported. This would make sense being that the function I modified was parseOpen and not the function to export the file.

@guyonroche sorry I don't think I have permission to reopen this issue. I can't figure out what attribute in the xml is causing the column to be hidden (the hidden column attribute is set to false, and width is undefined).

@qo4on
Copy link

qo4on commented Nov 28, 2018

@AJamesPhillips, I tried:
sheet.getColumn('D').numFmt = '# ##0.00';
And column became hidden. Do you know how to fix that?

@AJamesPhillips
Copy link
Contributor Author

AJamesPhillips commented Nov 28, 2018

I can't remember now @qo4on . Looks like I set the width too as I can see in the code I did something like this:

const worksheet = workbook.addWorksheet(`some worksheet name`)
const columnDefinitions = [
  { header: 'field 1' },
  { header: 'field 2', style: { numFmt: '#,##0.00' }, width: 30 },
]
worksheet.columns = columnDefinitions

Does that fix it for you?

@qo4on
Copy link

qo4on commented Dec 8, 2018

Thank you @AJamesPhillips, but I don't know how adapt your code for setting width of each individual column.

@jonimoas
Copy link

jonimoas commented Jan 24, 2019

Fell on exactly the same issue. I can confirm @AJamesPhillips 's solution. When altering the style, you have to explicitly set the width attribute or else the column will be hidden. This problem affects ONLY microsoft office and not LibreOffice, so i assume that each application interprets "undefined" differently when a style is present.

@Siemienik Siemienik reopened this Jan 25, 2019
@Siemienik Siemienik added the bug label Jan 25, 2019
@MohdVara
Copy link

In files row-xform.js(80) and col-xform.js(52), I have added extra if clause on the code. It works for me.
if (node.attributes.hidden != 'false') { model.hidden = true; }
It seems that the library set the model if there are styles to
{... hidden: 'false' }
thus causing the hidden row and cols issue.
I'm new to this. So, I'm not sure what factors that I'm not considering with adding this to the part of the code. I also don't know how to do a git pull request. Do let me know my current hack is a good or bad solution. Appreciate it, Thanks.

@Siemienik
Copy link
Member

@MohdVara that's great that you find a solution :)

If could I ask you to create pull request with this fixation? 👍

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

5 participants