Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

load excel spreadsheet to table variable?

Explorer ,
Nov 01, 2016 Nov 01, 2016

I know how to create a doc, place an excel spreadsheet in the doc, and then refer to the cells of the table....

Is it possible to skip the "create" and "place" steps -- and do something like

myTable = new Table;

myTable = open("path to excel file");

myData=myTable.rows[2].cells[11].texts[0].contents;

TOPICS
Scripting
396
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 01, 2016 Nov 01, 2016

Hi akiva_atwood

Short answer: no…

First you need to have a open document. Then you can place a spreadsheet which creates a table inside a text frame. Then you can get the data of a specific field.

A bit of code:

main();

exit();

function main() {

  // take the open document

  var myDoc = app.activeDocument;

  // take the first textframe in my example

  var myTextFrame = myDoc.textFrames[0];

  // take the first table of the first textframe. A table lives inside a textframe

  var myTable = myTextFrame.tables[0];

  // get the data from the cell (1,3)

  var myData = myTable.columns[1].cells[2].contents;

  // write the data to the console

  $.writeln(myData);

}

I hope this helps to answer your question

kind regards

Daniel

(from Switzerland)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 01, 2016 Nov 01, 2016

Hi Daniel

I know how to do it that way -- I was hoping to avoid the create and place steps.

Thanks

Akiva

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Nov 01, 2016 Nov 01, 2016
LATEST

On Windows, it would be like this:

  var vb;

  vb = "\rSet myExcel = CreateObject(\"Excel.Application\")";

  vb += "\rDim s";

  vb += "\rSet objWorkbook = myExcel.Workbooks.Open(/*Path to Excel Doc*/)";

  vb += "\rSet objSheet = myExcel.ActiveWorkbook.WorkSheets(1)";

  vb += "\rs = objSheet.Cells(1, 2).Text";

  vb += "\robjWorkBook.close";

  vb += "\rreturnValue = s";

  result = app.doScript (vb, ScriptLanguage.VISUAL_BASIC);

This gives you the plain text of cell 1,2.

Ariel

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines