Expand my Community achievements bar.

Export to Excel

Avatar

Level 3

1.5 years ago i created a solution for an export to Excel using Acrobat Pro.

But now i want to do the same in LiveCycle Designer ES2.

Can someone help me with the conversion of that scipt?

I don't know if this can be done in Livecycle.

Also, in the new livecycle form i have a table where the user can add a new row.

that's the most dificult part for me

The Acrobat solution was the folowing:

I've attached an empty text-file with the .xls extension to the PDF-form.

On a button i added a script like this:

var vFirstName = this.getField("firstname").value;

var vLastName = this.getField("lastname").value;

var vStreet = this.getField("street").value;

var vStreetNumber = this.getField("number").value;

var vPostalcode = this.getField("PC").value;

var vCity = this.getField("city").value;

var vdistance = this.getField("distance").value;

var vDate = this.getField("date").value;

var vStartTime = this.getField("starttime").value;

var vEndTime = this.getField("endtime").value;

// check acrobat version

if (app.viewerVersion >= 7){

// get file

var oFile = this.getDataObjectContents("export.xls");

// convert the file to string

var vFile = util.stringFromStream(oFile, "utf-8");

// formatting data

var vText =

"Name of applicant\t" +  vFirstName + "\t" + vLastName + "\r\n" +

"Address\t" + vStreet + " " + vStreetNumber + "\r\n\t" + vPostalcode + "\t" + vCity + "\r\n" +

"traveling expenses" + "\t" + vDate+ "\t" + vStartTime + "\t" + vEndTime + "\t" + vdistance;

// convert data to string

var oFile = util.streamFromString(vText, "utf-8");

// Overwrite the embedded file

this.setDataObjectContents("export.xls", oFile);

// Open file

this.exportDataObject({cName: "export.xls", nLaunch: 1});

}

else {

app.alert("Acrobat 7.0 or later is required!")

}

1 Reply

Avatar

Level 10

Hi,

you only need to change 2 things.

1. replace the method getField with xfa.resolveNode()

2. replace the expression this with event.target.

var vFirstName = xfa.resolveNode("form1.#subform.firstname").rawValue;

var vLastName = xfa.resolveNode("form1.#subform.lastname").rawValue;

...

// check acrobat version if (app.viewerVersion >= 7){  

// get file

var oFile = event.target.getDataObjectContents("export.xls");  

// convert the file to string

var vFile = util.stringFromStream(oFile, "utf-8");  

// formatting data

var vText =  "Name of applicant\t" +  vFirstName + "\t" + vLastName; /* + "\r\n" + "Address\t" + vStreet + " " + vStreetNumber + "\r\n\t" + vPostalcode + "\t" + vCity + "\r\n" + "traveling expenses" + "\t" + vDate+ "\t" + vStartTime + "\t" + vEndTime + "\t" + vdistance;*/  

// convert data to string

var oFile = util.streamFromString(vText, "utf-8");  

// Overwrite the embedded file event.target.setDataObjectContents("export.xls", oFile);  

// Open file event.target.exportDataObject({cName: "export.xls", nLaunch: 1});   +

} else {

app.alert("Acrobat 7.0 or later is required!")

}