This example shows how to extract and loop through table content in an Excel (XLSX) file using GroupDocs.Parser.
Java
// Initialize Parser with the Excel file
try (Parser parser = new Parser("input.pdf"))
{
// Exit if table extraction isn’t supported for this document
if (!parser.getFeatures().isTables())
{
return;
}
// Apply rules to locate table layout
TemplateTableLayout layout = new TemplateTableLayout(
java.util.Arrays.asList(new Double[]{50.0, 95.0, 275.0, 415.0, 485.0, 545.0}),
java.util.Arrays.asList(new Double[]{325.0, 340.0, 365.0, 395.0}));
// Configure settings for table extraction
PageTableAreaOptions options = new PageTableAreaOptions(layout);
// Invoke the extraction process
Iterable<PageTableArea> tables = parser.getTables(options);
// Loop over all parsed table structures
for (PageTableArea t : tables)
{
// Iterate over each row within the table
for (int row = 0; row < t.getRowCount(); row++)
{
// Process each cell in the current row
for (int column = 0; column < t.getColumnCount(); column++)
{
// Access and read the current cell's content
PageTableAreaCell cell = t.getCell(row, column);
if (cell != null)
{
// Output the textual value of each table cell
System.out.print(cell.getText());
System.out.print(" | ");
}
}
}
}
}