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

How to match text in tables and apply paragraph style via external CSV?

Explorer ,
Nov 08, 2018 Nov 08, 2018

Hi good peoples,

I wish to know is there a way/script to search and match a big list of item numbers in an indesign table from a external CSV file and apply a new paragraph style over it?

Below is my example:

  1. We have a catalogue with part numbers on the right most columns applied with "item#" paragraph style.
  2. Client wish to highlight the only certain part numbers in the catalogue they have in stock and supplied a corresponding Excel/CSV list they carry (in this case it's T365 0500,T365 0600,T365 0800,T367 1000,T367 1200,T367 1400.
  3. We have to create a new document with the items from the CSV highlighted (in this case we wish to just bold and change colour by applying a "item#2" paragraph style) 
  4. So my question is if there any way of scripting this process of matching item numbers to a CSV or text file and applying "item#2" over it?

IScreen Shot 2018-11-09 at 12.08.27 AM.png

I hope my question makes sense and thanks for any suggestions in advance

966
Translate
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

Guide , Nov 08, 2018 Nov 08, 2018

Try this:

// by FRIdNGE, November 2018

var myDoc = app.activeDocument,

mySKUsListFile = File(myDoc.filePath + "/ProductsRefToBeCatched.txt"); 

mySKUsListFile.open(); 

var mySKUsList = mySKUsListFile.read(),

mySKUs = mySKUsList.split("\n"); 

mySKUsListFile.close(); 

var S = mySKUs.length,  s;

for ( s = 0; s < S; s++ ) {

    app.findGrepPreferences = app.changeGrepPreferences = null;

    app.findGrepPreferences.findWhat = "\\b" + mySKUs + "\\b";

    app.findGrepPreferences.appliedParagraphStyle = "item#";

...
Translate
Community Expert ,
Nov 08, 2018 Nov 08, 2018

I think I would use a GREP style within your Paragraph style to attach a Character style with underline and bold to the list of numbers.

Apply text Underline to :

T365 0500|T365 0600|T365 0800|T367 1000|T367 1200|T367 1400

The | character in GREP functions as OR, so any of those values listed get the character style, and the rest are left alone.

This was, you don't need a separate paragraph style for those numbers, and if the highlighted numbers changed, you just have to edit the GREP list.

Screenshot 2018-11-08 09.15.13.png

Translate
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 ,
Nov 08, 2018 Nov 08, 2018

a bit more flexibel:

aaa.png

Grep:

T36(5\h[5-8]|7\h1[0-4])00

Translate
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
Explorer ,
Nov 08, 2018 Nov 08, 2018

Thanks for the suggestion but we dealing with a big list of unique items number and they tend to jump around. So I'm not sure the range method will work

Translate
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 ,
Nov 08, 2018 Nov 08, 2018

no list - no rule

Translate
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
Guide ,
Nov 08, 2018 Nov 08, 2018

Hi,

[ Hi Pixxxel! ]

If the numbers indicated in the CSV file are unique, it's not really complicated to be scripted [note using a grep style has no interest].

You'll surely find here someone to write such a script for free! Personally, it won't be the case.

Best,

Michel, for FRIdNGE

Translate
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
Explorer ,
Nov 08, 2018 Nov 08, 2018

I have found something that sort of works, although its not from a external csv, and i will have to create a list of items that need to change to paste into the search queries...

Would someone shed some more light on this?

var myDoc = app.activeDocument,      

myCodes = ["T820 0300","T820 0500","T820 0800", etc...etc...],    

C = myCodes.length,  c;      

app.findTextPreferences = null;    

for ( c = 0; c < C; c++) {        

    app.findTextPreferences.findWhat = myCodes;        

    myFound = myDoc.findText();      

    var F = myFound.length,  f; 

    

    var ItemNumber = myDoc.paragraphStyles.itemByName("ItemNumber");

    var CoreRange = myDoc.paragraphStyles.itemByName("CoreRange");

   

    for ( f = 0; f < F; f++) {    

        myFound.appliedCharacterStyle = myDoc.characterStyles[0]; 

        

        if ((myFound.appliedParagraphStyle == ItemNumber)) {    

            

                myFound.appliedParagraphStyle = CoreRange; 

        } else{} 

    }    

}

Translate
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
Guide ,
Nov 08, 2018 Nov 08, 2018

Try this:

// by FRIdNGE, November 2018

var myDoc = app.activeDocument,

mySKUsListFile = File(myDoc.filePath + "/ProductsRefToBeCatched.txt"); 

mySKUsListFile.open(); 

var mySKUsList = mySKUsListFile.read(),

mySKUs = mySKUsList.split("\n"); 

mySKUsListFile.close(); 

var S = mySKUs.length,  s;

for ( s = 0; s < S; s++ ) {

    app.findGrepPreferences = app.changeGrepPreferences = null;

    app.findGrepPreferences.findWhat = "\\b" + mySKUs + "\\b";

    app.findGrepPreferences.appliedParagraphStyle = "item#";

    app.changeGrepPreferences.appliedParagraphStyle = "item#2";

    myDoc.changeGrep();

}

app.findGrepPreferences = app.changeGrepPreferences = null;

I've used a .txt file here saved at the same place as the .indd file.

Best,

Michel

Translate
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
Explorer ,
Nov 08, 2018 Nov 08, 2018

Hi Michel,

This works amazingly!   Just that I have to move the paragraph styles out of its folder. Is there a command to tell the script to search inside paragraph folders also?

Translate
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
Guide ,
Nov 09, 2018 Nov 09, 2018

Capture d’écran 2018-11-09 à 11.45.51.png

// by FRIdNGE, November 2018

var myDoc = app.activeDocument,

//------------------------------------------------------------------------------------------

myGroup1 = myDoc.paragraphStyleGroups.itemByName("item#_Group"),

myParaStyle1 = myGroup1.paragraphStyles.itemByName("item#"),

myGroup2 = myDoc.paragraphStyleGroups.itemByName("item#2_Group"),

myParaStyle2 = myGroup2.paragraphStyles.itemByName("item#2"),

//------------------------------------------------------------------------------------------

mySKUsListFile = File(myDoc.filePath + "/ProductsRefToBeCatched.txt"); 

mySKUsListFile.open(); 

var mySKUsList = mySKUsListFile.read(),

mySKUs = mySKUsList.split("\n"); 

mySKUsListFile.close(); 

var S = mySKUs.length,  s;

for ( s = 0; s < S; s++ ) {

    app.findGrepPreferences = app.changeGrepPreferences = null;

    app.findGrepPreferences.findWhat = "\\b" + mySKUs + "\\b";

    app.findGrepPreferences.appliedParagraphStyle = myParaStyle1;

    app.changeGrepPreferences.appliedParagraphStyle = myParaStyle2;

    myDoc.changeGrep();

}

app.findGrepPreferences = app.changeGrepPreferences = null;

Translate
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
Explorer ,
Nov 10, 2018 Nov 10, 2018
LATEST

This works really great Michel! Can't thank you enough

Translate
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