Define table row heights, column widths in styles somehow?
Learn / Forums / General InDesign Topics / Define table row heights, column widths in styles somehow?
- This topic has 37 replies, 14 voices, and was last updated 4 years, 4 months ago by Len Zigante.
-
AuthorPosts
-
-
May 21, 2010 at 3:30 am #55792RolandMember
The catalog I'm working on now is turning out to be a huge PITA thanks to my client changing his mind several times in a row. I've now come to the point where I have some 40 pages with several tables on each that have had a word in the header row changed, and of course now nothing fits anymore.
Am I going to have to go through all pages, selecting the tables one at a time to change the header row's height, or is there a <insert lisp> super secret table cell style setting </end lisp> I'm not seeing that will let me do this in one go?
-
May 21, 2010 at 5:43 am #55794Theunis De JongMember
It would seem you set your row heights to be of a fixed height. In hindsight, you would have been better off if you used the “Automatic” setting, together with the right cell insets on top and bottom, to get the height you wanted. Ahhh … the benefits of hindsight :-)
A simple javascript can set all header row heights to the same value.
The downside is, well, it would set all header row heights to the same value. If you have a few tables where this should not happen, you'd have to run the script and then restore these tables. If you have a mixed set, where some need changing and others do not, a script cannot help at all …
That header: is that just one row? Is it just the top row for each table, or did you actually converted them to Header Rows?
-
May 21, 2010 at 5:53 am #55796David BlatnerKeymaster
Yeah, it's frustrating that you cannot set “geometry” (including how tall or wide a row or column should be) in styles.
I have the same frustration with object styles… you cannot set object size there, either.
-
May 21, 2010 at 7:46 am #55802RolandMember
Unfortunately I set them to be header rows and indeed a fixed size. Going through them one by one to set them to “at least” works but it so darned time consuming I might be better off just making one new table with the correct settings, copying & pasting it plenty of times and then copying & pasting the contents back in.
It's a 3-day weekend over here, so I'll get to it on Tuesday.
I used the Bug/Feature Report form on Adobe's site to request a width/height option in the styles dialog boxes, but if I'm the only one who asks for these sorts of things, I doubt it'll ever be added, no matter how useful it may be or how many people want it (the form is so well hidden I had to Google for it).
-
May 21, 2010 at 8:00 am #55803Theunis De JongMember
Okay — perhaps this javascript is all you need. It will change the first row of each table in your entire document to the height you specify (in regular shorthand notation, e.g., “0.125in” or “1.2cm”). Fortunately — or not –, it doesn't matter whether it's a “header” row or a regular one.
Pay attention now, because last time I inserted a script of this length it was completely overlooked. (…)
Ready?
app.activeDocument.stories.everyItem().tables.everyItem().rows[0].height = “12mm”; // <- Change me!
Okay — that was it. Don't let its length fool you; a lot of thought went into it :-)
Copy, paste into a plain text editor (Notepad, Textedit — in plain text mode — or Adobe's own ESTK Editor), and save as “ChangeFirstRowsTo20mm.jsx” into your User Scripts folder. You don't have to do anything but double-click the script and sit back.
(Given the speed it works at, you might not even have time to sit back.)
-
May 21, 2010 at 10:43 am #55805erickpMember
Did I mention no feature enhancements for Tables in InDesign CS5? Must be the bastard son of features within ID, since they didn't seem to touch it at all. I suppose it must be perfect as is. ;-)
-
May 25, 2010 at 5:09 am #55829RolandMember
Another perfect script, Jongware. 10mm did the job :)
erickp, either that or nobody uses tables :)
Maybe I ought to add some animations to this catalog's file if the tables end up being too much of a hassle after all. I bet my client would love animation in his printed catalogs…. -
May 25, 2010 at 5:29 am #55830Eugene TysonMember
I would really prefer if there was a fit columns function, or the ability to double click to resize cells to fit.
Tables are a bit clunky in InDesign.
-
May 27, 2010 at 10:15 pm #55845Nadya MiloserdovaMember
A big WOW!
-
May 30, 2010 at 11:56 pm #55861RolandMember
Of course clients keep changing their minds, so I've had to adjust the script so it can change the width of a column in all tables. Turns out it takes only two words to be changed, along with the values of course:
app.activeDocument.stories.everyItem().tables.everyItem().rows[0].height = “12mm“;
app.activeDocument.stories.everyItem().tables.everyItem().columns[4].width = “6mm“;It doesn't change the fact better planning probably wouldn't have made the scripts necessary at all, but it looks like most of the data has changed (gotta love “final versions” changing several times) so I'll have to start copying data from scratch anyway.
-
June 4, 2010 at 12:09 am #55917seb400Member
This little script will prove invaluable for me!
I have amended above suggestions to give me the column widths for a particular table.
However I would like to be able to define a 'row depth' for all the remaining rows of a table below the two specified rows.
app.activeDocument.stories.everyItem().tables.everyItem().rows[0].height = “15mm”;
app.activeDocument.stories.everyItem().tables.everyItem().rows[1].height = “8mm”;app.activeDocument.stories.everyItem().tables.everyItem().columns[0].width = “8mm”;
app.activeDocument.stories.everyItem().tables.everyItem().columns[1].width = “36mm”;
app.activeDocument.stories.everyItem().tables.everyItem().columns[2].width = “37mm”;
app.activeDocument.stories.everyItem().tables.everyItem().columns[3].width = “7.5mm”;
app.activeDocument.stories.everyItem().tables.everyItem().columns[4].width = “7.5mm”;
app.activeDocument.stories.everyItem().tables.everyItem().columns[5].width = “7.5mm”;
app.activeDocument.stories.everyItem().tables.everyItem().columns[6].width = “7.5mm”;
app.activeDocument.stories.everyItem().tables.everyItem().columns[7].width = “7.5mm”;
app.activeDocument.stories.everyItem().tables.everyItem().columns[8].width = “7.5mm”;MTIA Steve
-
June 4, 2010 at 2:21 am #55918Theunis De JongMember
Hi Steve, and welcome to the wonderful world of scripting!
If you want to change “rows 2 to x“, normally you would have to 'manually' loop over these rows, and to do that, you'd have to manually loop over all tables, and to do that, well, you'd have to manually loop over all stories … Using the fast everyItem() function avoids all this work, but — it can only work on every item, not something like 'from row 2 to the end' (hence the name :-D ).
So you have no choice, other than using the much slower loops? Sure you have! You can set all rows of all tables to your 'remaining' height value, and then change only the 1st and 2nd rows' height.
Add this line before your first one, and you should be done:
app.activeDocument.stories.everyItem().tables.everyItem().rows.everyItem().height = “20mm”;
(replacing the 20 mm with the height you need).
-
June 4, 2010 at 2:37 am #55919seb400Member
Thanks Jongware!
As much as I'm struggling with (basic) scripting, I must admit to enjoying that sort of simple logic that just doesn't feature in my 'designer' mindset
Steve
-
August 28, 2010 at 5:53 am #56854avantiParticipant
Hi everybody,
First, thanks for your very interesting and comprehensive contributions.
I found and used the Jongware script above (app.activeDocument.stories.everyItem().tables.everyItem().rows[0].height = “12mm“;) to do what InDesign, even CS5 version, doesn't provide : cells dimensions in styles.
But i'd like to go a little further and change only particular styled cells height, not all first, second… rows.
I tried to insert appliedStyle in the script like that :
(app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().appliedStyle = “myCellStyle”.height = “12mm“;)Obviously, i'm so new to script, it doesn't work and i don't really understand what i do.
Please, can you guide me ?
Thanks in advance.
Sorry for my poor english. -
August 28, 2010 at 10:23 am #56855Theunis De JongMember
Javascript is missing a construct that is available in Applescript: the whose command. whose selects from an array only the elements that have a certain value. Since you don't want to apply your change to every cell, which is what everyItem selects, you'll have to get 'everything', then loop over the result, applying your height only to cells with the right name.
This seems to work (since it's no longer a single command, Undo undoes it one at a time):
cellarray = app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().getElements();
for (a=0; a<cellarray.length; a++)
if (cellarray[a].appliedCellStyle.name == “myCellStyle”) // <- Cell Style Name!
cellarray[a].height = “12mm”; -
August 28, 2010 at 11:30 am #56856avantiParticipant
Thanks a lot for your clear and quick answer Jongware, it perfectly works !
Do you think the same type of script could be “undone” in 1 time with Applescript (rather than 1 “Undo” per modification with Javascript) ?
-
August 28, 2010 at 11:47 am #56857Theunis De JongMember
That's strange — I can't get it not to work (locked story, locked layer, header rows …). There must be Something Unexpected™ in your tables.
Can you try this? It counts the number of changes made.
cellarray = app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().getElements();
changed = 0;
for (a=0; a<cellarray.length; a++)
if (cellarray[a].appliedCellStyle.name == “myCellStyle”) <- Cell Style Name
cellarray[a].height = “12mm”, changed++;
alert (changed+” change(s) made”); -
August 28, 2010 at 11:55 am #56858avantiParticipant
Sorry Jongware, it's my (huge) mistake : I took a paragraph style for a cell style (“Booooooo, looser !!!!!”).
Your script perfectly works (i just edited my post).
Sorry and thanks again.
-
August 28, 2010 at 12:03 pm #56859Theunis De JongMember
(Achh! Reply was to previous replay ;))
Yes, I suspect writing it as one single AS command allows you to Undo it at once. However, Me ≠ AppleScript.
There is also a way to encapsulate an entire Javascript into one “undo” command — hold on while I look up how that was done.
(.. insert elevator muzak here ..)
There we go:
cellStyleName = “myCellStyle”;
newHeight = “12mm”;app.doScript (sizeRows, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.FAST_ENTIRE_SCRIPT, 'Undo Resize Height of “'+cellStyleName+'”');
function sizeRows ()
{
cellarray = app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().getElements();
for (a=0; a<cellarray.length; a++)
if (cellarray[a].appliedCellStyle.name == cellStyleName)
cellarray[a].height = newHeight;
} -
August 28, 2010 at 12:14 pm #56860Theunis De JongMember
This is super-fancy if you need several variants. Save this script as “Resize_Cell Style Name_New Size.jsx”, and it'll pick up the variables from the script name :) (For instance, “Resize_Yellow Cells_10mm.jsx”.)
if (app.activeScript.name.match(/_/g).length == 2)
{
cellStyleName = app.activeScript.name.split('_')[1];
newHeight = app.activeScript.name.split('_')[2].split('.')[0];
if (app.activeDocument.cellStyles.item(cellStyleName).isValid)
app.doScript (sizeRows, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.FAST_ENTIRE_SCRIPT, “Undo Resize Height of “+cellStyleName);
else
alert ('There is no Cell Style named “'+cellStyleName+'”');
} else
alert ('The name “'+app.activeScript.name+'” should be in the format “Resize_CellStyleName_Height.jsx”!');
function sizeRows ()
{
cellarray = app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().getElements();
for (a=0; a<cellarray.length; a++)
if (cellarray[a].appliedCellStyle.name == cellStyleName)
cellarray[a].height = newHeight;
}-
July 25, 2017 at 3:50 pm #96361Rombout VersluijsMember
Its a bit of an old thread but i find it very usefull. I seem some simularities with AS scripting and python or php code.
I kept getting error, probably a format coding error, when the style has a space like his example Resize_Yellow Style_10mm.jsx it will give a error cause the space gets a ASCII code %20 for a space. I change line 2 which looks for %20 and replaces this with a space. The new working code for me on OSX looks like this then.if (app.activeScript.name.match(/_/g).length == 2) {
cellStyleName = app.activeScript.name.split(‘_’)[1].replace(‘%20’, ” “);
//newHeight = app.activeScript.name.split(‘_’)[2].split(‘.’)[0];
newHeight = app.activeScript.name.split(‘_’)[2].split(‘.jsx’)[0];
if (app.activeDocument.cellStyles.item(cellStyleName).isValid)
app.doScript (sizeRows, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.FAST_ENTIRE_SCRIPT, “Undo Resize Height of “+cellStyleName);
else
alert (‘There is no Cell Style named “‘+cellStyleName+'”‘);
} else
alert (‘The name “‘+app.activeScript.name+'” should be in the format “Resize_CellStyleName_Height.jsx”!’);function sizeRows (){
cellarray = app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().getElements();
for (a=0; a<cellarray.length; a++)
if (cellarray[a].appliedCellStyle.name == cellStyleName)
cellarray[a].height = newHeight;
}
-
-
August 28, 2010 at 12:17 pm #56861avantiParticipant
You're killing me after all those hours of research !
It's just… OK and seems much faster than the first script.Thanks for all and the elevator muzak while waiting about… 30 seconds (reminded me the “Blues brothers”, at the end of the movie, except it was longer for them !).
No thanks to Adobe that doesn't seem to care about height / width of styled cells.
Have a nice week-end !
-
August 28, 2010 at 12:20 pm #56862Theunis De JongMember
A small addendum: the Name_Script stuff does not play nice with decimal points in your value. Change line #4 to this to solve it:
newHeight = app.activeScript.name.split('_')[2].split('.jsx')[0];
-
August 28, 2010 at 3:18 pm #56863avantiParticipant
Super fancy… it's too much !
Why not a script with user interface to choose cell styles in a drop down menu… (i'll think about it after all, we could make money ;-).It seems there's a little problem with the condition (line 5) :
if (app.activeDocument.cellStyles.item(cellStyleName).isValid)Message from INDD :
There is no Cell Style named “myCellStyle”It's OK when // (commentary mark in english ?) the “if” and “else” (lines 7 and 8).
When it'll be done, i'll post the multiple scripts you've made in an archive for other people and send it on Adobe forums too where i asked for help.
-
August 28, 2010 at 3:57 pm #56864Theunis De JongMember
.. but but but .. I added the message there to warn there is no Cell Style named “myCellStyle” in your document!
You are supposed to use the correct cell style name in the script name. If you name the script “Resize_SomeTotallyRandomNameHere_5mm.jsx”, it'll try to use “SomeTotallyRandomNameHere” for a Cell Style name — and if you don't have that style, it'll warn you and don't do anything at all.
-
August 29, 2010 at 1:10 am #56865avantiParticipant
I understood this Jongware but i have a style call “myCellStyle” in the document for using with previous versions of the script ;-)
-
August 29, 2010 at 6:28 am #56867David BlatnerKeymaster
This is great information, but it would be terrific if you continued it in the Scripting section of the forums. (I think most users don't really want to look at all that code!) :)
-
August 29, 2010 at 2:37 pm #56869avantiParticipant
Sure David but Jongware JS code is a valuable answer to the missing Adobe's function in cells style.
What about moving this topic to the Scripting section so we could continue the discussion with the first part?
Could do this as an administrator, please?To Jongware
I tried the fancy script with another document cell style (“ChangeStyledCellsHeight-v1.3_Heure_12mm.jsx”) and the alert shows again : There is no Cell Style named “Heure”
I tried to simplify the script name (“script_Heure_12mm.jsx”) with no more success.
I think the condition “if (app.activeDocument.cellStyles.item(cellStyleName).isValid)” is not true.
So why the cell style name is detected as not valid?Could it be a problem with french version of CS5 or CS5 itself or… (so many questions)?
-
October 10, 2012 at 5:28 am #63324AlMember
Hi,
I need your help with this script you been working around. I can find it very useful and I tried to apply and works good but there is a tiny problem that I don't knowhow to fix yet as I am just strating to dive a bit into this fascinating world of scripting.
If I apply this script
app.activeDocument.stories.everyItem().tables.everyItem().columns[0].width = “8mm”;
app.activeDocument.stories.everyItem().tables.everyItem().columns[1].width = “36mm”;It clearly picks up every item (every table) from my story. But what if I want just to select tables made of two colums or just selected ones instead to apply the script?
How can I tell those conditions?
Thank you very much
Al
-
May 16, 2016 at 3:05 am #84924Ross ScaliseMember
Hi, just found this and it’s something I need but when trying to use the script I keep getting a JavaScript Error and lists elements from your code.
I pasted the below in text edit and saved it in the folder revealed through the scripts palette.
It doesn’t like the quote marks, mm or the 5.
I need my row heights to be at least 5mm
app.activeDocument.stories.everyItem().tables.everyItem().rows[0].height = “5mm“;
-
May 16, 2016 at 3:35 am #84927Ari SingerMember
That’s because the quotes are ‘smart quotes’, and what it needs are ‘straight quotes’. Just go into the JS file, delete the quotes and type in new quotes. The new quotes should come out straight, and should work.
-
-
May 16, 2016 at 3:51 am #84929Ross ScaliseMember
Thanks for this.
Tried it but text edit kept changing them to smart quotes so had to change them in adobe ExtendScript Toolkit.
All good now thanks so much for your help!
-
May 16, 2016 at 3:55 am #84931Ari SingerMember
My pleasure! I find it’s best to use the ESTK when writing JS for Adobe apps.
-
-
December 6, 2016 at 6:44 pm #90349Sar ActivatedMember
Thanks to the OP/Theunis and Roland for their posts here.
I have a 100 page document that I imported from Word. On each page is a table. Unfortunately all 100 of these tables stick out over the margin and off the page. Thanks to the javascript form Theunis, I managed to fix this issue! So FYI for beginners who don’t know how to use Scripts in InDesign:
1. In Dreamweaver, create a new Javascript file.
2. Paste the code*:app.activeDocument.stories.everyItem().tables.everyItem().columns[0].width = ‘17.956mm’;
3. Save this Javascript file and name it whatever you want, but you must save it in the ‘Program Files’ > ‘Adobe’ > ‘Adobe InDesign C 2015’ > ‘Script’s > ‘Scripts Panel’**
4. Now go to InDesign and open your document with your tables in it
5. Open up the ‘Scripts’ panel. If you don’t have it, it’s under ‘Window’ > ‘Utilities’ > ‘Scripts’.
6. Now all you have to do is double click on the Javascript file you saved in point 3!* Let me explain the code a bit. For each column table, repeat this exact line, but change the number. So for example, I have a whole lot of 6 columned tables. So my Javascript file looks like:
app.activeDocument.stories.everyItem().tables.everyItem().columns[0].width = ‘17.956mm’;
app.activeDocument.stories.everyItem().tables.everyItem().columns[1].width = ‘17.956mm’;
app.activeDocument.stories.everyItem().tables.everyItem().columns[2].width = ‘17.956mm’;
app.activeDocument.stories.everyItem().tables.everyItem().columns[3].width = ‘17.956mm’;
app.activeDocument.stories.everyItem().tables.everyItem().columns[4].width = ‘17.956mm’;
app.activeDocument.stories.everyItem().tables.everyItem().columns[5].width = ‘17.956mm’;** I’m on a PC with CC 2015 – so apologies for not providing an example for Macs if it’s different. I’m not on my Mac at the mo.
-
November 14, 2019 at 12:41 pm #14323706Len ZiganteParticipant
This article is almost exactly what I’ve been looking for. The only thing I need now is some way to only apply the cell size changes to tables that are of table style “Geometry”. Would someone here please explain how I should do this?
-
November 15, 2019 at 5:01 am #14323699Theunis De JongMember
Despite David’s plea, this thread only gets longer :( (Sorry David! Perhaps it is possible to physically move this thread?)
Len, you don’t mention which one of the dozen-or-so scripts you want to adjust so this thread is *probably* only going to get longer, what with all the expected clarifications of “no, I did not mean that script– oh wait, it could also work but it need to take the current user into account…”
So here is a valiant attempt at a solution that can be tacked on to a lot of the above scripts. (Minus the original one-liner. I see that script is only going to grow longer and longer.)
* At the top of your script, add the name of the table style to change:
tableStyleName = 'Geometry';
* Change the existing (?) function
sizeRows
to this 8 lines longer version:function sizeRows () { tablearray = app.activeDocument.stories.everyItem().tables.everyItem().getElements(); for (t=0; t<tablearray.length; t++) { if (tablearray[t].appliedTableStyle.name == tableStyleName) { cellarray = tablearray[t].cells.everyItem().getElements(); for (a=0; a<cellarray.length; a++) if (cellarray[a].appliedCellStyle.name == cellStyleName) cellarray[a].height = newHeight; } } }
Building further upon the magically working Changing The Script Name version(s) is possible but then this *definitely* should be moved into the Scripts subforum.
-
November 15, 2019 at 5:47 am #14323698David BlatnerKeymaster
LOL. No problem Theunis. :-)
-
November 15, 2019 at 11:38 am #14323695Len ZiganteParticipant
My apologies for adding to this thread.
Thank you Theunis; what you provided more than covers what I am looking for – I’ll likely utilize your cell identification method in some future script. With a bit of tweaking I made your code do what I need. Here is the script incase anyone needs something similar without bothering to identify each cell in the table to be formatted :
tableStyleName = ‘Geometry’; // name of the table(s) to be formatted (only)
tablearray = app.activeDocument.stories.everyItem().tables.everyItem().getElements();for (t=0; t<tablearray.length; t++)
{
if (tablearray[t].appliedTableStyle.name == tableStyleName)
{
tablearray[t].rows.everyItem().height = “11.428pt”;
tablearray[t].rows[0].height = “16.994pt”;
tablearray[t].rows[1].height = “17.176pt”;
}
}
-
-
AuthorPosts
- You must be logged in to reply to this topic.