Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Import several ranges from Excel, one under another into one text frame

New Here ,
Aug 30, 2021 Aug 30, 2021

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!

TOPICS
Scripting

Views

44

Likes

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

Adobe Community Professional , Aug 30, 2021 Aug 30, 2021
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

Likes

Translate

Translate
Adobe Community Professional ,
Aug 30, 2021 Aug 30, 2021

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

Likes

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 ,
Aug 30, 2021 Aug 30, 2021

Copy link to clipboard

Copied

LATEST

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);
            
            
            }
		}
	}

Likes

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