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

How to use xlsx.extendscript.js

New Here ,
May 08, 2023 May 08, 2023

Copy link to clipboard

Copied

Hey i am trying to read from an Excel file and I am using (#include "xlsx.extendscript.js"; ). This not working. I tried using seeing if I could use #include. It says Private identifiers are not allowed outside class bodies.  

 

Need help to know how to correctly use xlsx

TOPICS
How to , Import and export , Scripting

Views

772

Translate

Translate

Report

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

correct answers 1 Correct answer

Guru , May 08, 2023 May 08, 2023

I have no idea what xlsx.extendscript.js is, but you can use this function to get data from Excel to InDesign.

Votes

Translate

Translate
Guru ,
May 08, 2023 May 08, 2023

Copy link to clipboard

Copied

I have no idea what xlsx.extendscript.js is, but you can use this function to get data from Excel to InDesign.

Votes

Translate

Translate

Report

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
New Here ,
May 09, 2023 May 09, 2023

Copy link to clipboard

Copied

Thanks so much, I will try that

Votes

Translate

Translate

Report

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
Community Expert ,
May 09, 2023 May 09, 2023

Copy link to clipboard

Copied

Hi @Victor29751988fsbx , Another approach is to temporarily place the excel file and get its contents as a nested array:

 

var xlsf = File.openDialog("Please Choose an Excel file");

alert("Contents of row 2 cell 1: " + getExcelArray(xlsf)[1][0]);


/**
* Coverts an Excel file into a nested array 
* @ param Excel File to place 
* @ returns the Excel table as a nested array 
* 
*/
function getExcelArray(xf){
    var doc = app.activeDocument;	
    var xta = [];
    var temp = doc.pages[0].textFrames.add();
    try {
        temp.place(xf);
        var xtr = temp.parentStory.tables[0].rows.everyItem().getElements();
    }catch(e) {
        temp.remove()
        alert(e)
    }  
    var c; 
    for (var i = 1; i < xtr.length; i++){
        c = xtr[i].cells.everyItem().getElements();
        var ca = [];
        for (var j = 0; j < c.length; j++){
            ca.push(c[j].texts[0].contents)
        };   
        xta.push(ca)
    };   
    temp.remove()
    return xta;
}

 

Votes

Translate

Translate

Report

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
Community Expert ,
May 10, 2023 May 10, 2023

Copy link to clipboard

Copied

@rob day -- There's a shortcut to getting a table's content as an array of arrays:

xta = temp.parentStory.tables[0].rows.everyItem().contents;

P.

Votes

Translate

Translate

Report

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
Community Expert ,
May 10, 2023 May 10, 2023

Copy link to clipboard

Copied

Hi Peter, I was hoping that would work, but when I try it in my function the array elements are empty—a writeIn for xta returns ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

 

 

function getExcelArray(xf){
    var doc = app.activeDocument;	
    var temp = doc.pages[0].textFrames.add();
    try {
        temp.place(xf);
        var xta = temp.parentStory.tables[0].rows.everyItem().contents; 
        $.writeln(xta)
        //returns ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    }catch(e) {
        temp.remove()
        alert(e)
    }  
    temp.remove()
    return xta;
}

 

 

Votes

Translate

Translate

Report

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
Community Expert ,
May 10, 2023 May 10, 2023

Copy link to clipboard

Copied

LATEST

Turns out that when the table is exposed it works as expected. Just make the frame very big and enable ignoreWrap to make sure that another frame doesn;t cause overset:

var temp = doc.pages[0].textFrames.add ({
  geometricBounds: [0,0,1000,1000],
  textFramePreferences: {
    ignoreWrap: true,
  },
});

 

Votes

Translate

Translate

Report

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