![]() I hope that armed with this information, you will find it an easy matter to write a little script to delete all empty rows and columns from your InDesign tables. Work backwards here too to avoid any problems. In such a case, this can throw references to further tables out of sync as well. There are one or two things to be aware of though: If you remove a column or a row, this may throw your reference to subsequent rows or columns off, so, as always, it’s best to work backwards.Īnother danger is that by deleting a row or column, you delete the entire table (because some tables have only a single row or column). With this info, you should be able to loop through all rows and/or columns of all or some tables in an ID document, test whether they’re empty, and if so, remove() them! Some Caveats! And I think that is a pretty failsafe, and quick, method to test for an empty row or column in an InDesign table. If the above line returns True, we know the row is empty. We can use join() to join all of this, to make it easier to test whether the array is in fact empty: ().texts.everyItem().contents.join("") = "" This will get us an array of all the texts in all the cells in the row or column. To get a collection of all texts in those cells, we can write: ().texts.everyItem().contents I’ve shown above how to get a collection of all cells. It’s much, much faster! And, once you get the hang of it, a lot easier, too. But this is very slow, and unnecessary.Ī basic principle of InDesign scripting is to leverage the power of collections whenever possible instead of using Javascript looping. The simple, straightforward solution is to loop through all cells in the row or column (and I’ve seen some scripts floating about on the Interwebs that do this). The next question then is how to test quickly whether all the cells in a row or column are empty. If that is an empty string, you can be sure that the cell is empty and that there is not even any overset, invisible text attached to it. Given m圜ell being an InDesign table cell, you can check m圜 However, cells do not have a Story property. But checking myTextFrame.parentStory will return the Story object that the TextFrame is part of, and that can be checked to see if its empty. If a TextFrame is completely overset, that is, there are no visible characters in a text frame because they are all overset, then checking ntents will return an empty string, just like an overset table cell. Initially (not having scripted tables for a while), I though that a cell has a Story property, just like an InDesign text frame. To fix this, we have to find a different property to test. Whoops! Overset Text Frames versus Overset Cells ![]() What this means is that rows and columns that are not really empty will be deleted. If a cell is overset, its contents property returns an empty string. Why? Because a table cell in InDesign can be overset. However, it quickly became clear that this is an inadequate test. ![]() So, if after all that c remains empty, we know we have an empty row.Īnd of course, we can do the same thing with columns as well. Now, join(“”) is a standard Javascript command to join the contents of an array. So when we write cells.everyItem().content we get an array of all the contents of the cells. The contents of a cell is its text contents. Given a table row r, we can write: c = r.cells.everyItem().contents.join("") Īnd then test whether c is empty: if (c = "") Ĭells.everyItem() gets us a collection of all cells in the row. So the first question is: How to detect whether a table row or column is empty in InDesign? Detecting Empty Rows or Columns in an InDesign Table with Scripting While the Excel files did come into InDesign properly and appeared as formatted tables, there were very many empty rows and colums that needed to be deleted.Īnd that, of course, called for a script! I recently had a job involving importing dozens of Excel tables into InDesign in order to to create a document. ![]() It works with all the latest versions of InDesign right down to CS6, on Macintosh and Windows computers.īut if you would like the challenge of writing a script like this yourself, read on to glean some useful tips and tricks that should speed things up! Fixing up Dozens of Tables after Excel Import The latest version of the script (updated May 2018) has been updated to work seamlessly with data-merged documents as well as Excel imports. You’ve come to the right place! If you’ve just done a data merge in InDesign, or imported a large Excel table, and there are many empty rows and/or columns in your document tables that need to be deleted, scroll to the bottom of this page to download a script to fix the document in one click! Are you looking for a script that will delete all empty rows and columns from the tables in your InDesign document?
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |