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

Word table cell paragraph add image fix #176

Merged

Conversation

tmheath
Copy link
Contributor

@tmheath tmheath commented Dec 13, 2023

This pull request contains an untested fix for enabling a paragraph created by WordTableCell to add an image automatically by adding the argument for the document reference to the called constructed for WordParagraph to pass the WordTableCell's _document attribute.

  • Adds example for Images in Table
  • Adds additional testing for adding paragraph in table and attaching image to it

closes #174

@PrzemyslawKlys
Copy link
Member

PrzemyslawKlys commented Dec 31, 2023

I've modified your PR a bit. It seems to work fine. Keep in mind it's not necessary to add paragraph in empty table, as it already has at least one paragraph present.

internal static void Example_AddingImagesSampleToTable(string folderPath, bool openWord) {
    Console.WriteLine("[*] Creating standard document with some Images and Samples");
    var filePath = System.IO.Path.Combine(folderPath, "BasicDocumentWithImagesSample4.docx");
    var imagePaths = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "Images");

    using var document = WordDocument.Create(filePath);

    var table = document.AddTable(2, 2);
    table.Rows[0].Cells[0].Paragraphs[0].AddImage(System.IO.Path.Combine(imagePaths, "PrzemyslawKlysAndKulkozaurr.jpg"), 200, 200);

    // not really nessessary to add new paragraph since one is already there by default
    var paragraph = table.Rows[0].Cells[1].AddParagraph();
    paragraph.AddImage(System.IO.Path.Combine(imagePaths, "PrzemyslawKlysAndKulkozaurr.jpg"), 200, 200);

    document.AddHeadersAndFooters();

    var tableInHeader = document.Header.Default.AddTable(2, 2);
    tableInHeader.Rows[0].Cells[0].Paragraphs[0].AddImage(System.IO.Path.Combine(imagePaths, "PrzemyslawKlysAndKulkozaurr.jpg"), 200, 200);

    // not really nessessary to add new paragraph since one is already there by default
    var paragraphInHeader = tableInHeader.Rows[0].Cells[1].AddParagraph();
    paragraphInHeader.AddImage(System.IO.Path.Combine(imagePaths, "PrzemyslawKlysAndKulkozaurr.jpg"), 200, 200);

    document.Save(openWord);
}

@PrzemyslawKlys PrzemyslawKlys merged commit 134fd3a into EvotecIT:master Dec 31, 2023
2 of 3 checks passed
@tmheath
Copy link
Contributor Author

tmheath commented Dec 31, 2023

Thanks

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.

[Bug]Do Table Cells support adding images?
2 participants