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

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

Participant ,
Aug 10, 2022 Aug 10, 2022

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.pngexpand image

 

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.pngexpand image
 
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
533
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
Adobe
LEGEND ,
Aug 10, 2022 Aug 10, 2022

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.

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

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

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

@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?

 

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

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

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

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

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

Hi @Stephen 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.pngexpand image


I herewith attached Template excel for your reference.

Thanks

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

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?

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

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

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

You can't use XLS format either. That's why your first line is mangled. ONLY plain text (CSV/tab) files 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