Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.
Thu Jul 30, 2020 8:04 am
- Code: Select all
document_Renamed.LoadFromFile("Sample.doc")
Dim s1 As ParagraphStyle
s1 = document_Renamed.AddParagraphStyle("textStyle")
s1.CharacterFormat.FontName = "Arial"
Dim sections As SectionCollection = Document.Sections
For Each section As Section In sections
Dim p1 As Paragraph = section.Paragraphs(0)
p1.ApplyStyle(s1.Name)
Next
'Save pdf file.
document_Renamed.SaveToFile("Sample.pdf", FileFormat.PDF)
Hi guys,
Im trying to convert the whole doc to Arial font style, any solution for it?
i got an error from here
Dim sections As SectionCollection = Document.Sections
im trying to get all thee sections, but how?
Im new to spire doc.
Thanks and Regards,
Lean
-
lyjun550
-
- Posts: 4
- Joined: Wed Jul 22, 2020 5:04 am
Thu Jul 30, 2020 9:53 am
Hello Lean,
Thanks for your inquiry.
The following is the code for your reference. If there is any question, please provide your input file for further investigation.
- Code: Select all
Dim document_Renamed As Document = New Document
document_Renamed.LoadFromFile("Sample.docx")
Dim style As ParagraphStyle = New ParagraphStyle(document_Renamed)
style.Name = "Arial style"
style.CharacterFormat.FontName = "Arial"
document_Renamed.Styles.Add(style)
Dim sections As SectionCollection = document_Renamed.Sections
'Method 1
For Each section As Section In sections
For Each para As Paragraph In section.Paragraphs
para.ApplyStyle(style.Name)
Next
Next
''Method 2
'For Each section As Section In sections
' For Each para As Paragraph In section.Paragraphs
' For Each obj As DocumentObject In para.ChildObjects
' If (obj.DocumentObjectType = DocumentObjectType.TextRange) Then
' CType(obj, TextRange).CharacterFormat.FontName = "Arial"
' End If
' Next
' Next
'Next
document_Renamed.SaveToFile("Sample.pdf", FileFormat.PDF)
Sincerely,
Rachel
E-iceblue support team
-
rachel.lei
-
- Posts: 1571
- Joined: Tue Jul 09, 2019 2:22 am
Mon Aug 03, 2020 12:56 am
rachel.lei wrote:Hello Lean,
Thanks for your inquiry.
The following is the code for your reference. If there is any question, please provide your input file for further investigation.
- Code: Select all
Dim document_Renamed As Document = New Document
document_Renamed.LoadFromFile("Sample.docx")
Dim style As ParagraphStyle = New ParagraphStyle(document_Renamed)
style.Name = "Arial style"
style.CharacterFormat.FontName = "Arial"
document_Renamed.Styles.Add(style)
Dim sections As SectionCollection = document_Renamed.Sections
'Method 1
For Each section As Section In sections
For Each para As Paragraph In section.Paragraphs
para.ApplyStyle(style.Name)
Next
Next
''Method 2
'For Each section As Section In sections
' For Each para As Paragraph In section.Paragraphs
' For Each obj As DocumentObject In para.ChildObjects
' If (obj.DocumentObjectType = DocumentObjectType.TextRange) Then
' CType(obj, TextRange).CharacterFormat.FontName = "Arial"
' End If
' Next
' Next
'Next
document_Renamed.SaveToFile("Sample.pdf", FileFormat.PDF)
Sincerely,
Rachel
E-iceblue support team
Hi Rachel,
Why my SectionCollection is not defined?
-
lyjun550
-
- Posts: 4
- Joined: Wed Jul 22, 2020 5:04 am
Mon Aug 03, 2020 2:25 am
Hello,
Thanks for your response.
Here I uploaded
my test project for your reference, please run it directly on your side. If there are any questions, please feel free to write back.
Sincerely,
Rachel
E-iceblue support team
-
rachel.lei
-
- Posts: 1571
- Joined: Tue Jul 09, 2019 2:22 am
Mon Aug 03, 2020 4:10 am
rachel.lei wrote:Hello,
Thanks for your response.
Here I uploaded for your reference, please run it directly on your side. If there are any questions, please feel free to write back.
Sincerely,
Rachel
E-iceblue support team
Thanks Rachel,
Its working, thanks!
I have forgot to import Spire.Doc.Collections.
Thank you and Regards,
Lean
-
lyjun550
-
- Posts: 4
- Joined: Wed Jul 22, 2020 5:04 am
Mon Aug 03, 2020 5:35 am
Hello,
Glad to hear that!
If you need further assistance, please feel free to contact us.
Wish you all the best!
Sincerely,
Rachel
E-iceblue support team
-
rachel.lei
-
- Posts: 1571
- Joined: Tue Jul 09, 2019 2:22 am
Mon Aug 03, 2020 7:32 am
rachel.lei wrote:Hello,
Glad to hear that!
If you need further assistance, please feel free to contact us.
Wish you all the best!
Sincerely,
Rachel
E-iceblue support team
Hi Rachel,
I wanna have the listNumber with alphabet
Example:
(a)
(b)
(c)
How can i do that? Is that possible?
Thanks and regards,
Lean
-
lyjun550
-
- Posts: 4
- Joined: Wed Jul 22, 2020 5:04 am
Mon Aug 03, 2020 10:10 am
Hello,
Thanks for your post.
Please refer to the following code. If there are any questions, just feel free to write back.
- Code: Select all
Dim document As Document = New Document
Dim section As Section = document.AddSection
Dim listStyle As ListStyle = New ListStyle(document, ListType.Numbered)
listStyle.Name = "levelstyle"
listStyle.Levels(0).NumberPrefix = "("
listStyle.Levels(0).NumberSufix = ")"
listStyle.Levels(0).PatternType = ListPatternType.LowLetter
document.ListStyles.Add(listStyle)
Dim paragraph As Paragraph = section.AddParagraph
paragraph.AppendText("The first item")
paragraph.ListFormat.ApplyStyle("levelstyle")
paragraph.ListFormat.ListLevelNumber = 0
paragraph = section.AddParagraph
paragraph.AppendText("The second item")
paragraph.ListFormat.ApplyStyle("levelstyle")
paragraph.ListFormat.ListLevelNumber = 0
document.SaveToFile("result.docx", FileFormat.Docx)
Sincerely,
Lynn
E-iceblue support team
-
lynn.zhang
-
- Posts: 57
- Joined: Mon Jul 27, 2020 2:27 am
Mon Aug 10, 2020 11:34 am
Hi
Greetings from E-iceblue.
Did my code work for you? Could you please give us some feedback at your convenience?
Sincerely,
Lynn
E-iceblue support team
-
lynn.zhang
-
- Posts: 57
- Joined: Mon Jul 27, 2020 2:27 am