Skip to main content
Participant
June 17, 2022
Question

Export Titles and Page numbers to Excel or .CSV

  • June 17, 2022
  • 2 replies
  • 663 views

Hey!

I have a INDD file that has it's content flowed in from an XML, each field has a Tag and a Paragraph style applied to it.

I need to see if I can export a report of the Titles and what Page Number corresponds to each one, an Excel Or .CSV file would be ideal.

Anyone have any clues on who to do this from InDesign?

Thanks!

This topic has been closed for replies.

2 replies

rob day
Community Expert
Community Expert
June 17, 2022

Hi @andyjamieson , A script could get every paragraph with a certain style applied and write the paragraph’s contents and its page number to a text or cvs file. Something like this gets all paragraphs with the style named Title and writes a Titles.cvs file to the desktop:

 

var sName = "Title"
var doc = app.activeDocument
var txt = "Title\tPage Number\r"

for(var i=0; i <doc.stories.length; i++){  
    var s = doc.stories.item(i);  
    for(var j=0; j < s.paragraphs.length; j++){  
        var p=s.paragraphs.item(j); 
        if (p.appliedParagraphStyle.name == sName ) {
            txt += p.contents.slice(0,-1) + "\t" + p.parentTextFrames[0].parentPage.name + "\r"
        } 
    }  
}  

writeText(Folder.desktop + "/Titles.csv", txt)

function writeText(p,s){
    var file = new File(p);
    file.encoding = 'UTF-8';
    file.open('w');
    file.write(s);
    file.close();
}

 

 

Participant
June 18, 2022

Hey @rob day 

That looks ideal, when I tried to create my own JSX script I get this error —

 

Here's an example of a listing with the file 

 

rob day
Community Expert
Community Expert
June 18, 2022

Can you share the ID file? You should be able to attach it.

 

Mike Witherell
Community Expert
Community Expert
June 17, 2022

Why not generate a table of contents and then copy paste that text into a spreadsheet?

Mike Witherell