Question

How can i retrive excel table header row.
I able to retrive all rows except table header row.
Code

private static void printTableContent(final ListObject table) {
    System.out.println(table.getShowHeaderRow());
    Range range = table.getDataRange();

    for (int row = 0; row < range.getRowCount(); row++) {
        for (int column = 0; column < range.getColumnCount(); column++) {
            System.out.print(range.get(row, column).getDisplayStringValue());
            System.out.print("\t");
        }
        System.out.println();
    }
}
Was it helpful?

Solution

ListObject.getDataRange() will only return the data rows.

To get the header row, use ListObject.getListColumns(). Add the following code in your method to print the list of header row.

for (int iColumn = 0 ; iColumn < table.getListColumns().getCount() ; iColumn++)
{
    System.out.print(table.getListColumns().get(iColumn).getName());
}
System.out.println();

I work with Aspose as a Developer Evangelist.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top