Pregunta

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?

¿Fue útil?

Solución

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();
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top