Wednesday, January 21, 2009

Excel table parsing

This code parses output of Excel-document and put it to array.


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 ] );

Tuesday, November 18, 2008

PrintToWeb: quick start

What is the “PrintToWeb” Technology?


PrintToWeb is a technology of managing web-site in easy way. Using this technology you can update information on your site from any desktop application. The idea of the technology is in using virtual printing mechanism which allows you to “print” information from application directly to the site. For example, if you want to publish an article you can write it in any text-processor and then just click “print” button of the application and the document will be published on the server. So if you know how to print your document you can manage your site.

How can I start using PrintToWeb


You need to install PrintToWeb printer driver with speciation installation application. If installation process succeeded then “PrintToWeb” printer would appear in printer setup of your operation system.

How can I add document to the web-site


Publishing process consists of three main steps:
• Click “Print” button in your desktop application, choose “PrintToWeb” printer and print the document.
• In dialog login to web-server and choose application and action you want to perform with document
• Click OK button

How does PrintToWeb know where to put my document?


This is determined by the script which is selected when printing. Scripts are inside web-application, therefore you don’t need any additional settings.

What is the “script”?


Script is the program written in high level language. The purpose of this program is to add the printing document to the user’s site. Scripts are written inside special editor in ECMA-script language.