Heading 2 style does not apply to Paragraph correctly using VB.NET

Hi !

i’m french, excuse me for my english.

i’ve got word document, and i must add text bloc when conditions appears.
i’m in Visual Studio 2019, VB.net, website framework 3.5.

i’m using bookmark to go to text for add header and text paragraph.
my document have more paragraph and headers, i’ve just add next number of header
my code :

 b.MoveToBookmark("optionAChiffrer", False, True)
 b.Writeln()

 b.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading2
 'b.CurrentParagraph.ParagraphFormat.StyleName = "Heading 2"
 b.Writeln("My header text")
 b.ParagraphFormat.StyleIdentifier = StyleIdentifier.Normal
 b.CurrentParagraph.ParagraphFormat.StyleName = "Normal"
 b.Writeln()
 b.Writeln("write normal text paragraph")

image.png (23.1 KB)

if i open the doc in word and clic my header, and the “header 2” style, it’s work (bold and properties)
same problem with all created header blocs.

Thanks for help.

@conan76

Could you please ZIP and attach your input and expected output Word documents here for our reference? We will then provide you more information on it.

Hi !

Ok, but i need to modify source document and replace all text, because contains confidential informations.

Join zip file contains :
source : doc source
result, after treatment
wanted result

my code add bloc or part of bloc (with writeln()) from condtionnal variable

bookmarks name used :
revetementPVC
parquetStrat
parquetColle
optionAChiffrer

in my test, i’ve add all bloc to see headings incrementation.

If you open the result file, and just click to headers wanted and click in style heading 2 you see application of style to line (bold and incremential number)

thanks for your help.Aspose docs.zip (69.0 KB)

@conan76

We have tested the scenario using the latest version of Aspose.Words for .NET 20.8 and have not found the shared issue. So, please use Aspose.Words for .NET 20.8. We have attached the output DOCX with this post for your kind reference. out 20.8.zip (19.4 KB)

We suggest you please get the 30 days temporary license and apply it before importing document.

Thanks,

My project Aspose Words version is 13.8 (yes it’s an old project).
my IT department manager is back from holidays, see with him if licence is always valid to upgrade to Aspose Total 20.8, and see if all project work with this upgrade and all previous documents generation.
thanks for you’re help, if i’ve got a problem, i’ll back here.

Vincent.

@conan76

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.

Bad news…

after change in my project many,many,many,many

monDocFinal.Range.Replace("@@strCommune@@", false, false)

by

Dim so As New Aspose.Words.Replacing.FindReplaceOptions() With {.MatchCase = False, .FindWholeWordsOnly = False} 
monDocFinal.Range.Replace("@@strCommune@@", strCommuneProgramme, so)

i’ve regenarate the new document with aspose 20.6 (Framework 2, because no 3.5 dll)
i’ve the same problem with headers

perhaps something is wrong in my code, not document because you use it and it’s work for you.

i think i’ll make sample project to see what exactly doesn’t work this afternoon

Hi !

When i made a project sample for you, i’m tested and it’s work… strange…
i’ve search difference between sample and my project and found when i’ve got problem

in different bookmark i’ve just say to you my first write (header and first normal line)
in my sample i’ve set just header an 1st line inside all bookmark and it’s work : say to me : strange…

but problem appear to the newt writeln, because i’ve got list parts :

        b.MoveToBookmark("revetementPVC", False, True)
    b.Writeln()
    b.CurrentParagraph.ParagraphFormat.StyleName = "Heading 2"
    b.Writeln("REVETEMENT PVC")
    b.CurrentParagraph.ParagraphFormat.StyleName = "Normal"
    b.Writeln()


    b.Writeln("Fourniture et pose de revêtements de sol souples avec les caractéristiques suivantes :")

    Dim caracteristiques As New List(Of String)
    With caracteristiques
        .Add("Classement UPEC : conforme à la réglementation U2S P2")
        .Add("Indice d’insonorisation : 20dB")
        .Add("Epaisseur : 7mm")
        .Add("Largeur 4ml.")
        .Add("Pose : collée avec un produit préconisé sur dalle béton.")
        .Add("Référence : Tx Living de chez Tarkett ou équivalent.")
    End With

    b.ListFormat.ApplyBulletDefault()
    b.ListFormat.ListLevel.NumberFormat = "-"

    For Each caract In caracteristiques
        b.Writeln(caract)
    Next

    b.ListFormat.ListOutdent()
    'b.ListFormat.RemoveNumbers()
    b.Writeln()

when i set remove numbers, it’s remove for all next.
if i not set it, all my next write line is include in list

if you see in previous post with file “Wanted Result” you see under “Revevement PVC” title you see one of list include in header 2.2

what is solution to specify and of list to not remove numbers for all headers but just say “end of list” ?

After many tests i’ve join my sample with full code, no solution…
testAspose.zip (5.6 MB)

@conan76

Please use ParagraphFormat.ClearFormatting method before inserting new content into document to get the desired output. Please check the following modified code. Hope this helps you.

Private Sub UpdateDoc_Revetement(doc As Aspose.Words.Document)

    Dim b As New Aspose.Words.DocumentBuilder(doc)

    'here parts are normaly conditional, just for cumulative test to chained numbers, set all present.
    b.ParagraphFormat.ClearFormatting()
    UpdateDoc_Revetement_PVC(b)
    b.ParagraphFormat.ClearFormatting()
    UpdateDoc_Revetement_ParquetStratifie(b)
    b.ParagraphFormat.ClearFormatting()
    UpdateDoc_Revetement_ParquetColle(b)
    b.ParagraphFormat.ClearFormatting()
    UpdateDoc_Revetement_OptionsAChiffrer(b)

End Sub

Thanks, it’s works, just my last 2.5 isn’t bold like other, bold is set normaly to headings 2.

just now, my boss waiting update licence, to finish SQL doc source save, and little code before to put in production.

@conan76

We have logged this problem in our issue tracking system as WORDSNET-21055 . You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

@conan76

Regarding WORDSNET-21055, we suggest you please call builder.Font.ClearFormatting() after builder.MoveToBookmark(“optionAChiffrer”, false, true) just before inserting content. Hope this helps you.

Private Sub UpdateDoc_Revetement_OptionsAChiffrer(b As DocumentBuilder)

        b.MoveToBookmark("optionAChiffrer", False, True)
        b.Font.ClearFormatting()
        b.Writeln()

        b.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading2
        b.Writeln("OPTIONS A CHIFFRER OBLIGATOIREMENT")
        b.ParagraphFormat.StyleIdentifier = StyleIdentifier.Normal
        b.ParagraphFormat.StyleName = "Normal"
        b.Writeln()
        ...