Indesign导出段落到基于文本的csv

时间:2015-10-25 01:12:12

标签: javascript csv adobe-indesign

我们正在尝试编写一个简单的脚本来导出Indesign文件中的所有故事 我们只有两种样式标题,这是每篇文章的标题 和文字,这是文章的正文 我们要导出到csv文件(文本),以便我们可以导入一系列我们喜欢的应用程序:

  标题,文字(系列段落)
  " xxxxx"," xxxxxxxxx x x x x xxx xxxxx xxxx xxx"
  " xxxxx"," xxxxxxxxx x x x x xxx xxxxx xxxx xxx"
  " xxxxx"," xxxxxxxxx x x x x xxx xxxxx xxxx xxx"

但是当我们尝试向文件写入"段落内容"的字符串变量时,我们遇到了一个问题。不会写入文件,我们可以在警告对话框中显示它们,但不要将它们写在文本文件中。

问题是第46行,我们不知道是否必须删除一些字符或将内容转换为唯一的文本变量

这是代码

//Exportascsv.js  
      var myStory, myParagraph, myParagraphTemp, myString, myTag, myStartTag;   var myEndTag, myTextStyleRange, myTable;  
      if(app.documents.length !=0){     if(app.documents.item(0).stories.length != 0){   //Open a new text file.  
    var myTextFile = File.saveDialog("Save CSV As", undefined);   //If the user clicked the Cancel button, the result is null.  
    if(myTextFile != null){   //Open the file with write access.  
      myTextFile.open("w");  
      var myCounterArt = 0;   //walk through the stories.  
      for(var myCounter = 0; myCounter < app.documents.item(0).stories.length; myCounter++){  
        myStory = app.documents.item(0).stories.item(myCounter);   // we have stories inside stories (articles in articles sometimes)  
        var myParagraphCounter = 0;  
        myParagraphTemp = "";  
        myString = "";  
        do{  
          myParagraph = myStory.paragraphs.item(myParagraphCounter);  
          myParagraphTemp = "";  
          switch(myParagraph.appliedParagraphStyle.name){   //Headline paragraph style  
              case "Headline":  
                myString = '"'+myParagraph.contents+'","';  
                myParagraphCounter++;  
                break;  
              case "Texto":   //Text paragraph style  
                myString = myString+myParagraph.contents;  
                myParagraphCounter++;  
                break;  
              default:  
                myParagraphCounter++;  
                break;  
          }  
        } while (myParagraphCounter < myStory.paragraphs.length)  
        myString = myString+'"';  
        myTextFile.writeln(myString);  
      }  
      myTextFile.write("\r");  
      myTextFile.close();  
    }     }   }  

0 个答案:

没有答案