How many sheets in Excel file
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
-- 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
Copy link to clipboard
Copied
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

