question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to fill in different color headers and rows

See original GitHub issue

Hello guys, I was very interested in this library and did a lot of work with it, at the moment I’m stuck with how to fill out the headings and rows with different colors with a loop. This is my code, where I find all cells in my table by tag “tbody” and my table have class “table_for_export_excel”

$('.table_for_export_excel').each(function(index, element){
		var body = [];
			$(element).each(function (index_body, element_body){
				$($(element_body).find("#tbody tr")).each(function(index_tr, element_tr){
					$(this.cells).each(function(index_td, element_td){

				  	body.push($(element_td).text());
					});
						worksheet.addRow(body);
						body = [];	
				});	
			});
			});

I have tried usage worksheet.eachRow but this did not help me((

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

26reactions
azhar22kcommented, Nov 1, 2018

@PashaFrontEnd Instead of setting the property of each cell, you can set it for a row directly Following example changes the style of header row(row 1)

const workbook = new ExcelJS.Workbook();
const worksheet = workbook.addWorksheet();
worksheet.columns = [
			{ key: 'pp', width: 15},
			{ key: 'part', width: 25},
			{ key: 'plav', width: 25 },
			{ key: 'rul', width: 25 },
			{ key: 'date', width: 25 },
			{ key: 'nd', width: 25 },
			{ key: 'mark', width: 25 },
			{ key: 'znach', width: 25 },
			{ key: 'tol', width: 25 },
			{ key: 'width', width: 25 },
			{ key: 'length', width: 25 }
];

worksheet.getRow(1).fill = {
type: 'pattern',
pattern:'solid',
fgColor:{ argb:'cccccc' }
}

0reactions
PashaFrontEndcommented, Nov 1, 2018

@itz-azhar thanks for help, but each column have has different sizes )

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add or change the fill color of a table cell - Microsoft Support
On the Tables tab, under Table Styles, click the arrow next to Fill. On the Fill menu, click Fill Effects. Click the Solid...
Read more >
How to add different background colors to the Row Headers
Hi Madhura29, You can do this in the "Filed Formatting" section under the "Format" tab (below the visualizations). Select each field to give...
Read more >
Excel: Change the row color based on cell value - Ablebits
Click the "Format…" button and switch to Fill tab to choose the background color. If the default colors do not suffice, click the...
Read more >
Best Shortcuts to Fill Color in Excel (Basic & Advanced)
You can continue to use the F4 key to fill color in multiple cells/ranges as long as you don't do anything else. You...
Read more >
How to color cells, and alternate row colors in Google Sheets
After selecting the desired cells to color, click "Fill Color" · Select desired default color · (Optional)- Click "Custom…" and then select a ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found