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

How do I skip the excel First line (Heading) while write the data using Javascript

Participant ,
Aug 10, 2022 Aug 10, 2022

Copy link to clipboard

Copied

Hi,

I would like to write the data from Photoshop into Excel template. Excel template having the head line (see below snap shot)

Screenshot 2022-08-10 at 10.09.57 PM.png

 

The task is to write the data from 2nd row. For that I am using the following code.

 

var rep = File.openDialog("Please choose the file");
rep.open("w");
var imageNm =["1", "2","3"];
for(var x=0; x<imageNm.length-1; x++){
rep.write("Asuvath"+"\t"+"smartObjPathFnl[x]"+"\t"+"imageNm[x]"+"\t"+"imgSize[x]"+"\t"+"imgRes[x]"+"\n");
}
 
But this code replace the heading (see below snap shot).
Screenshot 2022-08-10 at 10.12.33 PM.png
 
Can any one please advise code for to keep the Heading as is, and to write the data from 2nd row onwards.

Thanks
Asuvath
TOPICS
Actions and scripting , macOS

Views

190

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
Adobe
LEGEND ,
Aug 10, 2022 Aug 10, 2022

Copy link to clipboard

Copied

When you open for write, that deletes whatever is already in the file. You can open for append, or better yet- open the old file, copy the header, write it into a new file, and then write your data. You can save and swap old and new when you finish.

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 ,
Aug 11, 2022 Aug 11, 2022

Copy link to clipboard

Copied

@Lumigraphics, I am tried, but the heading is not copied properly, instead of heading content I get junk characters.

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 ,
Aug 10, 2022 Aug 10, 2022

Copy link to clipboard

Copied

@Asuvath 

 

I only have limited experience with writing to text files, so perhaps something like:

 

var rep = File.openDialog("Please choose the file");
var os = $.os.toLowerCase().indexOf("mac") >= 0 ? "mac" : "windows";
if (os === "mac") {
    repLF = "Unix";
} else {
   repLF = "Windows";
}
rep.encoding = "UTF-8";
rep.lineFeed = repLF;
// r = read mode | w = write mode | a = append | e = edit
rep.open("r");
var headerRow = rep.readln(1);
rep.close(); // not sure if needed, seems to work OK with or without
rep.open("w");
rep.writeln(headerRow);
var imageNm =["1", "2","3"];
for(var x=0; x<imageNm.length-1; x++){
rep.write("Asuvath"+"\t"+"smartObjPathFnl[x]"+"\t"+"imageNm[x]"+"\t"+"imgSize[x]"+"\t"+"imgRes[x]"+"\n");
}
rep.close(); // not sure on the necessity to close or not?

 

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 ,
Aug 11, 2022 Aug 11, 2022

Copy link to clipboard

Copied

@Stephen_A_Marsh Thanks for checking, but still I am not get expected result. Can you please check and advise.

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 ,
Aug 11, 2022 Aug 11, 2022

Copy link to clipboard

Copied

It would help if you gave the forum something to go on!

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 ,
Aug 11, 2022 Aug 11, 2022

Copy link to clipboard

Copied

Hi @Stephen_A_Marsh ,
Sure. I used the below code.

var rep = File.openDialog("Please choose the file");
var os = $.os.toLowerCase().indexOf("mac") >= 0 ? "mac" : "windows";
if (os === "mac") {
repLF = "Unix";
} else {
repLF = "Windows";
}
rep.encoding = "UTF-8";
rep.lineFeed = repLF;

rep.open("r");
var headerRow = rep.readln(1);
rep.open("w");
alert(headerRow.length);
rep.writeln(headerRow);
var imageNm =["1", "2","3"];

for(var x=0; x<imageNm.length-1; x++){
rep.write("Asuvath"+"\t"+"smartObjPathFnl[x]"+"\t"+"imageNm[x]"+"\t"+"imgSize[x]"+"\t"+"imgRes[x]"+"\n");
}

Result is
Screenshot 2022-08-11 at 5.53.39 PM.png


I herewith attached Template excel for your reference.

Thanks

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
LEGEND ,
Aug 11, 2022 Aug 11, 2022

Copy link to clipboard

Copied

For one thing, you need to close the file before reopening it.

Are these CSV or tab-delimited? You realize that Bridge cannot write XLSX files?

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 ,
Aug 11, 2022 Aug 11, 2022

Copy link to clipboard

Copied

Hi @Lumigraphics 

Okey, I tried, but the result it same. Tab delimited. Yes, I aware on that, thats the reason I am using XLS instead of XLSX.
Thanks

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
LEGEND ,
Aug 11, 2022 Aug 11, 2022

Copy link to clipboard

Copied

LATEST

You can't use XLS format either. That's why your first line is mangled. ONLY plain text (CSV/tab) files will work.

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