2 Replies Latest reply on Aug 19, 2010 4:59 AM by GordonEddey

    Placing xlsx file directly into table

    GordonEddey

      Hi, as always thank you for your help. I am uncertain whether I should have placed three questions, in terms of forum ettiquette, and would someone please tell me if I should not have combined the questions into one post.

       

       

      I am confusing myself so please bear with the simplicty of the questions.

       

      Here is the script:

       

      function placed_3to10 (doc)
      {
      with(doc)
      {
      //pg 1 recto
      var textFrameEdd = docEdd.pages.item(0).textFrames.add
        (
        doc.layers.item('TableLayer')
      , undefined,
      , undefined
      {
      , geometricBounds: [10,15,280,200]
      ,
      }
      );
      //THIS PLACES TEXT DIRECTLY IN THE PARENT TEXT FRAME AS EXPECTED
      //textFrames.parentStory.insertionPoints.item(0).place(File('~/Documents/1add2doc/pg1p4222 .xlsx'))
      //THIS CREATES A TABLE WHICH GOES INTO THE TEXT FRAME AS A 4 X 4 AS EXPECTED
      var tableFrameEdd = textFrames.parentStory.tables.add()
      My FIRST QUESTION is how does one place the xslx data into the table? I have tried several options without success.
      My SECOND QUESTION is how to apply styles to the text frame contents around the table and to the table itself. I have tried the following, but they do not seem to work:
      //TEXT FRAME STYLE
      textFrameEdd = docEdd.pages.item(0).textFrames.item(0).words.item(0).applyParagraphStyle(docEdd.paragrap hStyles.item('INDENTparaBody'))
      //TABLE FRAME STYLE
      tableFrameEdd.appliedTableSyle = docEdd.tableStyles.item('altROWtable')
      My THIRD QUESTION is whether it is possible to write a 'place xslx' script in such a way that one does not need to identify the cells. Can one ignore the range statement in the ExcelImportPreferences script or will this place the entire spreadsheet?
      As always thank you for  your help. I am excited by the potential of scripting and wish my brain were quicker.

        • 1. Re: Placing xlsx file directly into table
          [Jongware] Most Valuable Participant

          1. I don't think you can place an XLSX sheet into an existing table. If you import an XLSX sheet, it's treated just like imported text; you can either place it as a new object (a text frame containing a table containing your data) or use the 'replace' function, which will effectively empty out an existing frame and place the new text (/table) into it.

           

          2. textFrameEdd = docEdd.pages.item(0).textFrames.item(0).words.item(0).applyParagraphS tyle(docEdd.paragraphStyles.item('INDENTparaBody'))

           

          That ought to work -- but "applyParagraphStyle" does not return any value, it's just a function that applies the settings immediately. It returns 'void', meaning, your variable textFrameEdd will be set to 'null' (or 'undefined' or sth).

          A small note is you don't have to target a word, since paragraph styles can only be applied to entire paragraphs. Personally, I'd use the shortcut "direct indexed" form [0] rather than ".item(0)", so I'd probably write this as

           

          docEdd.pages[0].textFrames[0].paragraphs[0].applyParagraphStyle(docEdd.paragraphStyles.ite m('INDENTparaBody'));

           

          An alternative is this, by the way:

           

          docEdd.pages[0].textFrames[0].paragraphs[0].appliedParagraphStyle = docEdd.paragraphStyles.item('INDENTparaBody');

           

          3. Per 2., your variable is cleaned out, so you cannot use it anymore. Furthermore (and more important), you cannot apply a table style to text, which it seems you are trying to do. You should target the table itself instead:

           

          docEdd.pages[0].textFrames[0].tables[0].appliedTableStyle = docEdd.tableStyles.item('altROWtable');

          • 2. Re: Placing xlsx file directly into table
            GordonEddey Level 1

            Thank you so much for your help. Cheers.