Export in excel - retrieve last row and add style

Export in excel - retrieve last row and add style

itajackassitajackass Posts: 121Questions: 37Answers: 3

I'd like to retrieve last line on a exported excel result to apply a background style.
Is there any formula to use inside customize option? I don't find anything.
In general, how can i apply styles to rows when I don't know the position yet?
For example if I want to export a table with 10 rows, and row 3 and 10 show me a subtotal line i want to BOLD in my export, how can I know that row 5 on excel (5 because row 1 in excel is the title, 2 is the header, and data start from excel line 3....) need to be formatted?
My data of course is dynamic, so in the next search subtotal maybe is on line 100 for example....

Answers

  • kthorngrenkthorngren Posts: 20,251Questions: 26Answers: 4,761
    edited December 2019

    Maybe the last example in this thread will help. It shoes how to iterate the rows and set formatting based on certain values.

    Kevin

  • smiddicksmiddick Posts: 5Questions: 1Answers: 0

    That's a pretty big and 'diverse' thread. This OP asked about simply identifying the last line, using some kind of command/option inside the 'customize' option. I need the same thing -- to identify and target the last row (that has anything in it). The suggested thread seems to imply that we have to loop through all the rows to identify that last row. Really? There's no 'getHighestRow' or some equivalent to your "$('row:first c', sheet)" command? I use your $('row:first c', sheet).attr('s', '2') to create a bold title heading on my excel export. I'd like to use messageBottom or some other option to create a BOLD line using my 'totals' data. Is there not a way to 'bold' that data without pumping through every row??

  • smiddicksmiddick Posts: 5Questions: 1Answers: 0
    edited December 2020

    Potential solution below

  • smiddicksmiddick Posts: 5Questions: 1Answers: 0

    Never mind. I spent a few hours in Firefox debug combing through all the variables, functions, prototypes, etc, that appear there and finally stumbled upon "$('row', sheet)". Then I took a leap of faith and appended "length" to that ( i.e., $('row', sheet).length ) to get the number of rows in the sheet, and set that to a variable 'numrows'. Then I went through a bunch of your examples to find how to address a particular row and col. Came up with "$('c[r=A' + numrows + ']', sheet).attr('s', '2'); " to make my last row bold. There's probably an easier way, but this works and I'm tired. I'm used to Excel, PHPExcel, and PHPSpreadsheet, so the datatables options/commands/functions/variables/etc for excel seem pretty different from those tools, at least once you get past the high level of "this row, that column". I hope this helps someone who wants to do something less resource-intensive than pumping through all the rows in a spreadsheet.

This discussion has been closed.