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 :
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)
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)
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.
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
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)
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
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()
...