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 title to worksheet #240

Closed
NandoMB opened this issue Dec 9, 2016 · 4 comments · May be fixed by ABenassi87/exceljs#5
Closed

Add title to worksheet #240

NandoMB opened this issue Dec 9, 2016 · 4 comments · May be fixed by ABenassi87/exceljs#5
Labels

Comments

@NandoMB
Copy link

NandoMB commented Dec 9, 2016

Hi man, first of all, I'd like to congratulate you for your awesome project!

I'd like to know if is possible to insert an "title" for my worksheet, above of columns headers?
Something like the green cell on image bellow:

screen shot 2016-12-09 at 15 51 54

Thank you for your attention 😃

@AdamInTheOculus
Copy link

AdamInTheOculus commented Feb 23, 2017

Hey @NandoMB, if I understand your issue correctly do the following to give your worksheets a title:

I would store the worksheet title in a variable and later assign that as your My Title cell value.

const wsTitle = 'Nando Title'; // Store our title in a variable
const ws = workbook.addWorksheet(wsTitle); // Create our worksheet with the desired title
...
ws.getCell(`A1`).value = wsTitle; // Assign title to cell A1 -- THIS IS WHAT YOU'RE LOOKING FOR.
ws.mergeCells('A1:G1'); // Extend cell over all column headers
ws.getCell(`A1`).alignment = { horizontal: 'center' }; // Horizontally center your text
... 

Let me know if that helps at all.

@kurt343
Copy link

kurt343 commented Aug 15, 2017

Note for anyone reading this. Microsoft Excel has a max length on worksheet titles of 30 chars, and, the following chars are invalid:

\ / ? * [ ] :

@jwmann
Copy link
Contributor

jwmann commented Nov 27, 2017

This doesn't work.
If you do this before columns are defined then columns overwrite these cells.
If you do this after columns are defined, then it overwrites the columns.

The problem is needing to shift/ set a start row line to start the columns at or something.
This is something I'm also trying to figure out.

@jwmann
Copy link
Contributor

jwmann commented Nov 27, 2017

#433 Solves this for me.

The trick is to not set a header properties for the columns themselves.
You add a row with the values of columns where you want them to start and add the data after that row.

As long as you set the columns with the correct key it will map out accordingly.

sheet.columns = [ {key: 'myFull'}, {key: 'displayedValues'}, {key: 'goHere'} ]
sheet.addRow(5).values = [ 'My Full', 'Displayed Values', 'Go Here']
sheet.addRows( [
  { myFull: 'Text', displayedValues: 1234, goHere: 'Foobar' },
  { myFull: 'Text', displayedValues: 1234, goHere: 'Foobar' },
  { myFull: 'Text', displayedValues: 1234, goHere: 'Foobar' },
  { myFull: 'Text', displayedValues: 1234, goHere: 'Foobar' }
]);

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

Successfully merging a pull request may close this issue.

5 participants