function ParseExcelTable (pageNum)
{
document = Document.ObjectModel ();
documentPage = document.GetPage (pageNum);
textObjects = documentPage.GetTextObjects ();
// result parsed table
var table = new Array ();
var row_id = new Array ();
var col_id = new Array ();
// looking through all the text objects
var row = 0, column = 0;
for (key = 0; key < textObjects.length; ++key)
{
textObject = textObjects [key];
base = textObject.Attribute ("base");
left = textObject.Attribute ("left");
// checking whether the text object is the first one in a row
if (left == textObjects [0].Attribute ("left"))
{
try { row_id [base] }
catch (er) { row_id [base] = row++; }
if (row_id [base] == undefined)
row_id [base] = row++;
}
// checking whether the text object is the first one in a column
if (base == textObjects [0].Attribute ("base"))
{
try { col_id [left] }
catch (er) { col_id [left] = column++; }
if (col_id [left] == undefined)
col_id [left] = column++;
}
}
// result table initialization with undefined values
for (r in row_id)
{
table [row_id [r]] = new Array ();
for (c in col_id)
table [row_id [r]] [col_id [c]] = undefined;
}
// filling the table
for (key = 0; key < textObjects.length; key++)
{
textObject = textObjects [key];
base = textObject.Attribute ("base");
left = textObject.Attribute ("left");
text = textObject.Attribute ("value");
try { row_id [base] }
catch (er)
{
print ("unexpected y at: '" + base + "' '" + left + "' " + text);
continue;
}
try { col_id [left] }
catch (er)
{
print("unexpected x at '" + base + "' '" + left + "' " + text);
continue;
}
table [row_id [base]] [col_id [left]] = text;
}
print ("Excel table has been successfully parsed.");
return table;
}
Sample of use:
var table = ParseExcelTable( 0 );
print( table[ 2 ][ 2 ] );