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

Help for fix script

Contributor ,
May 10, 2019 May 10, 2019

Hi experts,

my script like this:

var file = new File("~/Desktop/Book contents and page number.txt");
for(var i = 0; i < app.selection.length; i++)  {
    if (app.selection.hasOwnProperty ( "baseline" )) {
    myContents = app.selection.contents;
    WriteToFile(file, myContents);
    }
    else if (app.selection.constructor.name == "Cell") {
    myCellCeontents = app.selection.cells.everyItem().texts.everyItem().contents;
    myCellCeontents += "\r";
    WriteToFile(file, myCellCeontents);
    }
else exit ();
}

       
function WriteToFile(file, text)
{
file.encoding = "UTF-8";
file.open("w");
file.write(text);
file.close();
file.execute();
}

for report my selection contents.

but

after run script

see screen movie:

text stories.gif

my come out like this:

2014,HK$’000,,,,921, ,,34,321, ,,4,250, ,,662, ,,45,11,027, ,,, ,,555,5,087, ,,5,642,

it isn't my goal.

how can I make the result like this:

2014
HK$’000

921

34,321

4,250

662

45
11,027

555
5,087

5,642

thanks

regard

John

TOPICS
Scripting
463
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

Community Expert , May 10, 2019 May 10, 2019

Hi John,

Change the else if code to the following

else if (app.selection[0].constructor.name == "Cell") {

    myCellCeontents = app.selection[0].cells.everyItem().texts.everyItem().contents;

    WriteToFile(file, myCellCeontents.join("\n"));

}

-Manan

Translate
Community Expert ,
May 10, 2019 May 10, 2019

Hi John,

Change the else if code to the following

else if (app.selection[0].constructor.name == "Cell") {

    myCellCeontents = app.selection[0].cells.everyItem().texts.everyItem().contents;

    WriteToFile(file, myCellCeontents.join("\n"));

}

-Manan

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
Contributor ,
May 10, 2019 May 10, 2019
LATEST

thank you Man,

thank so much.

John

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