Style Woes on Export to DOCX

This forum is for all Flare issues related to PDF, eBook, Microsoft Word, Adobe FrameMaker, XPS, and XHTML book targets.
Post Reply
thforbes
Jr. Propeller Head
Posts: 3
Joined: Wed May 24, 2017 12:23 pm

Style Woes on Export to DOCX

Post by thforbes »

Part of my organization's workflow involves exporting manuals to DOCX so that they can be approved. We've been working on streamlining this process, and we've found some successes there, but one thing continues to be a problem: when Flare exports docx files, the styles in use in the resulting document are a bit... exotic. By which I specifically mean, the system will create multiple versions of various styles, appending these with a "_1" or "_2." We have an existing, mostly-useful workaround involving MS Word macros that goes through and fixes these things, but unfortunately, it can only fix what it knows what to fix. Which is to say, if Flare spits out a style that's not a hard-coded part of the macro, it won't get fixed. And boy, Flare really loves to spit out new styles on different documents. For example, the H2s in one document are all tagged with class="heading2". The resulting Flare output gave us "h2_heading2," "h2_Heading2," "h2_heading2_1," and "h2_Heading2_1". I'd rather not keep expanding the macro to catch all of Flare's distinct outputs, so is there any method that anyone has found to prevent Flare from freestyling quite as hard?
ChoccieMuffin
Senior Propellus Maximus
Posts: 2630
Joined: Wed Apr 14, 2010 8:01 am
Location: Surrey, UK

Re: Style Woes on Export to DOCX

Post by ChoccieMuffin »

I can't offer any suggestions, but I sympathise with your pain. Word just refuses to play nicely with Flare, and it's a massive PITA! Best of luck, and sorry I can't help.
Started as a newbie with Flare 6.1, now using Flare 2023.
Report bugs at http://www.madcapsoftware.com/bugs/submit.aspx.
Request features at https://www.madcapsoftware.com/feedback ... quest.aspx
wclass
Propellus Maximus
Posts: 1238
Joined: Mon Feb 27, 2006 5:56 am
Location: Melbourne, Australia

Re: Style Woes on Export to DOCX

Post by wclass »

We used a macro that converted anything with the specified prefix to a standard Word style, so we didn't have to keep adding in all the possible ones that Flare came up with.
For example, all of your examples - "h2_heading2," "h2_Heading2," "h2_heading2_1," and "h2_Heading2_1" - since they all start with "h2_" would be converted to Word style "Heading 2".
We had a similar macro for converting "p_nnn" to Normal.
I will post the code.
Margaret Hassall - Melbourne
wclass
Propellus Maximus
Posts: 1238
Joined: Mon Feb 27, 2006 5:56 am
Location: Melbourne, Australia

Re: Style Woes on Export to DOCX

Post by wclass »

Macro to convert Flare generated web/html headings to Word

Code: Select all

Sub stl_convert_all_StandardHeadings()
' ----
' This routine converts web-type headings (H1) to standard Word ones (Heading 1),
' in the current active document.
' It loops through the document checking the style of each paragraph found,
' updating as it goes.
' Default is to convert all 6 levels of headings (H1 - H6).
' abd then convert subclasses (h1_something)

Dim rngSave As Range
Dim tPara As Paragraph
Dim tStyle As String
Dim newStyle As String
Dim stylePrefix As String

    ' save current location
    Set rngSave = Selection.Range
    
    For Each tPara In ActiveDocument.Paragraphs
        tStyle = tPara.Style
        If Len(tStyle) <= 2 Then
            stylePrefix = tStyle
        Else
            stylePrefix = Left(tStyle, 3)
        End If
        Select Case LCase(stylePrefix)
            Case "h1", "h1_"
                newStyle = "Heading 1"
            Case "h2", "h2_"
                newStyle = "Heading 2"
            Case "h3", "h3_"
                newStyle = "Heading 3"
            Case "h4", "h4_"
                newStyle = "Heading 4"
            Case "h5", "h5_"
                newStyle = "Heading 5"
            Case "h6", "h6_"
                newStyle = "Heading 6"
            Case Else
                newStyle = ""
        End Select
        If newStyle <> "" Then
            tPara.Style = newStyle
        End If
    
    Next tPara
    
    
    ' return cursor to  original location
    rngSave.Select
    Selection.Collapse
    
End Sub
Margaret Hassall - Melbourne
wclass
Propellus Maximus
Posts: 1238
Joined: Mon Feb 27, 2006 5:56 am
Location: Melbourne, Australia

Re: Style Woes on Export to DOCX

Post by wclass »

Macro to convert web/html paragraphs to Word styles.

Code: Select all

Sub stl_convert_all_paras_normal()
' ----
' This routine converts web-type paragraphs (p, p_1, p_2, etc) to Word Normal
' in the current selection in the active document.
' It loops through the document checking the style of each paragraph found,
' updating as it goes.

Dim rngSave As Range
Dim tPara As Paragraph
Dim tStyle As String
Dim newStyle As String
Dim stylePrefix As String

    ' save current location
    Set rngSave = Selection.Range
    
    For Each tPara In ActiveDocument.Paragraphs
        tStyle = tPara.Style
        If Len(tStyle) <= 2 Then
            stylePrefix = tStyle
        Else
            stylePrefix = Left(tStyle, 2)
        End If
        Select Case LCase(stylePrefix)
            Case "p", "p_"
                newStyle = "Normal"
            Case Else
                newStyle = ""
        End Select
        If newStyle <> "" Then
            tPara.Style = newStyle
        End If
    
    Next tPara
    
    ' return cursor to  original location
    rngSave.Select
    Selection.Collapse
    
End Sub
Margaret Hassall - Melbourne
fchan1
Jr. Propeller Head
Posts: 3
Joined: Mon Mar 23, 2020 1:04 pm

Re: Style Woes on Export to DOCX

Post by fchan1 »

Hello, I have the same problem and appreciate your code. :D
My question, though, is where/when do you run the macro? Can you point me to the documentation on this?
We are also looking into a workflow to use Word for collaboration & approval.

Thanks!
ChoccieMuffin
Senior Propellus Maximus
Posts: 2630
Joined: Wed Apr 14, 2010 8:01 am
Location: Surrey, UK

Re: Style Woes on Export to DOCX

Post by ChoccieMuffin »

The main thing is, you can't export to Word, do things in Word and then re-import back into Flare - the way Word deals with XML is just too foreign to be able to do this.

Rather than worrying too much about the styles that appear in Word, you are probably going to just let people put in their comments or corrections in Word and then you do a compare between what you sent them and what they send you back, then implement those changes manually in Flare.

If anyone does find some way to allow content to move back and forth between Word and Flare, they'll deserve a medal!
Started as a newbie with Flare 6.1, now using Flare 2023.
Report bugs at http://www.madcapsoftware.com/bugs/submit.aspx.
Request features at https://www.madcapsoftware.com/feedback ... quest.aspx
fchan1
Jr. Propeller Head
Posts: 3
Joined: Mon Mar 23, 2020 1:04 pm

Re: Style Woes on Export to DOCX

Post by fchan1 »

Oh, I see.

Well, that's a complete disappointment for me.
wclass
Propellus Maximus
Posts: 1238
Joined: Mon Feb 27, 2006 5:56 am
Location: Melbourne, Australia

Re: Style Woes on Export to DOCX

Post by wclass »

Just to follow up, we did this formatting for output that needed to end up in Word. We generated Word docs from Flare, then ran the macros, then copied the cleaner code into our existing Word templates. Since most of our output was for web/online rather than Word, we didn’t want to go to the trouble of trying to build page layouts in Flare when we already had Word templates that did what we wanted.

A round trip collaboration with Flare and Word will never work if you want to use the single sourcing features like snippets, variables, global projects, etc – and I love those features. Word is an end of the line output for us. We use it as a review tool sometimes but then we don’t need any fancy formatting, and any updates are manual.
Margaret Hassall - Melbourne
Post Reply