Copy link to clipboard
Copied
Hi eveybody
i want copy text and group_item to empty cell but my script only copy text
var myCell = app.activeDocument.textFrames [0] .tables [0] .cells;
var cell_one = myCell [0] .contents;
mycell [1].contents=cell_one;
i can get group_item with code but i dont know how to copy to cell
var item_group_cell_one = myCell [0] .groups [0];
Who can help me, i very hope
Addressing the valid issues raised by Laubender, i have modified the code. Now the code will test if the destination cell type is graphic, if it is then it will convert the cell to text type. If anything else needs to be done in this case the statement under if can be modified accordingly.
...var tb = app.selection[0] //Select the table before running the code
var source = tb.cells[0]
var dest = tb.cells[1]
if(dest.cellType == CellTypeEnum.GRAPHIC_TYPE_CELL)
dest.cellType = CellTypeEnum.TEXT
Copy link to clipboard
Copied
You can try the following code
var tb = app.selection[0] //Select the table before running the code
var source = tb.cells[0]
var dest = tb.cells[1]
app.select(source.texts.everyItem())
app.copy()
app.select(dest.insertionPoints[0])
app.paste()
Make a selection of the table before running the code, this will copy over the contents of the first cell to the second cell.
-Manan
Copy link to clipboard
Copied
Hi Manan,
one could use method duplicate() for texts[0] of a cell to avoid copy(), select() and paste().
Before, you could remove all contents of the target cell with cell.contents = "" . Assign an empty string.
Regards,
Uwe
Copy link to clipboard
Copied
Perfect Uwe, nice and short.
I had never used duplicate, copy paste seemed like natural choices for the issue at hand so used it without further investigation or thought. Thanks for the heads up on the new api
Copy link to clipboard
Copied
Hi Manan,
FWIW: Don't know what version of InDesign our OP is using.
It could be that there are also graphic cells in the table where no insertion point can be addressed.
Regards,
Uwe
Copy link to clipboard
Copied
Addressing the valid issues raised by Laubender, i have modified the code. Now the code will test if the destination cell type is graphic, if it is then it will convert the cell to text type. If anything else needs to be done in this case the statement under if can be modified accordingly.
var tb = app.selection[0] //Select the table before running the code
var source = tb.cells[0]
var dest = tb.cells[1]
if(dest.cellType == CellTypeEnum.GRAPHIC_TYPE_CELL)
dest.cellType = CellTypeEnum.TEXT_TYPE_CELL
source.texts[0].duplicate(LocationOptions.AT_END, dest) //This will copy the content to the end of the destination cell
-Manan
Copy link to clipboard
Copied
Bonjour Manam et Laubender,
Est-il possible ce copié deux cellule en même temps?
Merci
Philippe
Copy link to clipboard
Copied
What goes wrong with your script when copying one cell at a time?
Copy link to clipboard
Copied
Hi Philippe,
of course you can also copy/paste two cells at one time.
But for that you have to select the cells and use copy, select the target cell(s) and use paste.
Example:
Have two text frames with one table each on page 1 of your document.
Every table has at least two cells. The two text frames are not threaded, they belong to different stories.
Run the following snippet to copy the first two cells of the first frame to the table of the second frame:
var sourceTable =
app.documents[0].pages[0].textFrames[0].parentStory.tables[0];
var targetTable =
app.documents[0].pages[0].textFrames[1].parentStory.tables[0];
app.select( sourceTable.cells.itemByRange(0,1) );
app.copy();
app.select( targetTable.cells[0] );
app.paste();
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Important note: With my code cell properties like strokes and fill will also be transferred.
Properties like height and width will not travel along.
The OP does not like to do that. He wants to copy the formatted contents of cells.
Regards,
Uwe Laubender
( ACP )