In my previous post I showed you how to add content to a text frame. In this post I'll show you how to import a Word file.
Again, if we were doing this manually, the steps would be:
• Create a new Indesign document
• Select File > Place > navigate to your Word file > select and open
• Either click on an existing text frame or draw a new one to place your text.
To do it via scripting we'll replace this line in our current script:
myFrame.contents = "Hello world";
with:
var wordFile = File.openDialog("Choose a Word file to import", "*.doc");
myFrame.insertionPoints.item(-1).place(wordFile);
You can guess just by reading these lines that a dialog box will open asking you to pick a Word file to import, and then it will place it into the frame you created.
An added bonus is if you have formatted the Word file with paragraph and character styles, then they will be imported as well.
• Create a new Indesign document
• Select File > Place > navigate to your Word file > select and open
• Either click on an existing text frame or draw a new one to place your text.
To do it via scripting we'll replace this line in our current script:
myFrame.contents = "Hello world";
with:
var wordFile = File.openDialog("Choose a Word file to import", "*.doc");
myFrame.insertionPoints.item(-1).place(wordFile);
You can guess just by reading these lines that a dialog box will open asking you to pick a Word file to import, and then it will place it into the frame you created.
An added bonus is if you have formatted the Word file with paragraph and character styles, then they will be imported as well.
No comments:
Post a Comment