Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy/Clone row after the current row #226

Merged
merged 5 commits into from
Sep 20, 2024

Conversation

startewho
Copy link
Contributor

Long time no see.

it 's common that insert the row after some row. it looks easy to add this feature.

@PrzemyslawKlys
Copy link
Member

Would you be able to add some tests?

@PrzemyslawKlys
Copy link
Member

So I've changed things because what you've done was not really needed.

  • AddRow already exists and allows doing AddRow(4) which adds new row with 4 columns or AddRow(4,4) which adds 4 rows with 4 columns each)

I've changed your InsertRow into CopyRow which it actually copies/clones including the content

internal static void Example_Tables1CopyRow(string folderPath, bool openWord) {
    Console.WriteLine("[*] Creating standard document with tables");
    string filePath = System.IO.Path.Combine(folderPath, "Document with TablesInsert.docx");
    using (WordDocument document = WordDocument.Create(filePath)) {
        var paragraph = document.AddParagraph("Basic paragraph - Page 4");
        paragraph.ParagraphAlignment = JustificationValues.Center;

        document.AddParagraph();

        WordTable wordTable = document.AddTable(3, 4, WordTableStyle.PlainTable1);

        wordTable.Rows[1].Cells[0].Paragraphs[0].Text = "Cell 0";
        wordTable.Rows[1].Cells[1].Paragraphs[0].Text = "Cell 1";
        wordTable.Rows[1].Cells[2].Paragraphs[0].Text = "Cell 2";

        var secondRow = wordTable.Rows[1];

        var thirdRow = wordTable.CopyRow(secondRow);
        thirdRow.Cells[0].Paragraphs[0].Text = $"R3C1";

        Console.WriteLine(wordTable.Style);

        // let's overwrite style
        wordTable.Style = WordTableStyle.GridTable6ColorfulAccent1;

        wordTable.AddRow(2, 4);

        document.Save(openWord);
    }
}

@PrzemyslawKlys PrzemyslawKlys changed the title Insert the newrow after the current row Copy/Clone row after the current row Sep 20, 2024
@PrzemyslawKlys PrzemyslawKlys merged commit fbdd31f into EvotecIT:master Sep 20, 2024
0 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants