Beispiel #1
0
        static void Main(string[] args)
        {
            //Creates new Word document instance for Word processing
            WordDocument document = new WordDocument();
            //Opens the input Word document
            Stream docStream = File.OpenRead(Path.GetFullPath(@"../../../Table.docx"));

            document.Open(docStream, FormatType.Docx);
            docStream.Dispose();
            //Adds a new custom table style
            WTableStyle tableStyle = document.AddTableStyle("CustomStyle") as WTableStyle;

            //Applies formatting for whole table
            tableStyle.TableProperties.RowStripe       = 1;
            tableStyle.TableProperties.ColumnStripe    = 1;
            tableStyle.TableProperties.Paddings.Top    = 0;
            tableStyle.TableProperties.Paddings.Bottom = 0;
            tableStyle.TableProperties.Paddings.Left   = 5.4f;
            tableStyle.TableProperties.Paddings.Right  = 5.4f;
            //Applies conditional formatting for first row
            ConditionalFormattingStyle firstRowStyle = tableStyle.ConditionalFormattingStyles.Add(ConditionalFormattingType.FirstRow);

            firstRowStyle.CharacterFormat.Bold      = true;
            firstRowStyle.CharacterFormat.TextColor = Syncfusion.Drawing.Color.FromArgb(255, 255, 255, 255);
            firstRowStyle.CellProperties.BackColor  = Syncfusion.Drawing.Color.Blue;
            //Applies conditional formatting for first column
            ConditionalFormattingStyle firstColumnStyle = tableStyle.ConditionalFormattingStyles.Add(ConditionalFormattingType.FirstColumn);

            firstColumnStyle.CharacterFormat.Bold = true;
            //Applies conditional formatting for odd row
            ConditionalFormattingStyle oddRowBandingStyle = tableStyle.ConditionalFormattingStyles.Add(ConditionalFormattingType.OddRowBanding);

            oddRowBandingStyle.CellProperties.BackColor = Syncfusion.Drawing.Color.WhiteSmoke;
            //Gets table to apply style
            WTable table = (WTable)document.LastSection.Tables[0];

            //Applies the custom table style to the table
            table.ApplyStyle("CustomStyle");
            //Saves the file in the given path
            docStream = File.Create(Path.GetFullPath(@"Result.docx"));
            document.Save(docStream, FormatType.Docx);
            docStream.Dispose();
            //Releases the resources of Word document instance
            document.Dispose();
        }
Beispiel #2
0
 static void Main(string[] args)
 {
     //Creates new Word document instance for Word processing
     using (WordDocument document = new WordDocument())
     {
         //Opens the input Word document
         Stream docStream = File.OpenRead(Path.GetFullPath(@"../../../Table.docx"));
         document.Open(docStream, FormatType.Docx);
         docStream.Dispose();
         //Gets the table style (Medium Shading 1 Accent 1) from the styles collection
         WTableStyle tableStyle = document.Styles.FindByName("Medium Shading 1 Accent 1", StyleType.TableStyle) as WTableStyle;
         //Gets the conditional formatting style of the first row (table headers) from the table style
         ConditionalFormattingStyle firstRowStyle = tableStyle.ConditionalFormattingStyles[ConditionalFormattingType.FirstRow];
         if (firstRowStyle != null)
         {
             //Modifies the background color for first row (table headers)
             firstRowStyle.CellProperties.BackColor = Syncfusion.Drawing.Color.FromArgb(255, 31, 56, 100);
         }
         //Saves the file in the given path
         docStream = File.Create(Path.GetFullPath(@"Result.docx"));
         document.Save(docStream, FormatType.Docx);
         docStream.Dispose();
     }
 }