none
OpenXML Table Styles RRS feed

  • Question

  • This is my first attempt with OpenXML and creating styles in code.  I am trying to get the a style to do the following:

    For a table,

    1st row should be Bold, White, and background color of dark blue

    all other rows should be (normal font), and a background color of white.

    All rows should have a border on all four sides.

    I've gotten the borders, and the conditional style for the 1st row, but I'm not seeing how to apply the background color to the rest of the document.  And yea, I do want a white background because there is a picture behind the table that is not white.

    Here is my code, what am I doing wrong?

    Style style1 = new Style( new TableProperties( new TableCellProperties() { Shading = new Shading() { Val = ShadingPatternValues.Clear, ThemeFill = ThemeColorValues.Background1,

    Fill = "FFFFFF", Color = "auto" } }, new TableBorders( new TopBorder() { Val = BorderValues.Single }, new BottomBorder() { Val = BorderValues.Single }, new LeftBorder() { Val = BorderValues.Single }, new RightBorder() { Val = BorderValues.Single }, new InsideHorizontalBorder() { Val = BorderValues.Single }, new InsideVerticalBorder() { Val = BorderValues.Single })), new TableStyleProperties( new TableRowProperties( new ParagraphProperties( new RunProperties() { Bold = new Bold() { Val = true }, Color = new Color() { Val = "FFFFFF", ThemeColor = ThemeColorValues.Background1 }, }), new CantSplit(), new TableHeader() { Val = OnOffOnlyValues.On }, new TableCellProperties() { Shading = new Shading() { Val = ShadingPatternValues.Clear, ThemeFill = ThemeColorValues.Text2, Fill = "1F497D", Color = "auto" } } ) ) { Type = TableStyleOverrideValues.FirstRow } ) { Default = false, Type = StyleValues.Table, StyleId = "TableStyle1", StyleName = new StyleName() { Val = "TableStyle1" }, UIPriority = new UIPriority() { Val = 1 } };



    jhoop

    Friday, January 31, 2014 3:56 PM

Answers

  • Hi jhoop

    Are you able to create this table style manually, in the Word application interface?

    If yes, then best would be to save a document with that style and compare it to the result you currently have, where the white color is missing. You can use the Open XML SDK Productivity Tool to make the comparison - it should also be able to generate the code that would convert the document your code is currently generating to the result you want.


    Cindy Meister, VSTO/Word MVP, my blog

    Friday, January 31, 2014 6:44 PM
    Moderator
  • Hi jhoop

    I can give you the starting point, but if you encounter difficulties it would be best to ask in a forum that supports end-user where you'll find more people who use the feature regularly and know its quirks. Because it is quirky and I'm not current on it at the moment:

    http://answers.microsoft.com/en-us/office/forum/word

    To get started, in Word go to the Home tab, Styles group. Click on the dialog launcher of the group to open the Styles task pane. At the bottom are three buttons, the left-hand one is for creating a new style.

    In this dialog box, give the style a name and select Table as the style Type.

    In the bottom half of the dialog box you'll get tools for defining the style. If you can't find something you want to use, click the "Format" button to get to the full menus for the different kinds of properties. But one of the tools "right in your face" is for the Fill color, so you might not need to do a lot of digging :-)


    Cindy Meister, VSTO/Word MVP, my blog

    Friday, January 31, 2014 8:35 PM
    Moderator

All replies

  • Hi jhoop

    Are you able to create this table style manually, in the Word application interface?

    If yes, then best would be to save a document with that style and compare it to the result you currently have, where the white color is missing. You can use the Open XML SDK Productivity Tool to make the comparison - it should also be able to generate the code that would convert the document your code is currently generating to the result you want.


    Cindy Meister, VSTO/Word MVP, my blog

    Friday, January 31, 2014 6:44 PM
    Moderator
  • Maybe I am unaware of how to do that.

    I can create styles for paragraphs, but I do not know how to create styles for tables within MS Word.


    jhoop

    Friday, January 31, 2014 6:47 PM
  • Hi jhoop

    I can give you the starting point, but if you encounter difficulties it would be best to ask in a forum that supports end-user where you'll find more people who use the feature regularly and know its quirks. Because it is quirky and I'm not current on it at the moment:

    http://answers.microsoft.com/en-us/office/forum/word

    To get started, in Word go to the Home tab, Styles group. Click on the dialog launcher of the group to open the Styles task pane. At the bottom are three buttons, the left-hand one is for creating a new style.

    In this dialog box, give the style a name and select Table as the style Type.

    In the bottom half of the dialog box you'll get tools for defining the style. If you can't find something you want to use, click the "Format" button to get to the full menus for the different kinds of properties. But one of the tools "right in your face" is for the Fill color, so you might not need to do a lot of digging :-)


    Cindy Meister, VSTO/Word MVP, my blog

    Friday, January 31, 2014 8:35 PM
    Moderator