4 Replies Latest reply on Oct 19, 2010 10:07 PM by Boble5

    Read and import data from excel file

    Boble

      Hi guys, with indesign scripting can read and import data from an excel or csv file. I have tried the activexobject and it does not work


      var excel = new ActiveXObject("Excel.Application");
      var excel_file = excel.Workbooks.Open("D:\Delete\Indesign\positions.xls");
      var excel_sheet = excel_file.Worksheets("Sheet1");

       

      Is there a way? I want to be able to insert data from an excel file into specific textframes.

       

      Thanks for any help.

        • 1. Re: Read and import data from excel file
          Steven.. Level 3

          Is your question how to read the data in excel or how to place into inDesign

          • 2. Re: Read and import data from excel file
            Boble Level 1

            How to read it. Sort of treating it as a database  of some kind.

             

             

            So i could have an excel file on my hard drive then fill up textframes with values from the excel file.

             

            Pseudo code would be something like this

             

            Read excel file

            doc.textFrames.item(0).contents=Row1.Column1.From.Excel.File

            doc.textframes.item(1).contents=Row2.Colum1.From.Excel.File

             

             

             

            Obviously that's just imaginary syntax! But i hope it explains what i want to do.

            • 3. Re: Read and import data from excel file
              Steven.. Level 3

              I don't know if excel can be accessed via javascript, however using vbscript you would be able to take advantage of a robust com object model

              1 person found this helpful
              • 4. Re: Read and import data from excel file
                Boble5

                Trying to do this again, now in Visual Basic. This works perfectly.

                 

                Set myInDesign = CreateObject("InDesign.Application")
                Set myDocument = myInDesign.ActiveDocument
                Set myPages = myDocument.Pages

                 

                 

                Set myExcel = CreateObject("Excel.Application")
                Set objWorkbook = myExcel.Workbooks.Open("C:\Downloads\links.xls")
                Set objSheet = myExcel.ActiveWorkbook.WorkSheets(1)
                value_one=objSheet.Cells(1,1).Value
                msgbox ( value_one )
                objWorkBook.close

                 

                Amazing stuff. What a buzz