Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Table: convert first row to header rows

Participant ,
Mar 19, 2013 Mar 19, 2013

Copy link to clipboard

Copied

Hi all and sorry for this question.

I find this script that auto convert to header the first row of a table (we know that using table style - if i set a cell style for header - InDesign do not recognizes the header row that i also set in excel).

So i find a script that do it - but have 2 problem: error: 45 (Error string: Object is invalid) Line 4 and works for all table of the document (the best could be if work only with the table selected or of the page). Do you have an idea to solve this?

var myTables = app.activeDocument.stories.everyItem().tables;

for (var i = 0; i < myTables.length; i++) {

    myTables.rows.firstItem().rowType = RowTypes.HEADER_ROW;

}

(Another problem: what is the best way to set a border table use cell style? I want stroke 1!

The solution to do a stroke to the text frame fitted is a bad way, i think. Can i have a confirm? Yes, i use a table style and cell style - but i see that table style do not override cell style. See also here: http://forums.adobe.com/message/5153224#5153224

Many thanks

TOPICS
Scripting

Views

7.1K
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Mar 19, 2013 Mar 19, 2013

Copy link to clipboard

Copied

You might find some useful points in this post

http://forums.adobe.com/message/4792539#4792539

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 20, 2013 Mar 20, 2013

Copy link to clipboard

Copied

Many thanks Trevor - but it is not so easy...

Anyway what do you think about point 2 here: http://forums.adobe.com/message/5153224#5153224#5153224

Really many thanks.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Mar 20, 2013 Mar 20, 2013

Copy link to clipboard

Copied

Try this

#target indesign;

var myRows = app.activeDocument.stories.everyItem().tables.everyItem().rows[0].getElements(),

      myCells = app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem(),

      l = myRows.length;

while (l--) if (myRows.rowType == RowTypes.BODY_ROW) myRows.rowType = RowTypes.HEADER_ROW; // need to check that the top row is not a header so as not to throw a can't set error

myCells.leftEdgeStrokeWeight="1pt";

myCells.rightEdgeStrokeWeight="1pt";

myCells.topEdgeStrokeWeight="1pt";

myCells.bottomEdgeStrokeWeight="1pt";

Trevor

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Mar 20, 2013 Mar 20, 2013

Copy link to clipboard

Copied

To apply to selected page only change lines 2 and 3 to

var myRows = app.activeWindow.activePage.textFrames.everyItem().tables.everyItem().rows[0].getElements(),

      myCells = app.activeWindow.activePage.textFrames.everyItem().tables.everyItem().cells.everyItem(),

The best way to set the strokes for the cell would be to give them a cell style, so given that you have set your cell style "Cell Style 1" up you can use this.

app.activeWindow.activePage.textFrames.everyItem().tables.everyItem().cells.everyItem().appliedCellStyle ="Cell Style 1" // for cell on the page

app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().appliedCellStyle ="Cell Style 1" // for every cell in the document

So you can put the code together as

#target indesign;
var myRows = app.activeWindow.activePage.textFrames.everyItem().tables.everyItem().rows[0].getElements(),
      myCells = app.activeWindow.activePage.textFrames.everyItem().tables.everyItem().cells.everyItem(),
      l = myRows.length;
while (l--) if (myRows.rowType == RowTypes.BODY_ROW) myRows.rowType = RowTypes.HEADER_ROW; // need to check that the top row is not a header so as not to throw a can't set error
myCells.appliedCellStyle ="Cell Style 1"

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 21, 2013 Mar 21, 2013

Copy link to clipboard

Copied

Hi Trevor and really many many thanks.

I have to do some text because i have some problems to run your example.

Anyway i use cell and table style.

The problem is that if you use cell style you can not have a table border (because cell style override table border)!

So the question: what is the way to have a table border?

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 21, 2013 Mar 21, 2013

Copy link to clipboard

Copied

@Folobo – in that case you need a couple of cell styles for each and every occassion 😉


First row:

Left upper corner, middle in row, right upper corner


All rows except first and last row:

Left, middle, right

Last row:
Left bottom corner, middle in row, right bottom corner

If your first row is formatted differently than row two, you'll need another set of cell styles…

Uwe

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Mar 21, 2013 Mar 21, 2013

Copy link to clipboard

Copied

Hi all,

Well I have been realy lacking sleep, as can be seen by the times of some of my posts.

No need to set up loads of cell styles.

Just set up the one cell style and one table style that uses that cell style. Set the table border with the table style.

Then try this.

#target indesign;

var myTables = app.activeWindow.activePage.textFrames.everyItem().tables.everyItem(),

      myRows = myTables.rows[0].getElements(),     

      l = myRows.length;

while (l--) if (myRows.rowType == RowTypes.BODY_ROW) myRows.rowType = RowTypes.HEADER_ROW; // need to check that the top row is not a header so as not to throw a can't set error

myTables.cells.everyItem().appliedCellStyle ="Cell Style 1" // to make sure that even cell with manual cellstyles applied to them are Zapped

myTables.appliedTableStyle = "Table Style 1";

myTables.clearTableStyleOverrides ();

myTables.cells.everyItem().clearCellStyleOverrides(true); // true clears undefinded overides / false clears just defined overrided, take your pick, if in doubt, guess

Works for me.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 21, 2013 Mar 21, 2013

Copy link to clipboard

Copied

I'm still in doubt if clearing the table style overrides will work in every occasion…
But, of course, I will give it a try. Provided I'll find time to create a complicated enough test scenario.

OT: lack of sleep? Yes. Let's starting fresh with that 🙂

Uwe

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Nov 09, 2017 Nov 09, 2017

Copy link to clipboard

Copied

LATEST

I got a small question with applying cell styles. Ive got a script where i can change 2 tables per page which adjusts the width of each row according to a cell style. Ive added 2 lists 1 has the cell style and one is for the 2 width of the columns.

My problem now is that when i had setup the tables i used cell styles for the body, left and right column using table styles. My script doesnt seem to see these styles. It seems the script only check if they are manually applied.

cellStyleName = ["Product - Row 1", "Product - Row 2", "Specs - Row 1", "Specs - Row 2"]

cellWidth = ["108", "105", "35", "54"]

cellColor = ["Red", "Red", "Red", "Red"]

for (b = 0; b < cellStyleName.length; b++)

    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 + '"');

function sizeRows() {

    cellarray = app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().getElements();

    for (a = 0; a < cellarray.length; a++)

     if (cellarray.appliedCellStyle.name == cellStyleName)

        cellarray.width = cellWidth;

     else if (cellarray.appliedCellStyle.name == "[None]")

        cellarray.appliedCellStyle = cellStyleName;

}

Ive tried  adding a if statement in the sizeRows function which checks if appliedCellStyle.name == 'None'. But i keep getting errors

I need to get the even and uneven numbers for cells i guess in order to apply the correct cell style.

Essentually easch column has a cell style. Ive gotten script from the web and have tried looking into other script. Dont understand or can find the method to get column row instead rows. Most script seem to run and use row. It would be easier if i can apply the style to a complete column at once.

Below is my setup. the table are made using linked Excel files for easier updating

Screen Shot 2017-11-08 at 22.00.17.png

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 22, 2013 Mar 22, 2013

Copy link to clipboard

Copied

@Laubender Hi and really thanks! My problem is that i have to place all cell style in a table style (i import data with excel).

I understand your way but i have to set it with local formatting (out of cell style).

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Mar 23, 2013 Mar 23, 2013

Copy link to clipboard

Copied

Folobo

What didn't work with the code in 7 above?

did you make the  change

clearCellStyleOverrides (false)

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 02, 2015 Dec 02, 2015

Copy link to clipboard

Copied

Try This,

Worked For me.

var myDoc = app.activeDocument;

      for(var T=0; T < myDoc.textFrames.length; T++){

         for(var i=0; i < myDoc.textFrames.tables.length; i++){

myDoc.textFrames.tables.rows[0].rowType = RowTypes.HEADER_ROW;

}

}

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines