Copy link to clipboard
Copied
I'm looking for a way to use scripting to import several ranges from XLS(X) file one under another into one text frame. I've found a question here that had a solution for importing ranges into different text frames but I can't make it work for one text frame.
Here's the code I have now:
main();
function main() {
var doc = app.activeDocument;
var fileExcel = new File("path/filename.xlsx");
if (fileExcel.exists) {
var ranges = "range001";
app.excelImportPreferences.rangeName = ranges;
doc.pages[0].textFrames[0].place(fileExcel);
}
}
If I make a table with range names and add a loop that goes through them, it will just replace the contents of the frame. So basically I'm looking for a way that the script can go inside the frame, put the cursor at the very end and then import the next range.
Any help appreciated!
I can't test this but you could change the following line
doc.pages[0].textFrames[0].place(fileExcel);
to
doc.pages[0].textFrames[0].insertionPoints[-1].place(fileExcel);
-Manan
Copy link to clipboard
Copied
I can't test this but you could change the following line
doc.pages[0].textFrames[0].place(fileExcel);
to
doc.pages[0].textFrames[0].insertionPoints[-1].place(fileExcel);
-Manan
Copy link to clipboard
Copied
Amazing! Thank you, it works like a charm!
For anyone looking here's the code for a script that imports several ranges into currently selected textframe:
main();
function main() {
var doc = app.activeDocument;
var fileExcel = new File("path/filename.xls");
if (fileExcel.exists) {
var ranges = [
"range001",
"range002",
"range003"
];
for (var i = 0; i < ranges.length; i++) {
app.excelImportPreferences.rangeName = ranges[i];
app.selection[0].insertionPoints[-1].place(fileExcel);
}
}
}