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

This Script is use to convert first row to header, the last row to footer, it delete my content.

Advocate ,
Jul 10, 2024 Jul 10, 2024

Copy link to clipboard

Copied

This Script is use to convert first row to header, the last row to footer, it delete my content.
Sorry, The original post seemed to be posted by me. But for too long, I didn't find it.
The initial purpose: 

It will judge the last row of the table.

If it is empty, it is directly converted to the footer;if it is not empyt(have content), add 1 row Below the last row, and convert the new row to footer.

It also convert first row to header, apply the  cellstyle.
But now it delete the last row, that it is Non -empty line. my content lost.

 

 

 

 

table = app.selection[0];
app.selection[0].appliedTableStyle = "mytab";
var myHeaderRow = table.rows[0];
var myNextRow = table.rows[-2];
var myFooterRow = table.rows[-1];

for (var i = 0; i < table.rows.length - 1; i++) {
  table.rows[i].cells.everyItem().minimumHeight = "7.6mm";
};


// Optional:
myFooterRow.cells.everyItem().contents = "";
// Not optional. 
// Set the point size in a value, so that the text could be visible despite the minimal height of the cells:
myFooterRow.cells.everyItem().texts.everyItem().pointSize = 0.1;
myFooterRow.cells.everyItem().appliedCellStyle = "footer";
myHeaderRow.cells.everyItem().appliedCellStyle = "header";
myFooterRow.cells.everyItem().topInset = 0;
myFooterRow.cells.everyItem().leftInset = 0;
myFooterRow.cells.everyItem().bottomInset = 0;
myFooterRow.cells.everyItem().rightInset = 0;

myFooterRow.cells.everyItem().height = "1.06mm";//行高
//myNextRow.cells.everyItem().minimumHeight  = "7.5mm";


if (!(table.rows[0].rowType == RowTypes.HEADER_ROW)) {
  table.rows[0].rowType = RowTypes.HEADER_ROW;
}
else {
  //alert("header existed");
};
if (!(myFooterRow.rows.item(-1).rowType == RowTypes.FOOTER_ROW)) {
  myFooterRow.rows.item(-1).rowType = RowTypes.FOOTER_ROW;
}
else {
  //alert("end of the table exists");
};

 

 

 

 

This line lost.png

TOPICS
Bug , Scripting

Views

350

Translate

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 ,
Jul 10, 2024 Jul 10, 2024

Copy link to clipboard

Copied

What kind of translating software are you using? 

 

Can you post your question in your native language? 

 

Votes

Translate

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
Advocate ,
Jul 10, 2024 Jul 10, 2024

Copy link to clipboard

Copied

It should be easy to understand now.

Votes

Translate

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 ,
Jul 10, 2024 Jul 10, 2024

Copy link to clipboard

Copied

I'd refer to @Robert at ID-Tasker  as more experienced and better at this than I am

However, I attempted to correct your script, I'm not a professional scripter/coder - I am just learning

 

Looking forward to how this works - as it seems useful to me too

 

var table = app.selection[0];
table.appliedTableStyle = "mytab";
var myHeaderRow = table.rows[0];
var myFooterRow = table.rows[-1];

// Convert first row to header and apply cell style
myHeaderRow.cells.everyItem().appliedCellStyle = "header";
if (myHeaderRow.rowType !== RowTypes.HEADER_ROW) {
    myHeaderRow.rowType = RowTypes.HEADER_ROW;
}

// Check if the last row is empty
var isLastRowEmpty = true;
for (var j = 0; j < myFooterRow.cells.length; j++) {
    if (myFooterRow.cells[j].contents !== "") {
        isLastRowEmpty = false;
        break;
    }
}

// If the last row is not empty, add a new row for the footer
if (!isLastRowEmpty) {
    table.rows.add();
    myFooterRow = table.rows[-1];
}

// Convert the last row to footer and apply cell style
myFooterRow.cells.everyItem().contents = "";
myFooterRow.cells.everyItem().texts.everyItem().pointSize = 0.1;
myFooterRow.cells.everyItem().appliedCellStyle = "footer";
myFooterRow.cells.everyItem().topInset = 0;
myFooterRow.cells.everyItem().leftInset = 0;
myFooterRow.cells.everyItem().bottomInset = 0;
myFooterRow.cells.everyItem().rightInset = 0;
myFooterRow.cells.everyItem().height = "1.06mm";

if (myFooterRow.rowType !== RowTypes.FOOTER_ROW) {
    myFooterRow.rowType = RowTypes.FOOTER_ROW;
}

// Set the minimum height for all rows except the last one
for (var i = 0; i < table.rows.length - 1; i++) {
    table.rows[i].cells.everyItem().minimumHeight = "7.6mm";
}

 

Votes

Translate

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 ,
Jul 11, 2024 Jul 11, 2024

Copy link to clipboard

Copied

The only thing I would optimise is to get rid of all those insets, etc. - this should be set in the CellStyle - that is applied anyway. 

 

Votes

Translate

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
Advocate ,
Jul 11, 2024 Jul 11, 2024

Copy link to clipboard

Copied

Success.

Thank you very much~

 

Do I have to choose the entire table? Just need the cursor in the table, okay?

Votes

Translate

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 ,
Jul 11, 2024 Jul 11, 2024

Copy link to clipboard

Copied

quote

 

Do I have to choose the entire table? Just need the cursor in the table, okay?


By @dublove

 

You need to select whole table. 

 

Votes

Translate

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
Advocate ,
Jul 11, 2024 Jul 11, 2024

Copy link to clipboard

Copied

Hi~

@Eugene Tyson 

Can you add a "Continue" row in front of the header?
At the same time, apply "Continue" cellstyle  to it, and set  5mm  accurate line height  for it.

But how do you judge that "Continue" already exists? Need two versions?

Thank you~

continiue.png

Votes

Translate

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 ,
Jul 11, 2024 Jul 11, 2024

Copy link to clipboard

Copied

You should be able to do that automatically

https://www.youtube.com/watch?v=sKpo1jM7Jvk

 

Votes

Translate

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
Advocate ,
Jul 11, 2024 Jul 11, 2024

Copy link to clipboard

Copied

I can't log in to YouTube.
I know the way to make Continue, but first of all, you have to create a new Continue Row.
I just ask how to quickly insert the  Continue Row in front of the header, and set up accurate high, apply it's cellstyle.

Votes

Translate

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 ,
Jul 11, 2024 Jul 11, 2024

Copy link to clipboard

Copied

LATEST
quote

I can't log in to YouTube.
I know the way to make Continue, but first of all, you have to create a new Continue Row.
I just ask how to quickly insert the  Continue Row in front of the header, and set up accurate high, apply it's cellstyle.


By @dublove

 

You mean you want Header to automatically "duplicate" - be visible - in all following TextFrames?

 

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Table.html

 

Two properties:

 

RobertatIDTasker_0-1720714051891.png

 

And a bit more info:

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#HeaderFooterBreakTypes.html

 

Votes

Translate

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