4 Replies Latest reply on Jul 23, 2009 2:12 PM by SteveCaine

    JS CS4 setting header and footer rows in table

    SteveCaine Level 1

      How do I set rows in a table to be either header or footer rows?

       

      I have an Excel spreadsheet that's been imported (and linked) into my document as a formatted table. I can designate header and footer rows in the InDesign UI (by selecting rows and then selecting the menu item "Table > Convert Rows > To Header/To Footer"), but when I update the link to pick up changes in the spreadsheet, all the rows are body rows again.

       

      I've tried selecting the row and then setting its rowType property to RowTypes.HEADER_ROW or RowTypes.FOOTER_ROW, but (not surprisingly) I get a "cannot set row type" error.

       

      Thanks in advance for any help you can offer

        • 1. Re: JS CS4 setting header and footer rows in table
          [Jongware] Most Valuable Participant

          "Not surprisingly" -- it is tagged a read/write property!

           

          Try this for a workaround:

           

          myTable.headerRowCount = 1;

          myTable.footerRowCount = 1;

           

          on the original table. It's also r/w, but this one might work.

           

          (After some experimenting:) If you select any cell, this script will fail. However, if you select a top cell (so you can set its parentRow to be a header), both methods work just fine. Note that the script will fail if the table already has a header.

           

          if (app.selection[0].constructor.name != "Cell")
          {
           alert ("come on! select a cell!");
           exit(0);
          }
          a = app.selection[0].parentRow.parent;
          alert ("this a "+a.constructor.name);
          a.footerRowCount = 1;
          a = app.selection[0].parentRow;
          alert ("this is a row of "+enumToText(a.rowType));
          a.rowType = RowTypes.HEADER_ROW;
          alert ("this is now a "+enumToText(a.rowType));
          function enumToText (val)
          {
           var result = "";
           while (val > 0)
           {
            result = result+String.fromCharCode(val % 256);
            val = Math.floor( val/256 );
           }
           return result;
          }
          
          • 2. Re: JS CS4 setting header and footer rows in table
            SteveCaine Level 1

            Thanks for the quick reply.

             

            Your script does create header and footer rows in simple tables, but not the table I'm working on.

             

            Turns out the key is that my table has some merged cells in the rows I'm trying to make into header rows. If I unmerge the cells, then your script works (not surprisingly!).

             

            (Of course, the UI does let me designate header and footer rows even when they contain merged cells. Just one more example where scripting is more limited than direct manipulation in the UI.)

             

            How do I know which properties are read/write, and which are read-only? Where is this documented? If I look at the Row object in the "Object Model Viewer" I notice (now) that some properties have a darker icon than others. Is that the flag for read/write vs read-only? Does it say this anywhere in the CS4 JS scripting docs? I couldn't find anything when I went looking, hence my confusion about rowType's read/write status.

             

            Anyway, thanks again for your help.

            • 3. Re: JS CS4 setting header and footer rows in table
              [Jongware] Most Valuable Participant
              How do I know which properties are read/write, and which are read-only? Where is this documented? If I look at the Row object in the "Object Model Viewer" I notice (now) that some properties have a darker icon than others.

               

              They do? I really don't like the ESTK. Its "helpful" popping up suggestions are usually the wrong ones and they eat up too much CPU time, disrupting my typing rate. I also don't like the panels (whereas in ID I like them), and the default fonts and color settings. I even didn't bother to change them to my preferences. The Help system is ... novel ... is the kindest I can think of off-hand. After a few clicks I have to scroll through stacks of history, trying to regain my train of thought. And saving a single document in "c:\documents and settings\users\[myname]\adobe\indesign stuff\version 5.0\a lot more pathnames\and then the filename too.jsx" expands the Recent File menu width to 3/4s of my screen. And its Search/Replace dialog is thorougly non-standard. And it does not have a "search in files" option, which is quite necessary, as I have a vast library of scripts, dating back all the way to CS. And it doesn't have a GREP search and replace. And in general I don't like it as a text editor either.

               

              The biggest drawback of not using it is that you don't have access to the JS help -- that's why I took the original Help data files and re-wrote them into a set of hyperlinked-to-the-extreme HTML files, and (with much appreciated help of fellow ID scripter ABC GREEN) could transform that again into a single indexed and fully searchable Windows CHM Help file. <PLUG>Downloadable for CS3 and CS4 from http://www.jongware.com/idjshelp.html -- for CS3, you might want to download the separate JavaScript Base Class and the ScriptUI files; for CS4 everything's intergrated into one handy set.</PLUG>

               

              Did I mention that I reserved an entire column for "read/write"/"read-only"?

               

              Even if you are using a Mac, try the HTML (although searching is a bit troublesome), or find a Windows CHM Help file reader. Unfortunately, I'm still awaiting the skilled Mac programmer that can convert the HTML into a real Mac Dictionary dictionary ... (I can supply the necessary files, only need to build it! Hint, hint!)

              • 4. Re: JS CS4 setting header and footer rows in table
                SteveCaine Level 1

                So the short answer to "how do you know which properties are read/write, and which are read-only?" is, "You just have to know!"

                 

                The long answer is, "You have to reverse-engineer Adobe's help files to create your own reference." , or "You have to know someone who has already done this for you."

                 

                Now I have the latter, for which I thank you profusely.

                 

                Still, it seems the color of the "=X" icon next to each property in the ExtendScript Toolkit CS4's Object Model Viewer does indicate whether that property is read/write or read-only, which is a very useful thing to know. The read-only properties' icon looks dimmed relative to the read/write properties' icon, as if it were a disabled button. Now if only this were documented somewhere easy to find!

                 

                Thanks again.