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

Help Needed!

Engaged ,
Aug 30, 2016 Aug 30, 2016

Copy link to clipboard

Copied

Hello Everyone,

I have InDesign table had some values. I need to update that value from CSV document.  
However, I can't match both CSV value and table content value due to index mark(symbol ::).

match the value and update the price from CSV.

Please find the screen shot for your quick reference.

Example:

I can't match the text 6954 (The text placed in a table) between this symbol :: ::

Screen Shot 2016-08-30 at 4.17.28 pm.png

CSV data:

Screen Shot 2016-08-30 at 4.20.02 pm.png

Please advice or suggest me

Help much appreciated. Thanks in advance.

-VJ

Code:

var flagPrice,flagPageNo,flagUPC,flagQTY;   

main();

function main(){

    TableSel=app.selection[0];

    if(TableSel.constructor.name== "Cell"){

        var RowLen=TableSel.rows.length;

        var ColLen=TableSel.columns.length-1;

        var CelLen=TableSel.cells.length;

        var col=0;

        for(i=0;i<RowLen;i++){

            flagFindSKU=trim(TableSel.cells[i+col].contents).toString();

            GetDatafromCSV(flagFindSKU);

            alert(flagFindSKU+"\n"+flagPrice+"\n"+flagPageNo+"\n"+flagUPC+"\n"+flagQTY);

            col=col+ColLen;               

        }

    }

}

function GetDatafromCSV(flagFind){       

    var docRef=app.activeDocument;

    var docPath=app.activeDocument.filePath;

    myFolder=Folder(docPath);

    var myFiles = myFolder.getFiles ("*.csv");

    if(myFiles.length==0){

        myFolder = File.openDialog("Select the CSV file to Proceed");

        if(!myFolder){return;}

        fPathCSV=decodeURI(myFolder);

    }

    fPathCSV=decodeURI(myFiles[0]);       

    var datafile=File(fPathCSV);       

        if (datafile.exists){

            datafile.open('r');

            while (!datafile.eof){               

                strLineIn = datafile.readln();

                colArray = strLineIn.split(",");               

                if (trim(colArray[0])!="" && trim(colArray[1])!="" && colArray[0]!="sku"){                   

                    alert(colArray[0]+"=="+flagFind);

                    if(trim(colArray[0])==trim(flagFind)){

                        flagPrice=parseFloat(colArray[1]);

                        flagPrice=flagPrice.toFixed(2);

                        flagPageNo=colArray[2];

                        flagUPC=colArray[3];

                        flagQTY=colArray[4];     

                        return;

                    }

                }

            }

        }

    }

function trim(str) {

    try{return str.replace(/^\s+/,'').replace(/\s+$/,'');}catch(er) {}

}

TOPICS
Scripting

Views

297

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

Enthusiast , Aug 30, 2016 Aug 30, 2016

Try this,

Replace the below line:

    try{return str.replace(/^\s+/,'').replace(/\s+$/,'');}catch(er) {}

to

    try{return str.replace(/^\s+/,'').replace(/\s+$/,'').replace(/\uFEFF/g,'');}catch(er) {} 

Votes

Translate

Translate
Enthusiast ,
Aug 30, 2016 Aug 30, 2016

Copy link to clipboard

Copied

Try this,

Replace the below line:

    try{return str.replace(/^\s+/,'').replace(/\s+$/,'');}catch(er) {}

to

    try{return str.replace(/^\s+/,'').replace(/\s+$/,'').replace(/\uFEFF/g,'');}catch(er) {} 

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
Engaged ,
Aug 30, 2016 Aug 30, 2016

Copy link to clipboard

Copied

LATEST

Thanks, Bro

It is working now and you help much appreciated...

-VJ

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