Topic
  • 9 replies
  • Latest Post - ‏2014-11-28T10:18:28Z by Dragos.Cojocari
alexfeseto
alexfeseto
5 Posts

Pinned topic Applying table styles defined in a Word template

‏2013-06-20T13:27:38Z |

Hello RPE users,

Does anybody have a strategy for using Table Styles defined in a Word template?

RPE elements like Table, Row and Cell all accept a style assignment via the Formatting / common / style name property, but it seems this is designed only for applying regular paragraph styles to child content.

I am currently investigating how I might use VBA to accomplish this, as it seems this is the likely route I must go.  This leads to another topic - how to identify the particular tables I'd like to apply the style to.  First thoughts are: this is not going to be so elegant :S

Any thoughts, hints, tips etc greatly appreciated.

 

Thanks in advance,

Alex

Updated on 2013-06-20T13:43:28Z at 2013-06-20T13:43:28Z by alexfeseto
  • BillTidy
    BillTidy
    72 Posts

    Re: Applying table styles defined in a Word template

    ‏2013-06-20T19:02:17Z  

    Not entirely clear what your problem is but... in your Word template, you can create a style and call it Table (as example- you can call it whatever you want). You can then use any of the Word styling elements to that quick style. In your RPE template, you select that style by name (or IIRC you can also do it with javascript to make RPE dynamically select different styles based on data condition(s)) so that your content is printed out how you want it in Word.

    The only thing I have found no solution to so far is rotated text - RPE will not do rotated text no matter what you do in your Word template.

  • alexfeseto
    alexfeseto
    5 Posts

    Re: Applying table styles defined in a Word template

    ‏2013-06-20T19:50:34Z  
    • BillTidy
    • ‏2013-06-20T19:02:17Z

    Not entirely clear what your problem is but... in your Word template, you can create a style and call it Table (as example- you can call it whatever you want). You can then use any of the Word styling elements to that quick style. In your RPE template, you select that style by name (or IIRC you can also do it with javascript to make RPE dynamically select different styles based on data condition(s)) so that your content is printed out how you want it in Word.

    The only thing I have found no solution to so far is rotated text - RPE will not do rotated text no matter what you do in your Word template.

    Unfortunately this is not what I was looking for.

    In addition to regular paragraph styles (Heading 1, Normal etc.) it's possible to define 'Table Styles' in a Word template - see this MS Office Word Help article.

    Table styles are especially useful for applying banded colours to odd/even table rows, and particular formatting (border, shading, alignment settings etc) to header rows, columns and so on.  Assigning a Table Style to a table in RPE would make for a nice shortcut; at the moment one has to separately set each property on the various table related elements.

    Looks like it's going to be an RFE with IBM...

    PS.  I also tried my luck with rotated text, but I figured for now I could live without it :-).

  • BillTidy
    BillTidy
    72 Posts

    Re: Applying table styles defined in a Word template

    ‏2013-06-21T12:19:17Z  

    Unfortunately this is not what I was looking for.

    In addition to regular paragraph styles (Heading 1, Normal etc.) it's possible to define 'Table Styles' in a Word template - see this MS Office Word Help article.

    Table styles are especially useful for applying banded colours to odd/even table rows, and particular formatting (border, shading, alignment settings etc) to header rows, columns and so on.  Assigning a Table Style to a table in RPE would make for a nice shortcut; at the moment one has to separately set each property on the various table related elements.

    Looks like it's going to be an RFE with IBM...

    PS.  I also tried my luck with rotated text, but I figured for now I could live without it :-).

    We may be talking at cross-purposes but .... you can create a style for tables and tell it all the same things for RPE as you can for normal Word tables, like not breaking across pages, keep rows together, etc. you can also have differently coloured rows if you need it, so your Word doc out of RPE will look the same as you could create in Word directly. The only thing you can't do (that I know of) is text rotation. Why not just attach an example Word doc with the table style you need - just make the content rubbish if it is data you are not allowed to publish for the world to see.

    Updated on 2013-06-21T12:20:40Z at 2013-06-21T12:20:40Z by BillTidy
  • SJB6
    SJB6
    7 Posts

    Re: Applying table styles defined in a Word template

    ‏2014-11-26T14:55:58Z  

    Sorry to drag up an old post.

    I just wanted to say that I too would like to use my Word stylesheet to define how my published tables are styled, using the table styles defined in Word. This is so that I can use a predefined company template.

    Alex, did you ever find a method? Using a VBA macro perhaps?

    Best Regards,

    Sam

    Updated on 2014-11-26T14:56:11Z at 2014-11-26T14:56:11Z by SJB6
  • alexfeseto
    alexfeseto
    5 Posts

    Re: Applying table styles defined in a Word template

    ‏2014-11-27T08:46:52Z  
    • SJB6
    • ‏2014-11-26T14:55:58Z

    Sorry to drag up an old post.

    I just wanted to say that I too would like to use my Word stylesheet to define how my published tables are styled, using the table styles defined in Word. This is so that I can use a predefined company template.

    Alex, did you ever find a method? Using a VBA macro perhaps?

    Best Regards,

    Sam

    Hi Sam,

    As you suspect, we resorted to VBA to achieve this. From memory, the kind of thing you need is this (not tested whatsoever, haven't touched VBA in a long time!):

    For Each myTbl In ActiveDocument.Tables
        myTbl.Style = "TableStyleName"
    Next myTbl
    

    The trick will be when you want to selectively apply styling to some tables, but not others; or to apply different table styles to certain tables. At this point, your VBA will start to build up, and how you go about doing this will depend on your particular needs.

    Incidentally, the genesis of this question was work we were doing on our RPE extension product, Author XG. It makes working with RPE a less-programmatic experience, and more similar to how you use a regular word-processor. Table styles is just one of the many user experience things we think we've cracked with this.

    Best of luck!

    Alex

    Alex Feseto | www.gebsreporting.com

  • SJB6
    SJB6
    7 Posts

    Re: Applying table styles defined in a Word template

    ‏2014-11-27T09:19:02Z  

    Hi Sam,

    As you suspect, we resorted to VBA to achieve this. From memory, the kind of thing you need is this (not tested whatsoever, haven't touched VBA in a long time!):

    <pre class="javascript dw" data-editor-lang="js" data-pbcklang="javascript" dir="ltr">For Each myTbl In ActiveDocument.Tables myTbl.Style = "TableStyleName" Next myTbl </pre>

    The trick will be when you want to selectively apply styling to some tables, but not others; or to apply different table styles to certain tables. At this point, your VBA will start to build up, and how you go about doing this will depend on your particular needs.

    Incidentally, the genesis of this question was work we were doing on our RPE extension product, Author XG. It makes working with RPE a less-programmatic experience, and more similar to how you use a regular word-processor. Table styles is just one of the many user experience things we think we've cracked with this.

    Best of luck!

    Alex

    Alex Feseto | www.gebsreporting.com

    Hi Alex,

    I really appreciate your taking the time to reply!

    I did some poking around yesterday and came up with (upon searching the web's VBA forums) what you've said. I've added a very crude 'skip first 7 tables' as those are found on the Template title page. For anyone else digging about, I'll include that here:

    Sub FormatAllTables()
    
    Dim skip As Integer
    Dim count As Integer
    skip = 7
    count = 1
    
    Dim objTable As Table
        For Each objTable In ActiveDocument.Tables
        If (count > skip) Then
          With objTable
            .Style = "MyTableStyleName"   'table style
            .Range.Style = "Body Text"  'paragraph style
            .Rows.HeadingFormat = False
            .ApplyStyleHeadingRows = True
            .Rows(1).HeadingFormat = True  'uses table style heading row format instead of another paragraph style
            .PreferredWidthType = wdPreferredWidthPercent
            .PreferredWidth = 100
          End With
        End If
        count = count + 1
        Next objTable
    End Sub
    

    Author XG looks like an absolute blessing, having battled with RPE/DNG for the past month or so without any training. But as a Software engineer at my company, I think its my job to battle on behalf of everyone else - in the name of layout consistency. I'll pass on the link to my boss though, in case he bites.

    Thanks once again,

    Sam

    Updated on 2014-11-27T09:19:45Z at 2014-11-27T09:19:45Z by SJB6
  • Dragos.Cojocari
    Dragos.Cojocari
    1647 Posts

    Re: Applying table styles defined in a Word template

    ‏2014-11-27T12:05:19Z  
    • SJB6
    • ‏2014-11-27T09:19:02Z

    Hi Alex,

    I really appreciate your taking the time to reply!

    I did some poking around yesterday and came up with (upon searching the web's VBA forums) what you've said. I've added a very crude 'skip first 7 tables' as those are found on the Template title page. For anyone else digging about, I'll include that here:

    <pre class="javascript dw" data-editor-lang="js" data-pbcklang="javascript" dir="ltr">Sub FormatAllTables() Dim skip As Integer Dim count As Integer skip = 7 count = 1 Dim objTable As Table For Each objTable In ActiveDocument.Tables If (count > skip) Then With objTable .Style = "MyTableStyleName" 'table style .Range.Style = "Body Text" 'paragraph style .Rows.HeadingFormat = False .ApplyStyleHeadingRows = True .Rows(1).HeadingFormat = True 'uses table style heading row format instead of another paragraph style .PreferredWidthType = wdPreferredWidthPercent .PreferredWidth = 100 End With End If count = count + 1 Next objTable End Sub </pre>

    Author XG looks like an absolute blessing, having battled with RPE/DNG for the past month or so without any training. But as a Software engineer at my company, I think its my job to battle on behalf of everyone else - in the name of layout consistency. I'll pass on the link to my boss though, in case he bites.

    Thanks once again,

    Sam

    Hey all,

     

    there a couple of questions I'd like to answer on this thread and I'll put them all here.

     

    >>> . The only thing you can't do (that I know of) is text rotation. (Bill)

    That is now possible with RPE 1.3.

     

    >>> Assigning a Table Style to a table in RPE would make for a nice shortcut; (Alex, Sam)

    This  is not yet possible with RPE  so the macro solution is still the way to go.

     

    >>> I've added a very crude 'skip first 7 tables' as those are found on the Template title page. (Sam)

    You could add comments or hidden fields ( such as bookmarks) in the first cell of your tables and store there the style name you want to use ( the bookmarks could be named like tblStyle_TableStyle1). Then in your macro you can go through all the tables and read the style from that field/bookmark/comment rather than hardcoding it in the macro. This could make for a more future proof macro.

     

    Regards,

        Dragos

  • SJB6
    SJB6
    7 Posts

    Re: Applying table styles defined in a Word template

    ‏2014-11-28T10:10:03Z  

    Hey all,

     

    there a couple of questions I'd like to answer on this thread and I'll put them all here.

     

    >>> . The only thing you can't do (that I know of) is text rotation. (Bill)

    That is now possible with RPE 1.3.

     

    >>> Assigning a Table Style to a table in RPE would make for a nice shortcut; (Alex, Sam)

    This  is not yet possible with RPE  so the macro solution is still the way to go.

     

    >>> I've added a very crude 'skip first 7 tables' as those are found on the Template title page. (Sam)

    You could add comments or hidden fields ( such as bookmarks) in the first cell of your tables and store there the style name you want to use ( the bookmarks could be named like tblStyle_TableStyle1). Then in your macro you can go through all the tables and read the style from that field/bookmark/comment rather than hardcoding it in the macro. This could make for a more future proof macro.

     

    Regards,

        Dragos

    Hi Dragos,

    Many thanks for your message. I followed your instruction and inserted a bookmark at the start of every troublesome table. It has made everything much simpler AND more robust.

    Again, for anyone interested:

    Sub RPEMacro()
    '
    ' RPEMacro Macro
    '
    ' work through all bookmarks left by RPE
    '
    
    ' BOOKMARK_LABEL is the prefix searched for
    Const BOOKMARK_LABEL As String = "tbl_Style_"
    
    
    ' preallocation of variables
    Dim oBookmark As Bookmark
    
    Dim oTable As Table
    Dim oCol As Column
    Dim oCell As Cell
    Dim firstFlg As Boolean
    
    Dim oSelection As Object
    Dim oIndex As Object
    ' END preallocation
    
    For Each oBookmark In ActiveDocument.Bookmarks
        If InStr(1, oBookmark.Name, BOOKMARK_LABEL, vbTextCompare) = 1 Then
        
            ' get table info
            Set oTable = oBookmark.Range.Tables(1)
            Set oCol = oTable.Columns(1)
    
            ' Format table with set-style macro
            Call FormatTables(oTable)
            
            ' Add ID numbers in first column to Index with set-ID macro
            Call AddIDEntries(oCol)
            
            ' Remove bookmark now that processes are complete
            oBookmark.Delete
        End If
    Next oBookmark
    
    'Update so that Index is populated'
    Call UpdateAllFields
    
    End Sub
    

    Thanks very much for taking the time to reply.

    Best,

    Sam

  • Dragos.Cojocari
    Dragos.Cojocari
    1647 Posts

    Re: Applying table styles defined in a Word template

    ‏2014-11-28T10:18:28Z  
    • SJB6
    • ‏2014-11-28T10:10:03Z

    Hi Dragos,

    Many thanks for your message. I followed your instruction and inserted a bookmark at the start of every troublesome table. It has made everything much simpler AND more robust.

    Again, for anyone interested:

    <pre class="javascript dw" data-editor-lang="js" data-pbcklang="javascript" dir="ltr">Sub RPEMacro() ' ' RPEMacro Macro ' ' work through all bookmarks left by RPE ' ' BOOKMARK_LABEL is the prefix searched for Const BOOKMARK_LABEL As String = "tbl_Style_" ' preallocation of variables Dim oBookmark As Bookmark Dim oTable As Table Dim oCol As Column Dim oCell As Cell Dim firstFlg As Boolean Dim oSelection As Object Dim oIndex As Object ' END preallocation For Each oBookmark In ActiveDocument.Bookmarks If InStr(1, oBookmark.Name, BOOKMARK_LABEL, vbTextCompare) = 1 Then ' get table info Set oTable = oBookmark.Range.Tables(1) Set oCol = oTable.Columns(1) ' Format table with set-style macro Call FormatTables(oTable) ' Add ID numbers in first column to Index with set-ID macro Call AddIDEntries(oCol) ' Remove bookmark now that processes are complete oBookmark.Delete End If Next oBookmark 'Update so that Index is populated' Call UpdateAllFields End Sub </pre>

    Thanks very much for taking the time to reply.

    Best,

    Sam

    Thanks for sharing your solution Sam.