count选项卡从选项卡式分隔文本中收集数据.JSX Adob​​e InDesign

时间:2011-09-30 14:12:31

标签: javascript jsx adobe-indesign

我需要知道如何从选项卡式分隔文本文件中读取数据,以便将合并文档导出到正确的位置。

- 将始终为第4个选项卡第2行(组号)目录将按组号

命名

- 已经由私有的.vbs脚本创建了目录

必须放置数据:

app.open(File(dirPath + "Card~" + (group number) + ".indd"));   

还有:

fileName = (group number) + " " + myPageName + " " + date + ".pdf";        
        myFilePath = dirPath + docType + "/" + fileName;
        myFile = new File(myFilePath);
        myDocument.exportFile(ExportFormat.pdfType, myFile, false);

在以前的.vbs脚本中使用此数据文件的内容如下:

    Call TwoDimensionArrayTest
Sub TwoDimensionArrayTest

Dim fso
    Dim oFile
    Dim arrline
    Dim arrItem
    Dim i
    Dim arrMain()
    Dim sFileLocation, strResults
    Dim filesys, folder, path 

    Const forReading = 1
    
strFolder = "P:\RxCut\In Design Implementation\build\Co-Brand\"
mkdir = "P:\RxCut\In Design Implementation\"
Set objFSO = CreateObject("Scripting.FileSystemObject")
For Each objFile In objFSO.GetFolder(strFolder).Files
    If Right(LCase(objFile.Name), 4) = LCase(".txt") Then
    
        ' The file contains on each line:
    ' Text1 (tab) Text2 (tab) Text3 (tab) Text4
    ' Text5 (tab) Text6 (tab) Text7 (tab) Text8
'etc etc

Set fso = CreateObject("Scripting.FileSystemObject")
        sFileLocation = objFile.Name
        
        Set oFile = fso.OpenTextFile(objFile.Name, forReading, False)
        
    Do While oFile.AtEndOfStream <> True
        strResults = oFile.ReadAll
    Loop
    
    ' Close the file
    oFile.Close
    
' Release the object from memory
    Set oFile = Nothing
    
' Return the contents of the file if not Empty
    If Trim(strResults) <> "" Then
        
        ' Create an Array of the Text File
        arrline = Split(strResults, vbNewLine)
    End If
 
    For i = 0 To UBound(arrline)
        If arrline(i) = "" Then
            ' checks for a blank line at the end of stream
            Exit For
        End If 
        
        ReDim Preserve arrMain(i)
        
            arrMain(i) = Split(arrline(i), vbTab)

    Next
    
    path = arrMain(1)(3)
    dir = mkdir & path
    set filesys=CreateObject("Scripting.FileSystemObject") 
If Not filesys.FolderExists(dir) Then 
Set folder = filesys.CreateFolder(dir) 
End If
    
   dir = mkdir & path
   Set folder = filesys.CreateFolder(dir & "\Web")
   Set folder = filesys.CreateFolder(dir & "\Web\Web Cards")
   Set folder = filesys.CreateFolder(dir & "\Web\Web Headers")
   
       fso.MoveFile sFileLocation, arrMain(1)(3) & ".txt"
       
 End If 
 Next
End Sub ' TwoDimensionArrayTest

如何在.jsx中实现类似的东西? 提前致谢, 乔

1 个答案:

答案 0 :(得分:0)

想出来,这将读取1,3并为组号1,3

创建一个变量
 var aFile = File("P:/RxCut/In Design Implementation/build/automate/automate.txt");
    var fileData = readTabDelimitedFile ( aFile ) ;
    //$.writeln(fileData[1][3]); //should contain first tab on second line
    tstdata = fileData[1][3];
    var group = tsdata
    function readTabDelimitedFile ( fPath ) {

    var returnArray = new Array ( ) ;

    //-- Verify that the file exists
    var fileObject = File ( fPath ) ;
    if ( ! fileObject.exists ) {
    return returnArray ; // an empty array because the file doesn't exist.
    }
    //-- Create a regular expression for a tab.
    var tabExpression = new RegExp ( '\\t' ) ;

    //-- Read the file.
    try {
    //-- The file has to be open.
    fileObject.open ('r') ; //-- Open for reading.

    while ( ! fileObject.eof ) {
    var currentLine = fileObject.readln () ;

    if ( tabExpression.test( currentLine ) ) {

    returnArray.push(currentLine.split ('\t')) ;
    }
    }
    fileObject.close() ;
    }

    catch (errMain) {
    try {

    fileObject.close() ;
    }
    //-- if the close generates an error skip it.
    catch (errInner ) { /* nothing here */ }
    }

    return returnArray ;

    var group = returnArray 
    }