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

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

Guide ,
Jul 10, 2024 Jul 10, 2024

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

What kind of translating software are you using? 

 

Can you post your question in your native language? 

 

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

It should be easy to understand now.

Translate
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

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";
}

 

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

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. 

 

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

Success.

Thank you very much~

 

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

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

 

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

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

Translate
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

You should be able to do that automatically

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

 

In this InDesign how-to video, Jason Hoppe demos a clever way to have one table header for the first instance of a split table, and a different one for all subsequent locations. It takes a little bit of behind-the-scenes magic, but it gets the job done nicely! This comes from Jason's "Tabs and ...
Translate
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
Guide ,
Jul 11, 2024 Jul 11, 2024

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.

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

 

Translate
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
Guide ,
Jan 01, 2025 Jan 01, 2025

HI @Eugene Tyson 

 

// 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];
}

 

After my repeated testing, I think there is something wrong with this code of yours.
It doesn't recognize the two states when the text box is fully expanded, or contains overflow text.

In both states, it doesn't recognize if there is a empty row at the end.
It gets confused. Look at the latest test sample

https://community.adobe.com/t5/indesign-discussions/dead-loop-how-do-i-jump-out-and-why-do-i-get-two...

Translate
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
LEGEND ,
Jan 01, 2025 Jan 01, 2025

@dublove

 

Should be: 

    if (myFooterRow.cells[j].texts[0].contents !== "") { 
Translate
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
LEGEND ,
Jan 01, 2025 Jan 01, 2025

@dublove

 

Also, are you looking to set "false" footer rows - or "real" ones, like when you define their number in the Table Properties in the UI?

 

Translate
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 ,
Jan 02, 2025 Jan 02, 2025
LATEST

It works exactly as you described orginally, I tested it and it does what you asked for.

 

However, the issue here is that it’s not entirely clear what you're asking for, which makes it difficult to pinpoint the goals. This has led to some confusion, and it’s why I haven't responded sooner. There’s been quite a bit of back-and-forth, and I’m finding it challenging to fully understand what you're looking for.

 

 

Translate
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