InDesign script to put the excel file

Hi all, I'm new to Indesign Scripting, and I hope someone can help me with the following code:

All I want to do is:

  1. Open the indesign file
  2. Open excel file
  3. ExcelFile place as a table (with active flow)
  4. export as PDF & save document

Thank you!

//Define file to open
var myDocumentFile = new File("/d/Projecten/Indesign Server/document.indd");
//Define file to save
//var mySaveFile = new File("/d/Projecten/Indesign Server/document_save.indd");
//Define file to export
var exportPDF = new File("/d/Projecten/Indesign Server/document_save.pdf");
//Open xls-file to place as table
var myExcelFile = new File ("/d/Projecten/Indesign Server/products.xls");

var result = "";
if(!myDocumentFile.exists) {
    result = "Unable to find DOCUMENT:  " + myDocumentFile.path;
    $.writeln(result);
    exit();
} else if(!myExcelFile.exists) {
    result = "Unable to find EXCEL:  " + myDocumentFile.path;
    $.writeln(result);
    exit();
} else {
    // Open file
    var myDocument = app.open(myDocumentFile);
    with(app.documents.item(0).pages.item(0)){
        myTarget = textFrames.item("tabel");
    }
    var myPage = myDocument.pages.item(0);

    //Set excel placement properties
    setXLimportPrefs();

    // Place Excel file
       try {
             $.writeln("Place Excel file");
            //HELP!! HOW TO PLACE EXCEL FILE?
            //myTextFrame.place(myFile);
        }
        catch (e) {
             $.writeln("Place Excel file "  + e + " " + app.excelImportPreferences.errorCode);
            myDocument.close();
            exit();
        } 
    if(!exportPDF.parent.exists && !exportPDF.parent.create()) {
        result = "Not exported.  Unable to create the folder:  " + exportPDF.parent.fullName;
        $.writeln(result);
    } else {
        app.documents.item(0).exportFile(ExportFormat.pdfType, exportPDF, app.pdfExportPresets.item("[Press Quality]"));
    }
    myDocument.exportFile(ExportFormat.PDF_TYPE,exportPDF);
    myDocument.close();
}

function setXLimportPrefs(){    $.writeln("setXLimportPrefs()");
        with(app.excelImportPreferences){
            //alignmentStyle property can be:
            //AlignmentStyleOptions.centerAlign
            //AlignmentStyleOptions.leftAlign
            //AlignmentStyleOptions.rightAlign
            //AlignmentStyleOptions.spreadsheet
            alignmentStyle = AlignmentStyleOptions.spreadsheet;
            decimalPlaces = 4;
            preserveGraphics = true;
            //Enter the range you want to import as "start cell:end cell".
            rangeName = "A1:B16";
            sheetIndex = 1;
            sheetName = "Appetizers";
            showHiddenCells = false;
            //tableFormatting property can be:
            //TableFormattingOptions.excelFormattedTable
            //TableFormattingOptions.excelUnformattedTabbedText
            //TableFormattingOptions.excelUnformattedTable
            tableFormatting = TableFormattingOptions.excelFormattedTable;
            useTypographersQuotes = true;
            viewName = "";
        }
}
result;

myTextFrame is not defined in your script.

It works for me:

myTextFrame = app.selection[0];
var myExcelFile = new File ("~/Documents/idml/some file.xlsx");
myTextFrame.place (myExcelFile);

-When I select a text block, of course.

To debug this, you can remove the try... catch statements because they're actually hiding the error now: InDesign can place the file, but the variable does not exist.

Thankfully, I fell it many times before.

Tags: InDesign

Similar Questions

  • Date format changes when you put an Excel file in Indesign

    I have an Excel sheet with the date format DD-MM-YYYY.

    I need to put this Excel file in Indesign - and the link, so I can update the Excel sheet and put it auto updated in Indesign.

    So I put my file management preferences to "create links when placing text years Spreadsheeet Files", go to file > Place and choose my Excel sheet. In the import option, I don't see any option to keep the date format. But when I look at the table in Indesign changed the date format DD/MM/YYYY.

    The same thing happens if I chose 'To format table' or 'Unofrmatted'. That if I copy and paste the table actually the show dates above right. But it's not a solution for me, since I need the linked Excel file!

    So, do I did wrong? Is there some settings in Indesign to preserve the format of Excel date instead of change?

    I use the Mac version and I get different results with the 2011 and older versions. I tested the top down and the values are different. On windows, MS Office is better, so I often work on Mac, but change to Windows, then save again with a new file name, and use it. But not everyone has this opportunity.

    With Excel on Mac is a huge problem that. and exchanged everwhere in its German version. It's ok in numbers, as German and English exchanged. and,

    But with the files exported as CSV, it becomes a huge problem, because Excel separates files CSV Comma, but pointed, and no other application (and neither itsself Excel) will read these files correctly. Excel on Mac is so good for the calculation, but if you go information in another application it is a mess.

  • Report and read the Excel file

    Hi all

    I need to match the styles of paragraphs with Indesign and files the Excel file.

    Excel file consists of (approximately 500 paragraph Styles) naming of the files of standard paragraph styles

    Files InDesign with 100 paragraph Styles.

    My request:

    I need to generate the report if Indesign paragraph styles that are not in the Excel file.

    for example,.

    Indesign file Excel file

    h1                             H1

    h2                              h2

    h3                              BL

    tx                              tx1

    TX1

    TX2

    Create the report as:

    Paragraph error style is H1 and BL in Indesign file

    Created script:

    var myDoc = app.activeDocument;
    
    var myPstyles = app.activeDocument.allParagraphStyles;
    
    alert("myPstyles: " + myPstyles.length)
    
    for(i=0; i<myPstyles.length; i++)
    {
         var IndesignPStyles = myPstyles[i].name;
        alert(myPstyles[i].name)
        }
    //_____________________________________________________________
    
    //Help Here
    
    var myFile = File.openDialog("Choose a tab delimitted txt file:");
    if (!myFile){
    exit();
    }     
     
    myFile.open('r');
    while (myFile.eof==false){
         line=myFile.readln();
         line = line.split("\t");
         myFind = line[0];
    }
    
    
    

    Could someone help with this request.

    Thanks in advance

    Beginner_X

    Hi BEGINNER_X,

    First of all, you must convert the excel file to the format of files "*.csv or delimited by tabs. (I use commas .csv file).

    You posted in above code JS reading only the names of paragraph style. Then another code is read only comma-delimited text file, but you are not comparing the paragraph style in the list of excel files. You missed here.

    Please try the JS code below his works very well, but not generated the report file. I hope that you will generate the report of your side file.

    var myFile = File.openDialog("Choose a tab delimitted txt file:");
    if (!myFile){
    exit();
    }     
    
    var myArray = []
    myFile.open('r');
    while (myFile.eof==false){
        var line=myFile.readln().split(",");
        myArray.push(line[0]);
        }
    
    var myDoc = app.activeDocument;
    var myPstyles = app.activeDocument.allParagraphStyles;
    
    Array.prototype.contains = function(obj) {
        var i = this.length;
        while (i--) {
            if (this[i] === obj) {
                return true;
            }
        }
        return false;
    }
    
    var myMissingStyle =[];
    for(i=2; i
    

    THX,

    csm_phil

  • Search and replace the contents of the excel file

    Hello

    I have the list in the excel file that needs to replace. The script should read the excel then replace to open InDesign documents.

    The excel (*.xls) file has two columns, the first column has our old. and the second column has the new numbers to replace.

    Ex:

    Column 1 column 2

    (Research)               (Replace)

    -----------------------------------

    4257/2 = > 1/2

    4257/3 = > 1/3

    4257/4 = > 1/4

    ....

    3257/2 = > 1/5

    3257/3 = > 1/6

    3257/4 = > 1/7

    ....

    4457/4 = > 2/2

    4457/5 = > 2/3

    4457/6 = > 2/4

    4457/7 = > 2/5

    ......

    Thanks in advance,

    Thiru

    Hi Poirier,

    I modified your request for entry of csv file.

    Please save it as the xls to text delimetted tab. See the snapshot below.

    Then, run the provided scripts it will change the values.

    var myFile = File.openDialog("Choose a tab delimitted txt file:");
    if (!myFile){
    exit();
    }     
    
    myFile.open('r');
    while (myFile.eof==false){
         line=myFile.readln();
         line = line.split("\t");
         myFind = line[0];
         myChange = line[1];
         app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
         app.findGrepPreferences.findWhat = myFind;
         app.changeGrepPreferences.changeTo=myChange;
         app.documents.item(0).changeGrep();
         app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
         }
    myFile.close();
    

    THX

    csm_phil

  • labView send data wireless node for the excel file

    Hi all

    I used the basic tutorial for the network of wireless sensors OR. http://www.ni.com/tutorial/8890/en/. I finished it with a single node. The next phase of my project is to send the data from the node and the date and time in an excel file every hour. Is there any advice I can get to at least send the date and the data in the excel file? I'm using labView in 2012

    I change, because I put the text instead of excel file

    You cannot connect a scalar to the entry level that is needed. A solution would be to insert a table to build before the writing on the worksheet.

  • Create rectangles of information in the excel file... Help!

    I need help and have NO idea of what I'm doing. I have an excel file with thousands of lines, each with a column for the coordinate x, y-suface, the height and width of a rectangle. I need a script that will ask me to select the excel file, read the excel file and create rectangles of each of thousands of lines. I guess it would be simple enough for someone who knows what they're doing, but I have no idea where to start. I work in a windows environment and I have Illustrator CS4. Any suggestions? All scripts out there that could give me a start?

    you go, it's VBA code, I prefer to use it when I need to have Excel speak to Illustrator directly without exporting the data in Excel.

    to set up...

    -Open Excel

    -Press on Alt + F11 to bring up the editor

    -in the Tools menu, click references.

    -Add a reference to 'Adobe Illustrator CS5 type library' (or CS4 or your version)

    -in the perso.xls (or any other book) to add a Module. Personal is a comprehensive workbook that is always available. If you don't see it, go back to Excel and save a macro, anything will do. Who will create the personal folder.

    -type the following in this module

    Sub makeSquares()
        'carlos canto // 6/26/13
        'reads the active Excel workbook data to create squares in Illustrator
        'data is organized in rows as follows x, y, width, height
        'data has no headers, first row in cell "A1"
    
        Dim iapp As New Illustrator.Application
        Dim idoc As Illustrator.Document
        Dim isquare As Illustrator.PathItem
    
        Dim rowcount As Integer
        Dim x As Double
        Dim y As Double
        Dim w As Double
        Dim h As Double
    
        rowcount = Cells(1, 1).CurrentRegion.Rows.Count
    
        Set idoc = iapp.Documents.Add
    
        For i = 1 To rowcount
            x = Cells(i, 1)
            y = Cells(i, 2)
            w = Cells(i, 3)
            h = Cells(i, 4)
    
            Set isquare = idoc.PathItems.Rectangle(y, x, w, h)
        Next
    
        Set isquare = Nothing
        Set idoc = Nothing
        Set iapp = Nothing
    End Sub
    

    -Save the personal book

    -to run, move the cursor anywhere inside the slot... End Sub and press F5

    For simplicity, launch illustrator before running the script

  • Download and open the Excel files on iPad Pro

    I have the new iPad Pro.  I have Office 365 is installed.  In my work, I run queries of data on a server and the query result comes to me in Excel.  I want to download the Excel file and open it for editing on my iPad Pro.  What I have actually / to accomplish this task?

    You should be able to do this by using numbers

    https://www.Apple.com/ca/support/iWork-for-icloud/numbers/

  • Entries are concatenated in the same column in the excel file

    Hi, I really need help in this emergency. The problem is when I open the spreadsheet file after you run the program below, all the values that I believe are concatenated in the same column. However, there are 2 different analog inputs which I want in 2 different columns. I'm getting the 2 waveforms in the same graph, but when I open the excel file, it seems that the entries are concatenated in the same column. Someone knows how to fix this? Thank you very much.

    Hi Ben 64,.

    Thanks a lot again. I did as you said and I removed the dynamic data and logged files added directly to the results. I'm still checking if the program works as I can branch only when I return to work tomorrow. Tell me if you think it might be able to work this time. Thanks a lot again!

  • It is an intermittent problem, as the excellent files, powerpoint will corrupt network drive.

    It is an intermittent problem, as the excellent files, powerpoint will corrupt network drive. Any help will be much appreciated.

    To avoid this, I'm making sure that files are not left open so much because we run backup incremental three times in a week.

    Files is not very high - about - 2 MB

    Some screenshots are inserted

    Thank you

    Amit

    http://answers.Microsoft.com/en-us/Office/Forum/office_xp-Excel?tab=unanswered&TM=1373425932359

    above is office xp, excel forum you might be better off poster in this forum that many people are familiar with excel and powerpoint.

  • DirectX June 2010 asking where to put the extracted files. Where should I put them?

    DirectX June 2010 asking where to put the extracted files. Where should I put them?

    Create a new folder and extract the files to the new folder.

    Let us know if that helps.

  • Moving files: I am wanting to put the existing files to a new folder, how do I create a new folder and move those file to the new folder?

    I am wanting to put the existing files to a new folder, how do I create a new folder and move those file to the new folder?

    I am wanting to put the existing files to a new folder, how do I create a new folder and move those file to the new folder?

    Hello

    Go t the location where you want to create the new folder, right-click and select new/folder. Name the folder.

    Go to where the files, select the files and then use the right mouse button to drag the files into the new folder. When you drop the file, a pop-up menu, select the Move option.

    Let us know if you have any other questions.

    Thank you for using Windows 7

    Ronnie Vernon MVP
  • I have a form with the field names are the same as my excel sheet spread, how can I do the pdf file to find the excel file?

    Is it possible to link them together for the PDF will automatically fill in the excel file? Also is there a way to fill in a field in the PDF with a combination of two fields in the excel file. Example pdf 'name' a 'name' and 'name' excel file, I want to fill in the name of the PDF with a combination of the first name and name of the excel file.

    Thanks for any help.

    Using the example above, the custom in the 'name' field calculation code will be:

    This.getField("first_name").value = Event.Value + "" + this.getField("last_name").value;

  • Output in the Excel file

    Hello

    How can I get a query result in the EXCEL file? I use Oracle11g in soundcards XP.

    Thank you.
    Asif

    Published by: asif.maqbool on April 16, 2013 02:17

    SQL > the value html markup on
    SQL > set off comments
    SQL > spool c:\.xls
    SQL > select * from XXXXXX where XXXXXX;
    SQL > spool off
    SQL > set markup html off

  • can export us all the data in the Excel file format table in oracle?

    Hello

    Is it possible to export all the data in the table to the excel file format?

    Thank you

    Hi Mohammed_82!

    Oracle itself has no tools to export in csv or excel format. You have to search third-party tools such as Toad or the Torah.

    concerning

  • Save the data to the excel file

    Hello

    I make a program reads the value of the probe via serial port... but I don't know how I can record this data in excel file... I open the example in the labview example, but I don't want to like this... becaue I use a while loop in my program that cause opened "multi" excel file... . How can I solve this problem?

    You need to think about what you want to do, not how you want to do.  I'll make a few assumptions here - adopt to your notebook loads "real."

    I guess you want to take a series of readings from a device (sensor, serial port).  I suppose you take multiple readings, perhaps their display on a table or chart, for a certain period of time.  Once you have a set of data, you want to save all the data in an Excel file.

    If this scenario is correct, there are three distinct phases to this task - implemented the data collection (open the serial port, manage the interactions of the user according to the needs), data collection (and potentially produce tables or graphs) and save the data.  Note that only step 2, collect data, involves a repetitive action appropriate for a while loop.  Once you have all the data, you can then open an Excel report, use something like Excel table easy to put the Table in the report or chart Excel easy to put a chart in the report and save the report in evidence, save the report.

    If you are using a relatively recent version of LabVIEW (2010 or later), the new generation Excel report screws are pretty easy to use.

Maybe you are looking for