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

How many sheets in Excel file

Enthusiast ,
Jan 10, 2019 Jan 10, 2019

Hello!

There is a way to know how many sheets an Excel file has to loop and then import them?

What about the import options dialog... can JS code automate the filling for, for example, the Cell Range field?

I need to deal with Excel files that has more than one sheet in it. If I do it manually and choose to show the import options dialog, I have, in Cell Range field, this strange "_xlnm.Print_Area" option, so, I want to use it, because it results me a cleaner InDesign table.

TOPICS
Scripting
577
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
Community Expert ,
Jan 11, 2019 Jan 11, 2019

I could not find anything in the scripting API that gives the count of sheets available in Excel file. You could use VBScript or Applescript to get this info from your jsx.

-Manan

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
Participant ,
Jan 11, 2019 Jan 11, 2019

-- In Applescript:

tell application "Microsoft Excel"

  set theCount to count sheets --> 4

  (* -- another way:

  -- get the sheet names:

       set xlNameList to name of every sheet --> {"Sheet1", "Sheet2", "Sheet3", "Sheet4"}

  -- and count the names:

       set xlNameListCount to count xlNameList

  *)

end tell

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
Engaged ,
Jan 11, 2019 Jan 11, 2019
LATEST

With JavaScript you cound set the excelImportPreference:

app.excelImportPreferences.sheetIndex = 2;

If you don't run into an error, you know you have an Excel file with at least two sheets.

Thx Stefan

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