EvotecIT / OfficeIMO

Fast and easy to use cross-platform .NET library that creates or modifies Microsoft Word (DocX) and later also Excel (XLSX) files without installing any software. Library is based on Open XML SDK
MIT License
286 stars 50 forks source link

ConditionalFormattingFirstColumn sample #227

Closed BorisVolkan closed 3 months ago

BorisVolkan commented 3 months ago

Can you please provide a sample on how to use ConditionalFormattingFirstColumn. I have a problem with GridTable1Light table style. It makes first column bold. I just need header and footer to be bold.

Thank you

PrzemyslawKlys commented 3 months ago

Why can't you simply make those footer / header bold? I don't think ConditionalFormattingFirstColumn will do that for you?

PrzemyslawKlys commented 3 months ago

For the sake of example:

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

        document.AddParagraph();

        WordTable wordTable = document.AddTable(3, 5, WordTableStyle.PlainTable1);
        wordTable.Rows[0].Cells[0].Paragraphs[0].Text = "Test 1";
        wordTable.Rows[1].Cells[0].Paragraphs[0].Text = "Test 2";
        wordTable.Rows[2].Cells[0].Paragraphs[0].Text = "Test 3";
        wordTable.Rows[0].Cells[1].Paragraphs[0].Text = "Test 1";
        wordTable.Rows[1].Cells[1].Paragraphs[0].Text = "Test 2";
        wordTable.Rows[2].Cells[1].Paragraphs[0].Text = "Test 3";
        wordTable.Rows[0].Cells[2].Paragraphs[0].Text = "Test 1";
        wordTable.Rows[1].Cells[2].Paragraphs[0].Text = "Test 2";
        wordTable.Rows[2].Cells[2].Paragraphs[0].Text = "Test 3";
        wordTable.Rows[0].Cells[3].Paragraphs[0].Text = "Test 1";
        wordTable.Rows[1].Cells[3].Paragraphs[0].Text = "Test 2";
        wordTable.Rows[2].Cells[3].Paragraphs[0].Text = "Test 3";

        wordTable.ConditionalFormattingFirstRow = true;
        wordTable.ConditionalFormattingLastRow = true;
        wordTable.ConditionalFormattingFirstColumn = false;

        document.Save(openWord);
    }
}