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

write the content in particular column in .csv

Enthusiast ,
Nov 09, 2016 Nov 09, 2016

Copy link to clipboard

Copied

Hi All,

Is it possible to write the content in particular column like 4 or 6 etc..?

I have column count with the Heading.

Before script:

Screen Shot 2016-11-09 at 14.51.11.png

After Script, (array content placing in 5 column

Screen Shot 2016-11-09 at 14.51.23.png

Simple code for your reference:

var myArray = ["PASS", "FAIL", "PASS"]

alert("myArray: " + myArray)

var myJoin =myArray.join("\n");

alert(myJoin)

var csvFile=File(Folder.desktop + "/somefile.csv");

csvFile.open('w');    

csvFile.write(myJoin)

csvFile.close(); 

Thanks in Advance

Siraj

TOPICS
Scripting

Views

440

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

Mentor , Nov 09, 2016 Nov 09, 2016

Hi,

1. if you read a .csv file and split text by "\n" ==> you have an array (each CSV line is an element of this array)

2. Assuming you have another array with data to input ==> alike ['FAIL','PASS','FAIL']

3. Assuming you want to input this as a 5th column

so you need to loop - split - splice - join

something like:

--------------------------------------------------

var

  mTotalArray, // csvFile.read().split("\n")

  mLineArray, // current  mTotalArray element.split(",")

  mInputArray, // your data

  k,

  m

...

Votes

Translate

Translate
Mentor ,
Nov 09, 2016 Nov 09, 2016

Copy link to clipboard

Copied

Hi,

Open your.csv file in Notebook to see its real structure. You need to modify this 'text' body using this structure (row after row with 'comma separated' elements.

Jarek

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
Enthusiast ,
Nov 09, 2016 Nov 09, 2016

Copy link to clipboard

Copied

Thank you Jump_Over for your quick response...

Is it possible to placing the content by (i.e.,) Column count 5 or 10 or whatever as per job input.. (not by "," comma seperator)

1. Earlier stage itself, read the heading column count like "Missing Font", "Missing Link" etc... from Input.csv

See below code finding the Column count (its your code only, got from forum)

//----------------------Pick Missing Font Column Count----------------------------

   

    MissingFont_xIdx = (cLine).search("," + String(Missing_Font_Heading));

   

    if(MissingFont_xIdx == -1)

    {

        alert("Missing Font Heading is not in Standard Format. Please check and Fix")

        exit(0)

        }

    Missing_Font_column = cLine.slice(0, MissingFont_xIdx).split(",").length - 1;

    alert("Missing_Font_column: " + Missing_Font_column)

//----------------------Pick Text Size Column Count----------------------------

2. Grab the value in myMissingFont_Array (refer top of the thread or Previous link created on yesterday)

3. Finally write it in Input.csv Column (as per Heading Column) (this is my request now)

Regards

Siraj

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
Mentor ,
Nov 09, 2016 Nov 09, 2016

Copy link to clipboard

Copied

LATEST

Hi,

1. if you read a .csv file and split text by "\n" ==> you have an array (each CSV line is an element of this array)

2. Assuming you have another array with data to input ==> alike ['FAIL','PASS','FAIL']

3. Assuming you want to input this as a 5th column

so you need to loop - split - splice - join

something like:

--------------------------------------------------

var

  mTotalArray, // csvFile.read().split("\n")

  mLineArray, // current  mTotalArray element.split(",")

  mInputArray, // your data

  k,

  mTargetColumn = 5; // number of target column

for (k = 0; k < mTotalArray.length; k++) {

  mLineArray = mTotalArray.split(",");

  mLineArray.splice(mTargetColumn - 1, 1, mInputArray);

  mTotalArray = mLineArray.join();

  }

//After this you can write entire string - mTotalArray.join("\n") - into your CSV file

---------------------------------------------------------

Jarek

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
Participant ,
Nov 09, 2016 Nov 09, 2016

Copy link to clipboard

Copied

var f = File.openDialog();

f.open('r');

var arr = [];

while ( !f.eof ) {

  arr.push (  f.readln() );

}

f.close();

arr[0] = arr[0]+"\t\t"+"result";

arr[1] = arr[1]+"\t\t"+"FAIL";

arr[2] = arr[2]+"\t\t"+"SUCCESS";

arr[3] = arr[3]+"\t\t"+"FAIL";

f.open('w');

f.write(arr.join("\r"));

f.close();

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