Excel cell formatting - How can we iterate excel export rows and get the cell value dynamically??

Excel cell formatting - How can we iterate excel export rows and get the cell value dynamically??

leo2115leo2115 Posts: 3Questions: 1Answers: 0

// Loop over the cells in column C
$('row c[r^="C"]', sheet).each( function () {
// Get the value
if ( $('is t', this).text() == 'New York' ) {
$(this).attr( 's', '20' );
}
});
In this example,they are looping over cells in 'C' column..how can we get this column A,B,C,D .... index position dynamically without specifying it??

This question has accepted answers - jump to:

Answers

  • kthorngrenkthorngren Posts: 21,382Questions: 26Answers: 4,959
    Answer ✓

    'row c[r^="C"]'

    This is a string. You can substitute the C with a variable like this:

    var myColumn = 'A';
    $('row c[r^="' + myColumn + "]', sheet).each( function () {
    

    How you choose whether its A or B, etc is up to your specific requirements.

    kevin

  • leo2115leo2115 Posts: 3Questions: 1Answers: 0

    thank you for your answer..In an attached image,excel has 1st row as table title and 2nd row contains headers for each column,and remaining rows contains values for that headers..Based on header,i want to apply conditional formatting for cells in column.For example: header ****score1***column values should have conditional formatting..so how can we get column values based header??

  • kthorngrenkthorngren Posts: 21,382Questions: 26Answers: 4,959
    Answer ✓

    You can use table().header() to get the table header. Here is an example in the Excel export customize function.
    http://live.datatables.net/zagelija/1/edit

    Kevin

  • leo2115leo2115 Posts: 3Questions: 1Answers: 0

    how can we get column cell position based on cell value in excel export?

  • kthorngrenkthorngren Posts: 21,382Questions: 26Answers: 4,959

    Not sure I understand the question. It sounds like you are asking how to determine the Excel column letter from the position in array header array generated in my example (the titles variable). One way would be to build a mapping object like this:

    var mapping = {0: 'A', 1: 'B'....}
    

    Then use indexOf() to get the index in the array and use the index to get the Excel column letter, like this:

    var index = titles.indexOf( 'SCORE1' );
    var excelCol = mapping[index];
    

    Is this what you are asking about?

    Kevin

This discussion has been closed.