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

Improve Table with 2 new methods and 2 properties #70

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

PrzemyslawKlys
Copy link
Member

@PrzemyslawKlys PrzemyslawKlys commented Nov 11, 2022

Closes:

Details:

  • Add DistributeColumnsEvenly method
  • Add SetWidthPercentage method
  • Add AllowRowToBreakAcrossPages property for table, and each row
  • Add RepeatAsHeaderRowAtTheTopOfEachPage property for table (applies to first row)
  • Fixes ColumnWidthType and ColumnWidth when using on Table (now table row)
internal static void Example_DifferentTableSizes(string folderPath, bool openWord) {
    Console.WriteLine("[*] Creating standard document with tables of different sizes");
    string filePath = System.IO.Path.Combine(folderPath, "Document with Tables of different sizes.docx");
    using (WordDocument document = WordDocument.Create(filePath)) {
        document.AddParagraph("Table 1");
        WordTable wordTable = document.AddTable(3, 4, WordTableStyle.PlainTable1);
        wordTable.Rows[0].Cells[0].Paragraphs[0].Text = "Test 1";

        document.AddParagraph();
        document.AddParagraph();
        document.AddParagraph("Table 2 - Sized for 2000 width / Centered");
        WordTable wordTable1 = document.AddTable(2, 6, WordTableStyle.PlainTable1);
        wordTable1.Rows[0].Cells[0].Paragraphs[0].Text = "Test 1";
        wordTable1.Rows[1].Cells[0].Paragraphs[0].Text = "Test 1 - ok longer text, no autosize right?";
        wordTable1.WidthType = TableWidthUnitValues.Pct;
        wordTable1.Width = 2000;
        wordTable1.Alignment = TableRowAlignmentValues.Center;

        document.AddParagraph();
        document.AddParagraph();
        document.AddParagraph("Table 3 - By default the table is autosized for full width");
        WordTable wordTable2 = document.AddTable(3, 4, WordTableStyle.PlainTable1);
        wordTable2.Rows[0].Cells[0].Paragraphs[0].Text = "Test 1";

        document.AddParagraph();
        document.AddParagraph();
        document.AddParagraph("Table 4 - Magic number 5000 (full width)");
        WordTable wordTable3 = document.AddTable(3, 4, WordTableStyle.PlainTable1);
        wordTable3.WidthType = TableWidthUnitValues.Pct;
        wordTable3.Width = 5000;
        wordTable3.Rows[0].Cells[0].Paragraphs[0].Text = "Test 1";

        document.AddParagraph();
        document.AddParagraph();
        document.AddParagraph("Table 5 - 50% by using 2500 width (pct)");
        WordTable wordTable4 = document.AddTable(3, 4, WordTableStyle.PlainTable1);
        wordTable4.WidthType = TableWidthUnitValues.Pct;
        wordTable4.Width = 2500;
        wordTable4.Rows[0].Cells[0].Paragraphs[0].Text = "Test 1";

        document.AddParagraph();
        document.AddParagraph();
        document.AddParagraph("Table 6 - 50% by using 2500 width (pct), that we fix to full width");
        WordTable wordTable5 = document.AddTable(3, 4, WordTableStyle.PlainTable1);
        // this data is temporary just to prove things work
        wordTable5.WidthType = TableWidthUnitValues.Pct;
        wordTable5.Width = 2500;
        // lets fix it for full width
        wordTable5.DistributeColumnsEvenly();

        document.AddParagraph();
        document.AddParagraph();
        document.AddParagraph("Table 6 - 50%");
        WordTable wordTable6 = document.AddTable(3, 4, WordTableStyle.PlainTable1);
        wordTable6.SetWidthPercentage(50);

        document.AddParagraph();
        document.AddParagraph();
        document.AddParagraph("Table 6 - 75%");
        WordTable wordTable7 = document.AddTable(3, 4, WordTableStyle.PlainTable1);
        wordTable7.SetWidthPercentage(75);

        document.Save(openWord);
    }
}

@PrzemyslawKlys PrzemyslawKlys changed the title Add DistributeColumnsEvenly and SetWidthPercentage Add DistributeColumnsEvenly and SetWidthPercentage and AllowRowToBreakAcrossPages and RepeatAsHeaderRowAtTheTopOfEachPage Nov 13, 2022
@PrzemyslawKlys PrzemyslawKlys changed the title Add DistributeColumnsEvenly and SetWidthPercentage and AllowRowToBreakAcrossPages and RepeatAsHeaderRowAtTheTopOfEachPage Improve Table with 2 new methods and 2 properties Nov 13, 2022
@PrzemyslawKlys PrzemyslawKlys marked this pull request as draft January 29, 2023 18:11
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.

1 participant