Skip to main content
Known Participant
October 11, 2024
Answered

セルの結合について

  • October 11, 2024
  • 2 replies
  • 1096 views

既存の表にタイプ列を追加することになりました。
ただ、タイプ列の情報は、No.2~4のみ必要となります(添付参照ください)
その他の行は「Data」「Type」をセルの結合をしなければなりません。行が1300行あるため一括でそれぞれの行の結合ができないか考えていますが良い方法を思いつきません
どなたか、良い方法がございましたら教えていただきたくよろしくお願いします

    This topic has been closed for replies.
    Correct answer frameexpert

    Copy the code below and paste it in a plain text file. Save it with a .jsx extension. Click in the table and choose File > Script > Run and select the script. It should do what you want. Please let me know if you have any questions or comments.

     

    main ();
    
    function main () {
    
        var doc;
        
        doc = app.ActiveDoc;
        if (doc.ObjectValid () === 1) {
            processDoc (doc);
        }
    }
    
    function processDoc (doc) {
    
        var tbl;
        
        // Make sure the cursor is in a table.
        tbl = doc.SelectedTbl;
        if (tbl.ObjectValid () === 1) {
            if (app.Displaying === 1) {
                app.Displaying = 0;
            }
            
            processTbl (tbl, doc);
            
            if (app.Displaying === 0) {
                app.Displaying = 1;
                doc.Rehyphenate ();
                doc.Redisplay ();
            }
        }
    }
    
    function processTbl (tbl, doc) {
    
        var row, cell;
        
        // Go to the first body row.
        row = tbl.FirstRowInTbl.NextRowInTbl;
        // Go to the second cell.
        cell = row.FirstCellInRow.NextCellInRow;
        // Loop through the cells in the second column.
        while (cell.ObjectValid () === 1) {
            if ((cell.CellIsStraddled === 0) && (cell.CellNumColsStraddled === 1)) {
                if (cellToRightIsEmpty (cell) === true) {
                    cell.StraddleCells (1, 2); // rows, columns
                }                
            }
            cell = cell.CellBelowInCol;
        }   
    }
    
    function cellToRightIsEmpty (cell) {
    
        var textList;
        
        cell = cell.NextCellInRow;
        if (cell.ObjectValid () === 1) {
            if (cell.FirstPgf.id === cell.LastPgf.id) {
                textList = cell.FirstPgf.GetText (Constants.FTI_PgfEnd);
                if (textList[0].offset === 0) {
                    return true;
                }
            }
        }
    }
    

     

    2 replies

    Community Expert
    October 11, 2024

    Hi,

    As I understand it, you want to merge all cells Data and Type, but only not in row 2, 3 and 4.

    Do you want to keep the header Data and Type?

    If there is only a single character in column Data, you could select all rows and remove the line between columns Data and Type and only keep this line for rows 2, 3 and 4.

    However, when you really want to merge the cells in so many rows, then I recommend to get an ExtendScript script from one of the developers here.

    Best regards, Winfried

    geso10Author
    Known Participant
    October 11, 2024

    こんにちは。
    返信ありがとうございます。
    データ列の文字列は、長文なためデータ、タイプのセル結合して文字列の折り返しを少なくしたいです。

    なので、表の罫線を非表示にすることはできません。
    やはり、データ、タイプのセルを選択してセルの結合を繰り返し実施するしか方法がないんですね

    添付の左側から右側のようにしたいです

    Community Expert
    October 11, 2024

    Then I guess you have to do it manually (takes two hours).

    Or you could experiment with MIF.

    When I tested this, the only difference is that you have to change this code:

    <Cell
    <CellContent

    to this code:

    <Cell
    <CellColumns 2>
    <CellContent

    But to do a search/replace, you would have to search for the correct table cells. Not feasible.

    frameexpert
    Community Expert
    Community Expert
    October 11, 2024

    I assume that the attachment shows the "before" example. Can you post a screenshot of the result you want? Thank you.