문제

Does anyone know a way to move a row in a table?

I have a table with dynamic number of row, that I want to manipulate by code (interop c#). For example I want to move the row with the index 5 to index 8 or the other way round (index 8 to index 5).

Anyone an idea?

도움이 되었습니까?

해결책

Let say wrd is your instance of Word, aDoc your document and you want (for the first table in your document) to move the row with index src just before the row with index dest, you couyld write something like this (adding all the necessary checks):

        Table tbl = aDoc.Tables[1];
        Row toMove = tbl.Rows[src];
        object beforeRow = tbl.Rows[dest];
        Row newRow = tbl.Rows.Add(ref beforeRow);
        toMove.Select();
        wrd.Selection.Copy();
        newRow.Select();
        wrd.Selection.Paste();
        toMove.Delete();
        newRow.Delete();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top