Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

Delete empty cells from Data Merge via JS

Return to Member Forum

  • Author
    Posts
    • #56213
      Anonymous
      Inactive

      Hello,

      I am trying to sort a data merge document out. Everything is working well, howver I have some cells within tables that are empty (ie have no content except for a blank placeholder and an end of story mark). I need to automatically find those cells and then delete them.

      I sourced a script from Adobe forums to delete all empty cells in a document, but it either crashes Indesign, or does nothing. Here is that script:

      var myDocument = app.activeDocument;

      for(var i=myDocument.textFrames.length-1; i>=0; i–){

      for(var j=myDocument.textFrames[i].tables.length-1; j>=0; j–){

      for(var k=myDocument.textFrames[i].tables[j].rows.length-1; k>=0; k–){

      myContents = 0;

      for(var l=myDocument.textFrames[i].tables[j].rows[k].cells.length-1; l>=0; l–){

      if (myDocument.textFrames[i].tables[j].rows[k].cells[l].contents != “”) myContents++;

      }

      if (myContents == 0) myDocument.textFrames[i].tables[j].rows[k].remove();

      }

      }

      }

      Help??

    • #56227

      Does this make it work?

      if (myDocument.textFrames[i].tables[j].rows[k].cells[l].contents.length > 0)

      The 'contents' property of a cell is not guaranteed to be a string — it can also be a single special character or nothing at all (not even an empty string).

    • #56238
      Anonymous
      Inactive

      Hey Jongware,

      Thanks for your response.

      I've got to say I'm getting hooked on this scripting. Before I made this document I have never used it before. Suddenly my script palette is filling up and I can make text-heavy documents in no time at all.

      I updated the script as discussed above. The document didn't crash, but the cells didn't delete either. I did get a spinning beachball for a minute or so, suggesting it was doing something, but no real results I can see.

      Here is a screen shot of the cells:

      I can remove the cells with content like “Email: ” by searching for those via the following script. You will notice that the 'empty cell has a placeholder which is an empty Cell from excel. Is there a way I can search for that expression in GREP? I am not sure how to express it in GREP though:

      // JavaScript Document
      app.findGrepPreferences = null;
      app.findGrepPreferences.findWhat = “Email:s+Z“;
      empties = app.activeDocument.findGrep(true);
      for (i = 0; i < empties.length; i++)
      if (empties[i].parent instanceof Cell)
      empties[i].parent.parentRow.remove();

      Do you know how I can change the expression for the values that appear in the empty cells?

      Thanks in advance, really appreciate your help.

    • #56242

      Oh I see. My suggestion does work, and so did (probably) your own first try. Nothing happened because … the 'empty' cells are not empty!

      If I zoom in on the image, I can see a few tiny blue markers, quite different from the standard '#' end-of-text marker. They are also visible in the “Email” field, so apparently they get found by that GREP expression.

      I suggest using something like “As*Z” — any number of spaces, and hopefully that includes that unknown marker.

    • #56247

      (Two days later) Eh. That oughta be something like “As*Z” …

Viewing 4 reply threads
  • You must be logged in to reply to this topic.
Forum Ads