This code sample shows how to read and iterate through table data in an XLSX file using GroupDocs.Parser.
C#
// Open the Excel file using the Parser API
using (Parser parser = new Parser("input.xlsx"))
{
// Exit if tables cannot be extracted from the file
if (!parser.Features.Tables)
{
return;
}
// Use layout rules to locate tabular content
TemplateTableLayout layout = new TemplateTableLayout(
new double[] { 50, 95, 275, 415, 485, 545 },
new double[] { 325, 340, 365, 395 });
// Set up extraction parameters for tables
PageTableAreaOptions options = new PageTableAreaOptions(layout);
// Perform the table extraction operation
IEnumerable<PageTableArea> tables = parser.GetTables(options);
// Go through each detected table structure
foreach (PageTableArea t in tables)
{
// Iterate through each row in the table
for (int row = 0; row < t.RowCount; row++)
{
// Loop through the cells in each row
for (int column = 0; column < t.ColumnCount; column++)
{
// Access the current table cell
PageTableAreaCell cell = t[row, column];
if (cell != null)
{
// Display the text content of each cell
Console.Write(cell.Text);
Console.Write(" | ");
}
}
}
}
}