1 Reply Latest reply on Aug 12, 2015 8:10 AM by G. Singelmann

    Merged Cells confuse the counter

    hobbes_1979 Level 1

      Hello community,

      thanks in advance for any help, idea, comment!


      I have a weird issue: I browse via a JScript through a table in InDesign to update prices given by a .csv.

      To do so,

      - I search for a Part-Nr given by the .csv and draw the indexes (parentRow, parentColumn) from the matching cell

      - then I jump one cell to the right and place the new price (also given by the csv)


      That works fine, AS LONG AS there are no merged cells in the row involved. If there are merged cells, then the search-response is correct, but when I try to place the right price, it jumps one cell too far (because earlier in the row, two cells are merged to one cell). The funny thing is, that when I ask for parentColumn of the cell, where the price should land, the answer is right. But when I then try to place new content in exact this cell using the coordinates just given, it jumps one cell further as wanted???


      Here the code-piece that is inflicted:


      app.findTextPreferences.findWhat = "Part-Nr given from the csv";

      var myHit = myDoc.findText();


      if(myHit.length > 0){

          myCell = myHit[0].parent;

          myCell.parentRow.cells[myCell.parentColumn.index+1].contents = "Price given from the csv";



      Anyone an idea what causes that behaviour and what I can do to avoid it?

      Thanks a lot!



        • 1. Re: Merged Cells confuse the counter
          G. Singelmann Level 3

          You get the partnr cell by taking the parent of the found text. That, logically, is the correct cell.


          Then you take the index of the parent column, let’s say "4" and try to put the price into the 5th cell of the row. Not into the cell whose parent column has the index "5", but the fifth cell.

          If there are merged cells to the left, the fifth cell is the one whose parent column has the index "6".


          I prefer using the name of the cells to avoid having to dabble with merged cells.



          myCell = myHit[0].parent;

          var myTable = myCell;

          while (myTable.constructor.name != "Table") myTable = myTable.parent;


          var myName = myCell.name.split(":");

          myName[0] = myName[0] + 1;

          myName = myName.join(":");

          myTable.cells.itemByName( myName ).contents = "Price given from the csv";


          (Haven’t tested this, but the principle is valid)