Skip to main content
dublove
Legend
December 22, 2024
Question

Script request please: merge the rows where the cursor is and fill in Cell with the word "Continue"

  • December 22, 2024
  • 2 replies
  • 610 views

Hello, please.
What should I write in the next sentence?

 

merge the rows where the cursor is and fill in Cell with the word "Continue"

No need to select the  the row.

 

thank you~

This topic has been closed for replies.

2 replies

Robert at ID-Tasker
Legend
December 23, 2024

@dublove 

 

If you can first select cells to be merged - doesn't matter if it's a row or a few cells - this will work:

app.selection[0].merge();

 But it won't merge whole rows - if you select a few cells in the middle.

 

This, will only merge first selected row of the selection:

app.selection[0].parentRow.merge();

keeping the rest of the cells selected:

 

 

dublove
dubloveAuthor
Legend
December 23, 2024

I expressed myself wrongly.
I want to add a new row at the top of the table, and  then merge the whole row, and then apply the style and set row height.

Robert at ID-Tasker
Legend
December 23, 2024
quote

I expressed myself wrongly.
I want to add a new row at the top of the table, and  then merge the whole row, and then apply the style and set row height.


By @dublove

 

Yes, I know, I've just posted a more simplified version of the @Eugene Tyson's code - without error handling.

 

Community Expert
December 23, 2024

Here you go - if you need something more specific just let us know

 

// Ensure a document is open and a text insertion point is selected
if (app.documents.length > 0 && app.selection.length > 0 && app.selection[0].constructor.name === "InsertionPoint") {
    var cursor = app.selection[0];
    var parentCell = cursor.parent;

    // Check if the cursor is within a table cell
    if (parentCell.constructor.name === "Cell") {
        try {
            var parentRow = parentCell.parentRow;

            // Merge all cells in the parent row using the first and last cells of the row
            var firstCell = parentRow.cells[0];
            var lastCell = parentRow.cells[parentRow.cells.length - 1];
            firstCell.merge(lastCell);

            // Set the content of the merged cell to "Continue"
            firstCell.contents = "Continue";

            alert("Row merged and cell updated with 'Continue'.");
        } catch (e) {
            alert("An error occurred: " + e.message);
        }
    } else {
        alert("Please place the cursor inside a table cell.");
    }
} else {
    alert("Please open a document and place the cursor inside a table cell.");
}

 

dublove
dubloveAuthor
Legend
December 23, 2024

Hi Eugene Tyson

How does this script add a row at the top of the table and then merge this empty row?

I have this, but I can't pick it up.

The cursor should be able to be anywhere in the table. Adding a blank row jumps to the first blank row.

 

 

//first table in the active document
var table=app.activeDocument.textFrames[0].parentStory.tables[0]
dupeTopRow(table);
table.rows.add(LocationOptions.BEFORE, table.rows[0]);

/**
* duplicate the first row af a table 
* @ param the table 
* @ return void 
*/
function dupeTopRow(t){
    var nr = t.rows.add(LocationOptions.BEFORE, t.rows[0]);
    var c = nr.cells
    var lr = t.rows[1].cells
    for (var i = 0; i < c.length; i++){
        c[i].properties = lr[i].properties;
    };   
}

 

 

 

dublove
dubloveAuthor
Legend
December 23, 2024

I'm not sure what you're asking here. 

The way to get a continious header in the table is how I've shown it.

 

Doing what you need to do is a bit open ended because I don't fully understand what it is you're trying to do.

 

However, I'm not at the computer right now, and I'm not the best scripter so I might not even be able to do what you want.

I can take a look tomorrow or if you have a specific file that I work with that you can share and explain in detail what you need to happen.

 

 


Just want to start showing "continue" at the top of the second  frame.

 

Step 1. Select the row that may become the table header (there may be 1 or 2 rows).
2. Add an empty row at the top of the table and merge all cells of this  row.
3. Add “Continue” character into this row.
4. Set this row height  to 5mm, and apply "Continue" cell style.

5. Change the  "step 1 selected rows and Just added row"  to the table header.

6 . skip the first page of the table header

 

Please check the attachment sample

Thanks a lot