• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Export Titles and Page numbers to Excel or .CSV

Community Beginner ,
Jun 17, 2022 Jun 17, 2022

Copy link to clipboard

Copied

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!

TOPICS
How to , Import and export , Scripting , Type

Views

294

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
Community Expert ,
Jun 17, 2022 Jun 17, 2022

Copy link to clipboard

Copied

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

Mike Witherell

Votes

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
Community Expert ,
Jun 17, 2022 Jun 17, 2022

Copy link to clipboard

Copied

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

 

 

Screen Shot 9.png

Votes

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
Community Beginner ,
Jun 18, 2022 Jun 18, 2022

Copy link to clipboard

Copied

Hey @rob day 

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

Screenshot 2022-06-18 at 16.23.59.png

Screenshot 2022-06-18 at 16.29.45.png

 

Here's an example of a listing with the file 

 

Votes

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
Community Expert ,
Jun 18, 2022 Jun 18, 2022

Copy link to clipboard

Copied

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

 

Votes

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
Community Beginner ,
Jun 18, 2022 Jun 18, 2022

Copy link to clipboard

Copied

I've packaged one of the shorter sections, it's 20MB zipped so stuck it on Dropbox — 

https://www.dropbox.com/s/we2visxw34142r9/Fringe_Programme_2022_EXHIBITIONS_v2%20Folder.zip?dl=0

 

Thank you for your help!

Votes

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
Community Expert ,
Jun 18, 2022 Jun 18, 2022

Copy link to clipboard

Copied

I should have clarified the first line in the sample script is the ParagraphStyle name to get—you don’t have a style named "Title", so if I use your "B_RuleShowName" style:

 

 

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

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 ) {
            pn = p.parentTextFrames[0].parentPage.name
            txt += p.lines[0].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();
}

 

I get this (note in this version I’m getting the first line of the title for the Title column):

Screen Shot 10.png

Votes

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
Community Expert ,
Jun 18, 2022 Jun 18, 2022

Copy link to clipboard

Copied

Votes

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
Community Beginner ,
Jun 18, 2022 Jun 18, 2022

Copy link to clipboard

Copied

Excellent job Rob, just tried the script on a different file section it's throwning an error for Line 11

Screenshot 2022-06-18 at 17.36.59.png

Will the script need slightly adjust for each file?

Votes

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
Community Expert ,
Jun 18, 2022 Jun 18, 2022

Copy link to clipboard

Copied

LATEST

Will the script need slightly adjust for each file?

Yes if the header’s style name changes.

 

Also, if a text frame is on the pasteboard you would get that null error. This would set the page number to "PB" if the frame is not actually on a page. I updated the compiled link same address:

 

 

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

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 ) {
            if (p.parentTextFrames[0].parentPage != null) {
                pn = p.parentTextFrames[0].parentPage.name
            } else {
                pn = "PB"
            }
            try {
                txt += p.lines[0].contents.slice(0,-1) + "\t" + pn + "\r"
            }catch(e) {}  
        } 
    }  
}  

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

 

 

 

Screen Shot 11.png

Votes

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