Last active
February 7, 2017 04:39
-
-
Save aspose-words/278a891e14482f7fb9e9c5dfff587c9a to your computer and use it in GitHub Desktop.
This Gist contains VisualBasic code snippets for examples of Aspose.Words for .NET.
This gist exceeds the recommended number of files (~10).
To access all files, please clone this gist.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Examples-VisualBasic |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_LINQ() | |
| Dim fileName As String = "BubbleChart.docx" | |
| ' Load the template document. | |
| Dim doc As New Document(dataDir & fileName) | |
| ' Create a Reporting Engine. | |
| Dim engine As New ReportingEngine() | |
| ' Execute the build report. | |
| engine.BuildReport(doc, Common.GetContracts(), "contracts") | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| ' Save the finished document to disk. | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_LINQ() | |
| Dim fileName As String = "BulletedList.doc" | |
| ' Load the template document. | |
| Dim doc As New Document(dataDir & fileName) | |
| ' Create a Reporting Engine. | |
| Dim engine As New ReportingEngine() | |
| ' Execute the build report. | |
| engine.BuildReport(doc, Common.GetClients(), "clients") | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| ' Save the finished document to disk. | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_LINQ() | |
| Dim fileName As String = "ChartWithFilteringGroupingOrdering.docx" | |
| ' Load the template document. | |
| Dim doc As New Document(dataDir & fileName) | |
| ' Create a Reporting Engine. | |
| Dim engine As New ReportingEngine() | |
| ' Execute the build report. | |
| engine.BuildReport(doc, Common.GetContracts(), "contracts") | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| ' Save the finished document to disk. | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Public Class Client | |
| Public Property Name() As [String] | |
| Get | |
| Return m_Name | |
| End Get | |
| Set(value As [String]) | |
| m_Name = value | |
| End Set | |
| End Property | |
| Private m_Name As [String] | |
| End Class |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim returnCollection As New List(Of Client)() | |
| For Each manager As Manager In GetManagers() | |
| For Each contract As Contract In manager.Contracts | |
| returnCollection.Add(contract.Client) | |
| Next | |
| Next | |
| Return returnCollection |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim returnCollection As New List(Of Contract)() | |
| For Each manager As Manager In GetManagers() | |
| For Each contract As Contract In manager.Contracts | |
| ' Yield Return contract | |
| returnCollection.Add(contract) | |
| Next | |
| Next | |
| Return returnCollection |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim managers As IEnumerator(Of Manager) = GetManagers().GetEnumerator() | |
| managers.MoveNext() | |
| Return managers.Current |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim returnCollection As New List(Of Manager)() | |
| Dim manager As New Manager() With { _ | |
| .Name = "John Smith", _ | |
| .Age = 36, _ | |
| .Photo = Photo() _ | |
| } | |
| manager.Contracts = New Contract() {New Contract() With { _ | |
| .Client = New Client() With { _ | |
| .Name = "A Company" _ | |
| }, _ | |
| .Manager = manager, _ | |
| .Price = 1200000, _ | |
| .[Date] = New DateTime(2015, 1, 1) _ | |
| }, New Contract() With { _ | |
| .Client = New Client() With { _ | |
| .Name = "B Ltd." _ | |
| }, _ | |
| .Manager = manager, _ | |
| .Price = 750000, _ | |
| .[Date] = New DateTime(2015, 4, 1) _ | |
| }, New Contract() With { _ | |
| .Client = New Client() With { _ | |
| .Name = "C & D" _ | |
| }, _ | |
| .Manager = manager, _ | |
| .Price = 350000, _ | |
| .[Date] = New DateTime(2015, 7, 1) _ | |
| }} | |
| returnCollection.Add(manager) | |
| manager = New Manager() With { _ | |
| .Name = "Tony Anderson", _ | |
| .Age = 37, _ | |
| .Photo = Photo() _ | |
| } | |
| manager.Contracts = New Contract() {New Contract() With { _ | |
| .Client = New Client() With { _ | |
| .Name = "E Corp." _ | |
| }, _ | |
| .Manager = manager, _ | |
| .Price = 650000, _ | |
| .[Date] = New DateTime(2015, 2, 1) _ | |
| }, New Contract() With { _ | |
| .Client = New Client() With { _ | |
| .Name = "F & Partners" _ | |
| }, _ | |
| .Manager = manager, _ | |
| .Price = 550000, _ | |
| .[Date] = New DateTime(2015, 8, 1) _ | |
| }} | |
| returnCollection.Add(manager) | |
| manager = New Manager() With { _ | |
| .Name = "July James", _ | |
| .Age = 38, _ | |
| .Photo = Photo() _ | |
| } | |
| manager.Contracts = New Contract() {New Contract() With { _ | |
| .Client = New Client() With { _ | |
| .Name = "G & Co." _ | |
| }, _ | |
| .Manager = manager, _ | |
| .Price = 350000, _ | |
| .[Date] = New DateTime(2015, 2, 1) _ | |
| }, New Contract() With { _ | |
| .Client = New Client() With { _ | |
| .Name = "H Group" _ | |
| }, _ | |
| .Manager = manager, _ | |
| .Price = 250000, _ | |
| .[Date] = New DateTime(2015, 5, 1) _ | |
| }, New Contract() With { _ | |
| .Client = New Client() With { _ | |
| .Name = "I & Sons" _ | |
| }, _ | |
| .Manager = manager, _ | |
| .Price = 100000, _ | |
| .[Date] = New DateTime(2015, 7, 1) _ | |
| }, New Contract() With { _ | |
| .Client = New Client() With { _ | |
| .Name = "J Ent." _ | |
| }, _ | |
| .Manager = manager, _ | |
| .Price = 100000, _ | |
| .[Date] = New DateTime(2015, 8, 1) _ | |
| }} | |
| returnCollection.Add(manager) | |
| Return returnCollection |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_LINQ() | |
| ' Load the photo and read all bytes. | |
| Dim imgdata As Byte() = System.IO.File.ReadAllBytes(dataDir & Convert.ToString("photo.png")) | |
| Return imgdata |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_LINQ() | |
| Dim fileName As String = "CommonList.doc" | |
| ' Load the template document. | |
| Dim doc As New Document(dataDir & fileName) | |
| ' Create a Reporting Engine. | |
| Dim engine As New ReportingEngine() | |
| ' Execute the build report. | |
| engine.BuildReport(doc, Common.GetManagers(), "managers") | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| ' Save the finished document to disk. | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_LINQ() | |
| Dim fileName As String = "CommonMasterDetail.doc" | |
| ' Load the template document. | |
| Dim doc As New Document(dataDir & fileName) | |
| ' Create a Reporting Engine. | |
| Dim engine As New ReportingEngine() | |
| ' Execute the build report. | |
| engine.BuildReport(doc, Common.GetManagers(), "managers") | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| ' Save the finished document to disk. | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Public Class Contract | |
| Public Property Manager() As Manager | |
| Get | |
| Return m_Manager | |
| End Get | |
| Set(value As Manager) | |
| m_Manager = value | |
| End Set | |
| End Property | |
| Private m_Manager As Manager | |
| Public Property Client() As Client | |
| Get | |
| Return m_Client | |
| End Get | |
| Set(value As Client) | |
| m_Client = value | |
| End Set | |
| End Property | |
| Private m_Client As Client | |
| Public Property Price() As Single | |
| Get | |
| Return m_Price | |
| End Get | |
| Set(value As Single) | |
| m_Price = value | |
| End Set | |
| End Property | |
| Private m_Price As Single | |
| Public Property [Date]() As DateTime | |
| Get | |
| Return m_Date | |
| End Get | |
| Set(value As DateTime) | |
| m_Date = value | |
| End Set | |
| End Property | |
| Private m_Date As DateTime | |
| End Class |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_LINQ() | |
| Dim fileName As String = "HelloWorld.doc" | |
| ' Load the template document. | |
| Dim doc As New Document(dataDir & fileName) | |
| ' Create an instance of sender class to set it' S properties. | |
| Dim sender As New Sender() With { _ | |
| .Name = "LINQ Reporting Engine", _ | |
| .Message = "Hello World" _ | |
| } | |
| ' Create a Reporting Engine. | |
| Dim engine As New ReportingEngine() | |
| ' Execute the build report. | |
| engine.BuildReport(doc, sender, "sender") | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| ' Save the finished document to disk. | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_LINQ() | |
| Dim fileName As String = "InParagraphList.doc" | |
| ' Load the template document. | |
| Dim doc As New Document(dataDir & fileName) | |
| ' Create a Reporting Engine. | |
| Dim engine As New ReportingEngine() | |
| ' Execute the build report. | |
| engine.BuildReport(doc, Common.GetClients(), "clients") | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| ' Save the finished document to disk. | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_LINQ() | |
| Dim fileName As String = "InTableAlternateContent.doc" | |
| ' Load the template document. | |
| Dim doc As New Document(dataDir & fileName) | |
| ' Create a Reporting Engine. | |
| Dim engine As New ReportingEngine() | |
| ' Execute the build report. | |
| engine.BuildReport(doc, Common.GetContracts(), "contracts") | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| ' Save the finished document to disk. | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_LINQ() | |
| Dim fileName As String = "InTableList.doc" | |
| ' Load the template document. | |
| Dim doc As New Document(dataDir & fileName) | |
| ' Create a Reporting Engine. | |
| Dim engine As New ReportingEngine() | |
| ' Execute the build report. | |
| engine.BuildReport(doc, Common.GetManagers(), "managers") | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| ' Save the finished document to disk. | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_LINQ() | |
| Dim fileName As String = "InTableMasterDetail.doc" | |
| ' Load the template document. | |
| Dim doc As New Document(dataDir & fileName) | |
| ' Create a Reporting Engine. | |
| Dim engine As New ReportingEngine() | |
| ' Execute the build report. | |
| engine.BuildReport(doc, Common.GetManagers(), "managers") | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| ' Save the finished document to disk. | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_LINQ() | |
| Dim fileName As String = "InTableWithFilteringGroupingSorting.doc" | |
| ' Load the template document. | |
| Dim doc As New Document(dataDir & fileName) | |
| ' Create a Reporting Engine. | |
| Dim engine As New ReportingEngine() | |
| ' Execute the build report. | |
| engine.BuildReport(doc, Common.GetContracts(), "contracts") | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| ' Save the finished document to disk. | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Public Class Manager | |
| Public Property Name() As [String] | |
| Get | |
| Return m_Name | |
| End Get | |
| Set(value As [String]) | |
| m_Name = value | |
| End Set | |
| End Property | |
| Private m_Name As [String] | |
| Public Property Age() As Integer | |
| Get | |
| Return m_Age | |
| End Get | |
| Set(value As Integer) | |
| m_Age = value | |
| End Set | |
| End Property | |
| Private m_Age As Integer | |
| Public Property Photo() As Byte() | |
| Get | |
| Return m_Photo | |
| End Get | |
| Set(value As Byte()) | |
| m_Photo = value | |
| End Set | |
| End Property | |
| Private m_Photo As Byte() | |
| Public Property Contracts() As IEnumerable(Of Contract) | |
| Get | |
| Return m_Contracts | |
| End Get | |
| Set(value As IEnumerable(Of Contract)) | |
| m_Contracts = value | |
| End Set | |
| End Property | |
| Private m_Contracts As IEnumerable(Of Contract) | |
| End Class |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_LINQ() | |
| Dim fileName As String = "MulticoloredNumberedList.doc" | |
| ' Load the template document. | |
| Dim doc As New Document(dataDir & fileName) | |
| ' Create a Reporting Engine. | |
| Dim engine As New ReportingEngine() | |
| ' Execute the build report. | |
| engine.BuildReport(doc, Common.GetClients(), "clients") | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| ' Save the finished document to disk. | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_LINQ() | |
| Dim fileName As String = "NumberedList.doc" | |
| ' Load the template document. | |
| Dim doc As New Document(dataDir & fileName) | |
| ' Create a Reporting Engine. | |
| Dim engine As New ReportingEngine() | |
| ' Execute the build report. | |
| engine.BuildReport(doc, Common.GetClients(), "clients") | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| ' Save the finished document to disk. | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_LINQ() | |
| Dim fileName As String = "PieChart.docx" | |
| ' Load the template document. | |
| Dim doc As New Document(dataDir & fileName) | |
| ' Create a Reporting Engine. | |
| Dim engine As New ReportingEngine() | |
| ' Execute the build report. | |
| engine.BuildReport(doc, Common.GetManagers(), "managers") | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| ' Save the finished document to disk. | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_LINQ() | |
| Dim fileName As String = "ScatterChart.docx" | |
| ' Load the template document. | |
| Dim doc As New Document(dataDir & fileName) | |
| ' Create a Reporting Engine. | |
| Dim engine As New ReportingEngine() | |
| ' Execute the build report. | |
| engine.BuildReport(doc, Common.GetContracts(), "contracts") | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| ' Save the finished document to disk. | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Public Class Sender | |
| Public Property Name() As [String] | |
| Get | |
| Return m_Name | |
| End Get | |
| Set(value As [String]) | |
| m_Name = value | |
| End Set | |
| End Property | |
| Private m_Name As [String] | |
| Public Property Message() As [String] | |
| Get | |
| Return m_Message | |
| End Get | |
| Set(value As [String]) | |
| m_Message = value | |
| End Set | |
| End Property | |
| Private m_Message As [String] | |
| End Class |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_LINQ() | |
| Dim fileName As String = "SingleRow.doc" | |
| ' Load the template document. | |
| Dim doc As New Document(dataDir & fileName) | |
| ' Load the photo and read all bytes. | |
| Dim imgdata As Byte() = System.IO.File.ReadAllBytes(dataDir & Convert.ToString("photo.png")) | |
| ' Create a Reporting Engine. | |
| Dim engine As New ReportingEngine() | |
| ' Execute the build report. | |
| engine.BuildReport(doc, Common.GetManager(), "manager") | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| ' Save the finished document to disk. | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_LoadingAndSaving() | |
| Dim doc As New Document(dataDir & Convert.ToString("Test File (doc).doc")) | |
| For Each signature As DigitalSignature In doc.DigitalSignatures | |
| Console.WriteLine("*** Signature Found ***") | |
| Console.WriteLine("Is valid: " + signature.IsValid.ToString()) | |
| Console.WriteLine("Reason for signing: " + signature.Comments.ToString()) | |
| ' This property is available in MS Word documents only. | |
| Console.WriteLine("Time of signing: " + signature.SignTime.ToString()) | |
| Console.WriteLine("Subject name: " + signature.CertificateHolder.Certificate.SubjectName.Name) | |
| Console.WriteLine("Issuer name: " + signature.CertificateHolder.Certificate.IssuerName.Name) | |
| Console.WriteLine() | |
| Next |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_LoadingAndSaving() | |
| Dim supportedDir As String = dataDir & "OutSupported" | |
| Dim unknownDir As String = dataDir & "OutUnknown" | |
| Dim encryptedDir As String = dataDir & "OutEncrypted" | |
| Dim pre97Dir As String = dataDir & "OutPre97" | |
| ' Create the directories if they do not already exist | |
| If Directory.Exists(supportedDir) = False Then | |
| Directory.CreateDirectory(supportedDir) | |
| End If | |
| If Directory.Exists(unknownDir) = False Then | |
| Directory.CreateDirectory(unknownDir) | |
| End If | |
| If Directory.Exists(encryptedDir) = False Then | |
| Directory.CreateDirectory(encryptedDir) | |
| End If | |
| If Directory.Exists(pre97Dir) = False Then | |
| Directory.CreateDirectory(pre97Dir) | |
| End If | |
| Dim fileList() As String = Directory.GetFiles(dataDir) | |
| For Each fileName As String In fileList | |
| ' Extract and display the file name without the path. | |
| Dim nameOnly As String = Path.GetFileName(fileName) | |
| Console.Write(nameOnly) | |
| ' Check the file format and move the file to the appropriate folder. | |
| Dim info As FileFormatInfo = FileFormatUtil.DetectFileFormat(fileName) | |
| ' Display the document type. | |
| Select Case info.LoadFormat | |
| Case LoadFormat.Doc | |
| Console.WriteLine(Constants.vbTab & "Microsoft Word 97-2003 document.") | |
| Case LoadFormat.Dot | |
| Console.WriteLine(Constants.vbTab & "Microsoft Word 97-2003 template.") | |
| Case LoadFormat.Docx | |
| Console.WriteLine(Constants.vbTab & "Office Open XML WordprocessingML Macro-Free Document.") | |
| Case LoadFormat.Docm | |
| Console.WriteLine(Constants.vbTab & "Office Open XML WordprocessingML Macro-Enabled Document.") | |
| Case LoadFormat.Dotx | |
| Console.WriteLine(Constants.vbTab & "Office Open XML WordprocessingML Macro-Free Template.") | |
| Case LoadFormat.Dotm | |
| Console.WriteLine(Constants.vbTab & "Office Open XML WordprocessingML Macro-Enabled Template.") | |
| Case LoadFormat.FlatOpc | |
| Console.WriteLine(Constants.vbTab & "Flat OPC document.") | |
| Case LoadFormat.Rtf | |
| Console.WriteLine(Constants.vbTab & "RTF format.") | |
| Case LoadFormat.WordML | |
| Console.WriteLine(Constants.vbTab & "Microsoft Word 2003 WordprocessingML format.") | |
| Case LoadFormat.Html | |
| Console.WriteLine(Constants.vbTab & "HTML format.") | |
| Case LoadFormat.Mhtml | |
| Console.WriteLine(Constants.vbTab & "MHTML (Web archive) format.") | |
| Case LoadFormat.Odt | |
| Console.WriteLine(Constants.vbTab & "OpenDocument Text.") | |
| Case LoadFormat.Ott | |
| Console.WriteLine(Constants.vbTab & "OpenDocument Text Template.") | |
| Case LoadFormat.DocPreWord60 | |
| Console.WriteLine(Constants.vbTab & "MS Word 6 or Word 95 format.") | |
| Case Else | |
| Console.WriteLine(Constants.vbTab & "Unknown format.") | |
| End Select | |
| ' Now copy the document into the appropriate folder. | |
| If info.IsEncrypted Then | |
| Console.WriteLine(Constants.vbTab & "An encrypted document.") | |
| File.Copy(fileName, Path.Combine(encryptedDir, nameOnly), True) | |
| Else | |
| Select Case info.LoadFormat | |
| Case LoadFormat.DocPreWord60 | |
| File.Copy(fileName, Path.Combine(pre97Dir, nameOnly), True) | |
| Case LoadFormat.Unknown | |
| File.Copy(fileName, Path.Combine(unknownDir, nameOnly), True) | |
| Case Else | |
| File.Copy(fileName, Path.Combine(supportedDir, nameOnly), True) | |
| End Select | |
| End If | |
| Next fileName |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' Check the file format and move the file to the appropriate folder. | |
| Dim info As FileFormatInfo = FileFormatUtil.DetectFileFormat(fileName) | |
| ' Display the document type. | |
| Select Case info.LoadFormat | |
| Case LoadFormat.Doc | |
| Console.WriteLine(Constants.vbTab & "Microsoft Word 97-2003 document.") | |
| Case LoadFormat.Dot | |
| Console.WriteLine(Constants.vbTab & "Microsoft Word 97-2003 template.") | |
| Case LoadFormat.Docx | |
| Console.WriteLine(Constants.vbTab & "Office Open XML WordprocessingML Macro-Free Document.") | |
| Case LoadFormat.Docm | |
| Console.WriteLine(Constants.vbTab & "Office Open XML WordprocessingML Macro-Enabled Document.") | |
| Case LoadFormat.Dotx | |
| Console.WriteLine(Constants.vbTab & "Office Open XML WordprocessingML Macro-Free Template.") | |
| Case LoadFormat.Dotm | |
| Console.WriteLine(Constants.vbTab & "Office Open XML WordprocessingML Macro-Enabled Template.") | |
| Case LoadFormat.FlatOpc | |
| Console.WriteLine(Constants.vbTab & "Flat OPC document.") | |
| Case LoadFormat.Rtf | |
| Console.WriteLine(Constants.vbTab & "RTF format.") | |
| Case LoadFormat.WordML | |
| Console.WriteLine(Constants.vbTab & "Microsoft Word 2003 WordprocessingML format.") | |
| Case LoadFormat.Html | |
| Console.WriteLine(Constants.vbTab & "HTML format.") | |
| Case LoadFormat.Mhtml | |
| Console.WriteLine(Constants.vbTab & "MHTML (Web archive) format.") | |
| Case LoadFormat.Odt | |
| Console.WriteLine(Constants.vbTab & "OpenDocument Text.") | |
| Case LoadFormat.Ott | |
| Console.WriteLine(Constants.vbTab & "OpenDocument Text Template.") | |
| Case LoadFormat.DocPreWord60 | |
| Console.WriteLine(Constants.vbTab & "MS Word 6 or Word 95 format.") | |
| Case Else | |
| Console.WriteLine(Constants.vbTab & "Unknown format.") | |
| End Select |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim fileList() As String = Directory.GetFiles(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_LoadingAndSaving() | |
| ' Load the document from disk. | |
| Dim doc As New Document(dataDir & Convert.ToString("Test File (doc).doc")) | |
| ' Create a new memory stream. | |
| Dim outStream As New MemoryStream() | |
| ' Save the document to stream. | |
| doc.Save(outStream, SaveFormat.Docx) | |
| ' Convert the document to byte form. | |
| Dim docBytes As Byte() = outStream.ToArray() | |
| ' The bytes are now ready to be stored/transmitted. | |
| ' Now reverse the steps to load the bytes back into a document object. | |
| Dim inStream As New MemoryStream(docBytes) | |
| ' Load the stream into a new document object. | |
| Dim loadDoc As New Document(inStream) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_LoadingAndSaving() | |
| ' Load the document from disk. | |
| Dim doc As New Document(dataDir & Convert.ToString("Document.EpubConversion.doc")) | |
| ' Create a new instance of HtmlSaveOptions. This object allows us to set options that control | |
| ' How the output document is saved. | |
| Dim saveOptions As New HtmlSaveOptions() | |
| ' Specify the desired encoding. | |
| saveOptions.Encoding = System.Text.Encoding.UTF8 | |
| ' Specify at what elements to split the internal HTML at. This creates a new HTML within the EPUB | |
| ' Which allows you to limit the size of each HTML part. This is useful for readers which cannot read | |
| ' HTML files greater than a certain size e.g 300kb. | |
| saveOptions.DocumentSplitCriteria = DocumentSplitCriteria.HeadingParagraph | |
| ' Specify that we want to export document properties. | |
| saveOptions.ExportDocumentProperties = True | |
| ' Specify that we want to save in EPUB format. | |
| saveOptions.SaveFormat = SaveFormat.Epub | |
| ' Export the document as an EPUB file. | |
| doc.Save(dataDir & Convert.ToString("Document.EpubConversion_out.epub"), saveOptions) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Public Shared Sub ConvertDocumentToEPUBUsingDefaultSaveOption() | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_LoadingAndSaving() | |
| ' Load the document from disk. | |
| Dim doc As New Document(dataDir & Convert.ToString("Document.EpubConversion.doc")) | |
| ' Save the document in EPUB format. | |
| doc.Save(dataDir & Convert.ToString("Document.EpubConversionUsingDefaultSaveOption_out.epub")) | |
| End Sub |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_LoadingAndSaving() | |
| ' Load the document from disk. | |
| Dim doc As New Document(dataDir & Convert.ToString("Test File (doc).doc")) | |
| Dim options As New HtmlSaveOptions() | |
| ' HtmlSaveOptions.ExportRoundtripInformation property specifies | |
| ' Whether to write the roundtrip information when saving to HTML, MHTML or EPUB. | |
| ' Default value is true for HTML and false for MHTML and EPUB. | |
| options.ExportRoundtripInformation = True | |
| doc.Save(dataDir & Convert.ToString("ExportRoundtripInformation_out.html"), options) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_LoadingAndSaving() | |
| ' Initialize a Document. | |
| Dim doc As New Document() | |
| ' Use a document builder to add content to the document. | |
| Dim builder As New DocumentBuilder(doc) | |
| builder.Writeln("Hello World!") | |
| dataDir = dataDir & Convert.ToString("CreateDocument_out.docx") | |
| ' Save the document to disk. | |
| doc.Save(dataDir) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_LoadingAndSaving() | |
| ' The path to the document which is to be processed. | |
| Dim filePath As String = dataDir & Convert.ToString("Document.Signed.docx") | |
| Dim info As FileFormatInfo = FileFormatUtil.DetectFileFormat(filePath) | |
| If info.HasDigitalSignature Then | |
| Console.WriteLine(String.Format("Document {0} has digital signatures, they will be lost if you open/save this document with Aspose.Words.", Path.GetFileName(filePath))) | |
| End If |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_LoadingAndSaving() | |
| ' Create a simple document from scratch. | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| builder.Writeln("Test Signed PDF.") | |
| ' Load the certificate from disk. | |
| ' The other constructor overloads can be used to load certificates from different locations. | |
| Dim cert As New X509Certificate2(dataDir & Convert.ToString("signature.pfx"), "signature") | |
| ' Pass the certificate and details to the save options class to sign with. | |
| Dim options As New PdfSaveOptions() | |
| options.DigitalSignatureDetails = New PdfDigitalSignatureDetails() | |
| dataDir = dataDir & Convert.ToString("Document.Signed_out.pdf") | |
| ' Save the document as PDF. | |
| doc.Save(dataDir) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Imports System.Security.Cryptography.X509Certificates |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_LoadingAndSaving() | |
| ' Create a simple document from scratch. | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| builder.Writeln("Test Signed PDF.") | |
| Dim options As New PdfSaveOptions() | |
| options.DigitalSignatureDetails = New PdfDigitalSignatureDetails(CertificateHolder.Create(dataDir & Convert.ToString("CioSrv1.pfx"), "cinD96..arellA"), "reason", "location", DateTime.Now) | |
| doc.Save(dataDir & Convert.ToString("DigitallySignedPdfUsingCertificateHolder.Signed_out.pdf"), options) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_QuickStart() | |
| ' Load the document from disk. | |
| Dim doc As New Document(dataDir & "Template.doc") | |
| dataDir = dataDir & "Template_out.pdf" | |
| ' Save the document in PDF format. | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_LoadingAndSaving() | |
| Dim fileName As String = "Document.doc" | |
| Dim doc As New Document(dataDir & fileName) | |
| Dim saveOptions As New HtmlSaveOptions() | |
| saveOptions.ExportFontResources = True | |
| saveOptions.ExportFontsAsBase64 = True | |
| dataDir = dataDir & Convert.ToString("ExportFontsAsBase64_out.html") | |
| doc.Save(dataDir, saveOptions) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_LoadingAndSaving() | |
| Dim fileName As String = "Document.doc" | |
| Dim doc As New Document(dataDir & fileName) | |
| Dim saveOptions As New HtmlSaveOptions() | |
| saveOptions.CssStyleSheetType = CssStyleSheetType.External | |
| saveOptions.ExportFontResources = True | |
| saveOptions.ResourceFolder = dataDir & Convert.ToString("\Resources") | |
| saveOptions.ResourceFolderAlias = "http://example.com/resources" | |
| doc.Save(dataDir & Convert.ToString("ExportResourcesUsingHtmlSaveOptions.html"), saveOptions) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Public Class ImageLoadingWithCredentialsHandler | |
| Public Sub New() | |
| mWebClient = New WebClient() | |
| End Sub | |
| Public Function ResourceLoading(ByVal args As ResourceLoadingArgs) As ResourceLoadingAction | |
| If args.ResourceType = ResourceType.Image Then | |
| Dim uri As Uri = New Uri(args.Uri) | |
| If uri.Host = "www.aspose.com" Then | |
| mWebClient.Credentials = New NetworkCredential("User1", "akjdlsfkjs") | |
| Else | |
| mWebClient.Credentials = New NetworkCredential("SomeOtherUserID", "wiurlnlvs") | |
| End If | |
| ' Download the bytes from the location referenced by the URI. | |
| Dim imageBytes As Byte() = mWebClient.DownloadData(args.Uri) | |
| args.SetData(imageBytes) | |
| Return ResourceLoadingAction.UserProvided | |
| Else | |
| Return ResourceLoadingAction.Default | |
| End If | |
| End Function | |
| Private mWebClient As WebClient | |
| End Class |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' Create Aspose.Words.Document and DocumentBuilder. | |
| ' The builder makes it simple to add content to the document. | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| ' Read the image from file, ensure it is disposed. | |
| Using image__1 As Image = Image.FromFile(inputFileName) | |
| ' Find which dimension the frames in this image represent. For example | |
| ' The frames of a BMP or TIFF are "page dimension" whereas frames of a GIF image are "time dimension". | |
| Dim dimension As New FrameDimension(image__1.FrameDimensionsList(0)) | |
| ' Get the number of frames in the image. | |
| Dim framesCount As Integer = image__1.GetFrameCount(dimension) | |
| ' Loop through all frames. | |
| For frameIdx As Integer = 0 To framesCount - 1 | |
| ' Insert a section break before each new page, in case of a multi-frame TIFF. | |
| If frameIdx <> 0 Then | |
| builder.InsertBreak(BreakType.SectionBreakNewPage) | |
| End If | |
| ' Select active frame. | |
| image__1.SelectActiveFrame(dimension, frameIdx) | |
| ' We want the size of the page to be the same as the size of the image. | |
| ' Convert pixels to points to size the page to the actual image size. | |
| Dim ps As PageSetup = builder.PageSetup | |
| ps.PageWidth = ConvertUtil.PixelToPoint(image__1.Width, image__1.HorizontalResolution) | |
| ps.PageHeight = ConvertUtil.PixelToPoint(image__1.Height, image__1.VerticalResolution) | |
| ' Insert the image into the document and position it at the top left corner of the page. | |
| builder.InsertImage(image__1, RelativeHorizontalPosition.Page, 0, RelativeVerticalPosition.Page, 0, ps.PageWidth, _ | |
| ps.PageHeight, WrapType.None) | |
| Next | |
| End Using | |
| ' Save the document to PDF. | |
| doc.Save(outputFileName) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_LoadingAndSaving() | |
| ConvertImageToPdf(dataDir & Convert.ToString("Test.jpg"), dataDir & Convert.ToString("TestJpg_out.pdf")) | |
| ConvertImageToPdf(dataDir & Convert.ToString("Test.png"), dataDir & Convert.ToString("TestPng_out.pdf")) | |
| ConvertImageToPdf(dataDir & Convert.ToString("Test.wmf"), dataDir & Convert.ToString("TestWmf_out.pdf")) | |
| ConvertImageToPdf(dataDir & Convert.ToString("Test.tiff"), dataDir & Convert.ToString("TestTiff_out.pdf")) | |
| ConvertImageToPdf(dataDir & Convert.ToString("Test.gif"), dataDir & Convert.ToString("TestGif_out.pdf")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Public Shared Sub DeleteFromDatabase(fileName As String, mConnection As OleDbConnection) | |
| ' Create the SQL command. | |
| Dim commandString As String = (Convert.ToString("DELETE * FROM Documents WHERE FileName='") & fileName) + "'" | |
| Dim command As New OleDbCommand(commandString, mConnection) | |
| ' Delete the record. | |
| command.ExecuteNonQuery() | |
| End Sub |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim dbName As String = "" | |
| ' Open a database connection. | |
| Dim connString As String = Convert.ToString("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + RunExamples.GetDataDir_Database()) & dbName | |
| Dim mConnection As New OleDbConnection(connString) | |
| mConnection.Open() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' Store the document to the database. | |
| StoreToDatabase(doc, mConnection) | |
| ' Read the document from the database and store the file to disk. | |
| Dim dbDoc As Document = ReadFromDatabase(fileName, mConnection) | |
| ' Save the retrieved document to disk. | |
| Dim newFileName As String = Path.GetFileNameWithoutExtension(fileName) + " from DB" + Path.GetExtension(fileName) | |
| dbDoc.Save(dataDir & newFileName) | |
| ' Delete the document from the database. | |
| DeleteFromDatabase(fileName, mConnection) | |
| ' Close the connection to the database. | |
| mConnection.Close() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Public Shared Function ReadFromDatabase(fileName As String, mConnection As OleDbConnection) As Document | |
| ' Create the SQL command. | |
| Dim commandString As String = (Convert.ToString("SELECT * FROM Documents WHERE FileName='") & fileName) + "'" | |
| Dim command As New OleDbCommand(commandString, mConnection) | |
| ' Create the data adapter. | |
| Dim adapter As New OleDbDataAdapter(command) | |
| ' Fill the results from the database into a DataTable. | |
| Dim dataTable As New DataTable() | |
| adapter.Fill(dataTable) | |
| ' Check there was a matching record found from the database and throw an exception if no record was found. | |
| If dataTable.Rows.Count = 0 Then | |
| Throw New ArgumentException(String.Format("Could not find any record matching the document ""{0}"" in the database.", fileName)) | |
| End If | |
| ' The document is stored in byte form in the FileContent column. | |
| ' Retrieve these bytes of the first matching record to a new buffer. | |
| Dim buffer As Byte() = DirectCast(dataTable.Rows(0)("FileContent"), Byte()) | |
| ' Wrap the bytes from the buffer into a new MemoryStream object. | |
| Dim newStream As New MemoryStream(buffer) | |
| ' Read the document from the stream. | |
| Dim doc As New Document(newStream) | |
| ' Return the retrieved document. | |
| Return doc | |
| End Function |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Public Shared Sub StoreToDatabase(doc As Document, mConnection As OleDbConnection) | |
| ' Save the document to a MemoryStream object. | |
| Dim stream As New MemoryStream() | |
| doc.Save(stream, SaveFormat.Doc) | |
| ' Get the filename from the document. | |
| Dim fileName As String = Path.GetFileName(doc.OriginalFileName) | |
| ' Create the SQL command. | |
| Dim commandString As String = (Convert.ToString("INSERT INTO Documents (FileName, FileContent) VALUES('") & fileName) + "', @Doc)" | |
| Dim command As New OleDbCommand(commandString, mConnection) | |
| ' Add the @Doc parameter. | |
| command.Parameters.AddWithValue("Doc", stream.ToArray()) | |
| ' Write the document to the database. | |
| command.ExecuteNonQuery() | |
| End Sub |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_QuickStart() | |
| Dim fileName As String = "Document.doc" | |
| ' Load the document from the absolute path on disk. | |
| Dim doc As New Document(dataDir & fileName) | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| ' Save the document as DOCX document."); | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_QuickStart() | |
| Dim fileName As String = "Document.doc" | |
| ' Load the document from the absolute path on disk. | |
| Dim doc As New Document(dataDir & fileName) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_QuickStart() | |
| ' Open the stream. Read only access is enough for Aspose.Words to load a document. | |
| Dim stream As Stream = File.OpenRead(dataDir & "Document.doc") | |
| ' Load the entire document into memory. | |
| Dim doc As New Document(stream) | |
| ' You can close the stream now, it is no longer needed because the document is in memory. | |
| stream.Close() | |
| ' ... do something with the document | |
| ' Convert the document to a different format and save to stream. | |
| Dim dstStream As New MemoryStream() | |
| doc.Save(dstStream, SaveFormat.Rtf) | |
| ' Rewind the stream position back to zero so it is ready for the next reader. | |
| dstStream.Position = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_QuickStart() | |
| ' Open the stream. Read only access is enough for Aspose.Words to load a document. | |
| Dim stream As Stream = File.OpenRead(dataDir & "Document.doc") | |
| ' Load the entire document into memory. | |
| Dim doc As New Document(stream) | |
| ' You can close the stream now, it is no longer needed because the document is in memory. | |
| stream.Close() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_LoadingAndSaving() | |
| ' The encoding of the text file is automatically detected. | |
| Dim doc As New Document(dataDir & Convert.ToString("LoadTxt.txt")) | |
| dataDir = dataDir & "LoadTxt_out.docx" | |
| ' Save as any Aspose.Words supported format, such as DOCX. | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_LoadingAndSaving() | |
| ' Loads encrypted document. | |
| Dim doc As New Document(dataDir & Convert.ToString("LoadEncrypted.docx"), New LoadOptions("aspose")) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_LoadingAndSaving() | |
| Dim doc As New Document(dataDir & Convert.ToString("Document.doc")) | |
| dataDir = dataDir & Convert.ToString("Document.ConvertToTxt_out.txt") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_LoadingAndSaving() | |
| Dim doc As New Document(dataDir & Convert.ToString("Document.doc")) | |
| dataDir = dataDir & Convert.ToString("Report_out.doc") | |
| ' If this method overload is causing a compiler error then you are using the Client Profile DLL whereas | |
| ' The Aspose.Words .NET 2.0 DLL must be used instead. | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_LoadingAndSaving() | |
| Dim fileName As String = "TestFile RenderShape.docx" | |
| Dim doc As New Document(dataDir & fileName) | |
| ' This is the directory we want the exported images to be saved to. | |
| Dim imagesDir As String = Path.Combine(dataDir, "Images") | |
| ' The folder specified needs to exist and should be empty. | |
| If Directory.Exists(imagesDir) Then | |
| Directory.Delete(imagesDir, True) | |
| End If | |
| Directory.CreateDirectory(imagesDir) | |
| ' Set an option to export form fields as plain text, not as HTML input elements. | |
| Dim options As New HtmlSaveOptions(SaveFormat.Html) | |
| options.ExportTextInputFormFieldAsText = True | |
| options.ImagesFolder = imagesDir | |
| dataDir = dataDir & Convert.ToString("Document.SaveWithOptions_out.html") | |
| doc.Save(dataDir, options) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_MailMergeAndReporting() | |
| Dim fileName As String = "TestFile.doc" | |
| ' Open the document. | |
| Dim doc As New Document(dataDir & fileName) | |
| ' Create a data source which has some data missing. | |
| ' This will result in some regions that are merged and some that remain after executing mail merge. | |
| Dim data As DataSet = GetDataSource() | |
| ' Make sure that we have not set the removal of any unused regions as we will handle them manually. | |
| ' We achieve this by removing the RemoveUnusedRegions flag from the cleanup options by using the AND and NOT bitwise operators. | |
| doc.MailMerge.CleanupOptions = doc.MailMerge.CleanupOptions And Not MailMergeCleanupOptions.RemoveUnusedRegions | |
| ' Execute mail merge. Some regions will be merged with data, others left unmerged. | |
| doc.MailMerge.ExecuteWithRegions(data) | |
| ' The regions which contained data now would of been merged. Any regions which had no data and were | |
| ' Not merged will still remain in the document. | |
| Dim mergedDoc As Document = doc.Clone() ' ExSkip | |
| ' Apply logic to each unused region left in the document using the logic set out in the handler. | |
| ' The handler class must implement the IFieldMergingCallback interface. | |
| ExecuteCustomLogicOnEmptyRegions(doc, New EmptyRegionsHandler()) | |
| ' Save the output document to disk. | |
| doc.Save(dataDir & "TestFile.CustomLogicEmptyRegions1_out.doc") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim regions As New ArrayList() | |
| regions.Add("ContactDetails") | |
| ExecuteCustomLogicOnEmptyRegions(doc, New EmptyRegionsHandler(), regions) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| dataSet.Relations.Add(New DataRelation("OrderToItem", orderTable.Columns("Order_Id"), itemTable.Columns("Order_Id"))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Private Shared Function CreateDataSourceFromDocumentRegions(ByVal doc As Document, ByVal regionsList As ArrayList) As DataSet | |
| Const tableStartMarker As String = "TableStart:" | |
| Dim dataSet As New DataSet() | |
| Dim tableName As String = Nothing | |
| For Each fieldName As String In doc.MailMerge.GetFieldNames() | |
| If fieldName.Contains(tableStartMarker) Then | |
| tableName = fieldName.Substring(tableStartMarker.Length) | |
| ElseIf tableName IsNot Nothing Then | |
| ' Only add the table name as a new DataTable if it doesn' T already exists in the DataSet. | |
| If dataSet.Tables(tableName) Is Nothing Then | |
| Dim table As New DataTable(tableName) | |
| table.Columns.Add(fieldName) | |
| ' We only need to add the first field for the handler to be called for the fields in the region. | |
| If regionsList Is Nothing OrElse regionsList.Contains(tableName) Then | |
| table.Rows.Add("FirstField") | |
| End If | |
| dataSet.Tables.Add(table) | |
| End If | |
| tableName = Nothing | |
| End If | |
| Next fieldName | |
| Return dataSet | |
| End Function |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| dataSet.Relations.Add(New DataRelation("OrderToItem", orderTable.Columns("Order_Id"), itemTable.Columns("Order_Id"), False)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Public Class EmptyRegionsHandler | |
| Implements IFieldMergingCallback | |
| ''' <summary> | |
| ''' Called for each field belonging to an unmerged region in the document. | |
| ''' </summary> | |
| Public Sub FieldMerging(ByVal args As FieldMergingArgs) Implements IFieldMergingCallback.FieldMerging | |
| ' Change the text of each field of the ContactDetails region individually. | |
| If args.TableName = "ContactDetails" Then | |
| ' Set the text of the field based off the field name. | |
| If args.FieldName = "Name" Then | |
| args.Text = "(No details found)" | |
| ElseIf args.FieldName = "Number" Then | |
| args.Text = "(N/A)" | |
| End If | |
| End If | |
| ' Remove the entire table of the Suppliers region. Also check if the previous paragraph | |
| ' Before the table is a heading paragraph and if so remove that too. | |
| If args.TableName = "Suppliers" Then | |
| Dim table As Table = CType(args.Field.Start.GetAncestor(NodeType.Table), Table) | |
| ' Check if the table has been removed from the document already. | |
| If table.ParentNode IsNot Nothing Then | |
| ' Try to find the paragraph which precedes the table before the table is removed from the document. | |
| If table.PreviousSibling IsNot Nothing AndAlso table.PreviousSibling.NodeType = NodeType.Paragraph Then | |
| Dim previousPara As Paragraph = CType(table.PreviousSibling, Paragraph) | |
| If IsHeadingParagraph(previousPara) Then | |
| previousPara.Remove() | |
| End If | |
| End If | |
| table.Remove() | |
| End If | |
| End If | |
| End Sub | |
| ''' <summary> | |
| ''' Returns true if the paragraph uses any Heading style e.g Heading 1 to Heading 9 | |
| ''' </summary> | |
| Private Function IsHeadingParagraph(ByVal para As Paragraph) As Boolean | |
| Return (para.ParagraphFormat.StyleIdentifier >= StyleIdentifier.Heading1 AndAlso para.ParagraphFormat.StyleIdentifier <= StyleIdentifier.Heading9) | |
| End Function | |
| Public Sub ImageFieldMerging(ByVal args As ImageFieldMergingArgs) Implements IFieldMergingCallback.ImageFieldMerging | |
| ' Do Nothing | |
| End Sub | |
| End Class |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Public Shared Sub ExecuteCustomLogicOnEmptyRegions(ByVal doc As Document, ByVal handler As IFieldMergingCallback) | |
| ExecuteCustomLogicOnEmptyRegions(doc, handler, Nothing) ' Pass null to handle all regions found in the document. | |
| End Sub | |
| Public Shared Sub ExecuteCustomLogicOnEmptyRegions(ByVal doc As Document, ByVal handler As IFieldMergingCallback, ByVal regionsList As ArrayList) | |
| ' Certain regions can be skipped from applying logic to by not adding the table name inside the CreateEmptyDataSource method. | |
| ' Enable this cleanup option so any regions which are not handled by the user' S logic are removed automatically. | |
| doc.MailMerge.CleanupOptions = MailMergeCleanupOptions.RemoveUnusedRegions | |
| ' Set the user' S handler which is called for each unmerged region. | |
| doc.MailMerge.FieldMergingCallback = handler | |
| ' Execute mail merge using the dummy dataset. The dummy data source contains the table names of | |
| ' Each unmerged region in the document (excluding ones that the user may have specified to be skipped). This will allow the handler | |
| ' To be called for each field in the unmerged regions. | |
| doc.MailMerge.ExecuteWithRegions(CreateDataSourceFromDocumentRegions(doc, regionsList)) | |
| End Sub |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' Replace the unused region in the table with a "no records" message and merge all cells into one. | |
| If args.TableName = "Suppliers" Then | |
| If CStr(args.FieldValue) Is "FirstField" Then | |
| ' We will use the first paragraph to display our message. Make it centered within the table. The other fields in other cells | |
| ' Within the table will be merged and won' T be displayed so we don' T need to do anything else with them. | |
| parentParagraph.ParagraphFormat.Alignment = ParagraphAlignment.Center | |
| args.Text = "No records to display" | |
| End If | |
| ' Merge the cells of the table together. | |
| Dim cell As Cell = CType(parentParagraph.GetAncestor(NodeType.Cell), Cell) | |
| If cell IsNot Nothing Then | |
| If cell.IsFirstCell Then | |
| cell.CellFormat.HorizontalMerge = CellMerge.First ' If this cell is the first cell in the table then the merge is started using "CellMerge.First". | |
| Else | |
| cell.CellFormat.HorizontalMerge = CellMerge.Previous ' Otherwise the merge is continued using "CellMerge.Previous". | |
| End If | |
| End If | |
| End If |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' Store the parent paragraph of the current field for easy access. | |
| Dim parentParagraph As Paragraph = args.Field.Start.ParentParagraph | |
| ' Define the logic to be used when the ContactDetails region is encountered. | |
| ' The region is removed and replaced with a single line of text stating that there are no records. | |
| If args.TableName = "ContactDetails" Then | |
| ' Called for the first field encountered in a region. This can be used to execute logic on the first field | |
| ' In the region without needing to hard code the field name. Often the base logic is applied to the first field and | |
| ' Different logic for other fields. The rest of the fields in the region will have a null FieldValue. | |
| If CStr(args.FieldValue) Is "FirstField" Then | |
| ' Remove the "Name:" tag from the start of the paragraph | |
| parentParagraph.Range.Replace("Name:", String.Empty, New FindReplaceOptions(FindReplaceDirection.Forward)) | |
| ' Set the text of the first field to display a message stating that there are no records. | |
| args.Text = "No records to display" | |
| Else | |
| ' We have already inserted our message in the paragraph belonging to the first field. The other paragraphs in the region | |
| ' Will still remain so we want to remove these. A check is added to ensure that the paragraph has not already been removed. | |
| ' Which may happen if more than one field is included in a paragraph. | |
| If parentParagraph.ParentNode IsNot Nothing Then | |
| parentParagraph.Remove() | |
| End If | |
| End If | |
| End If |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_MailMergeAndReporting() | |
| ' Open an existing document. | |
| Dim doc As New Document(dataDir & Convert.ToString("MailMerge.ExecuteArray.doc")) | |
| ' Trim trailing and leading whitespaces mail merge values | |
| doc.MailMerge.TrimWhitespaces = False | |
| ' Fill the fields in the document with user data. | |
| doc.MailMerge.Execute(New String() {"FullName", "Company", "Address", "Address2", "City"}, New Object() {"James Bond", "MI5 Headquarters", "Milbank", "", "London"}) | |
| dataDir = dataDir & Convert.ToString("MailMerge.ExecuteArray_out.doc") | |
| ' Send the document in Word format to the client browser with an option to save to disk or open inside the current browser. | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_MailMergeAndReporting() | |
| Dim fileName As String = "MailMerge.ExecuteWithRegions.doc" | |
| Dim doc As New Document(dataDir & fileName) | |
| Dim orderId As Integer = 10444 | |
| ' Perform several mail merge operations populating only part of the document each time. | |
| ' Use DataTable as a data source. | |
| Dim orderTable As DataTable = GetTestOrder(orderId) | |
| doc.MailMerge.ExecuteWithRegions(orderTable) | |
| ' Instead of using DataTable you can create a DataView for custom sort or filter and then mail merge. | |
| Dim orderDetailsView As New DataView(GetTestOrderDetails(orderId)) | |
| orderDetailsView.Sort = "ExtendedPrice DESC" | |
| doc.MailMerge.ExecuteWithRegions(orderDetailsView) | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Private Shared Function GetTestOrder(orderId As Integer) As DataTable | |
| Dim table As DataTable = ExecuteDataTable(String.Format("SELECT * FROM AsposeWordOrders WHERE OrderId = {0}", orderId)) | |
| table.TableName = "Orders" | |
| Return table | |
| End Function | |
| Private Shared Function GetTestOrderDetails(orderId As Integer) As DataTable | |
| Dim table As DataTable = ExecuteDataTable(String.Format("SELECT * FROM AsposeWordOrderDetails WHERE OrderId = {0} ORDER BY ProductID", orderId)) | |
| table.TableName = "OrderDetails" | |
| Return table | |
| End Function | |
| ''' <summary> | |
| ''' Utility function that creates a connection, command, | |
| ''' Executes the command and return the result in a DataTable. | |
| ''' </summary> | |
| Private Shared Function ExecuteDataTable(commandText As String) As DataTable | |
| ' Open the database connection. | |
| Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + RunExamples.GetDataDir_Database() + "Northwind.mdb" | |
| Dim conn As New OleDbConnection(connString) | |
| conn.Open() | |
| ' Create and execute a command. | |
| Dim cmd As New OleDbCommand(commandText, conn) | |
| Dim da As New OleDbDataAdapter(cmd) | |
| Dim table As New DataTable() | |
| da.Fill(table) | |
| ' Close the database. | |
| conn.Close() | |
| Return table | |
| End Function |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim fileName As String = "TestFile.doc" | |
| ' Open the template document. | |
| Dim doc As New Document(dataDir & fileName) | |
| ' Fill the document with data from our data sources. | |
| ' Using mail merge regions for populating the order items table is required | |
| ' Because it allows the region to be repeated in the document for each order item. | |
| doc.MailMerge.ExecuteWithRegions(orderItemsDataSource) | |
| ' The standard mail merge without regions is used for the delivery address. | |
| doc.MailMerge.Execute(deliveryDataSource) | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| ' Save the output document. | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim orderItems = From order In orderXml.Descendants("Item") _ | |
| Select New With {Key .PartNumber = CStr(order.Attribute("PartNumber")), Key .ProductName = CStr(order.Element("ProductName")), Key .Quantity = CStr(order.Element("Quantity")), Key .USPrice = CStr(order.Element("USPrice")), Key .Comment = CStr(order.Element("Comment")), Key .ShipDate = CStr(order.Element("ShipDate"))} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' Query the delivery (shipping) address using LINQ. | |
| Dim deliveryAddress = From delivery In orderXml.Elements("Address") _ | |
| Where (CStr(delivery.Attribute("Type")) = "Shipping") _ | |
| ' Select New With {Key .Name = CStr(delivery.Element("Name")), Key .Country = CStr(delivery.Element("Country")), Key .Zip = CStr(delivery.Element("Zip")), Key .State = CStr(delivery.Element("State")), Key .City = CStr(delivery.Element("City")), Key .Street = CStr(delivery.Element("Street"))} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Public Class MyMailMergeDataSource | |
| Implements IMailMergeDataSource |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Public Sub New(ByVal data As IEnumerable) | |
| mEnumerator = data.GetEnumerator() | |
| End Sub |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Public Sub New(ByVal data As IEnumerable, ByVal tableName As String) | |
| mEnumerator = data.GetEnumerator() | |
| mTableName = tableName | |
| End Sub |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Public Function MoveNext() As Boolean Implements IMailMergeDataSource.MoveNext | |
| Return mEnumerator.MoveNext() | |
| End Function |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Public ReadOnly Property TableName() As String Implements IMailMergeDataSource.TableName | |
| Get | |
| Return mTableName | |
| End Get | |
| End Property |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Private Class HandleMergeFieldAlternatingRows | |
| Implements IFieldMergingCallback | |
| ''' <summary> | |
| ''' Called for every merge field encountered in the document. | |
| ''' We can either return some data to the mail merge engine or do something | |
| ''' Else with the document. In this case we modify cell formatting. | |
| ''' </summary> | |
| Private Sub IFieldMergingCallback_FieldMerging(ByVal e As FieldMergingArgs) Implements IFieldMergingCallback.FieldMerging | |
| If mBuilder Is Nothing Then | |
| mBuilder = New DocumentBuilder(e.Document) | |
| End If | |
| ' This way we catch the beginning of a new row. | |
| If e.FieldName.Equals("CompanyName") Then | |
| ' Select the color depending on whether the row number is even or odd. | |
| Dim rowColor As Color | |
| If IsOdd(mRowIdx) Then | |
| rowColor = Color.FromArgb(213, 227, 235) | |
| Else | |
| rowColor = Color.FromArgb(242, 242, 242) | |
| End If | |
| ' There is no way to set cell properties for the whole row at the moment, | |
| ' So we have to iterate over all cells in the row. | |
| For colIdx As Integer = 0 To 3 | |
| mBuilder.MoveToCell(0, mRowIdx, colIdx, 0) | |
| mBuilder.CellFormat.Shading.BackgroundPatternColor = rowColor | |
| Next colIdx | |
| mRowIdx += 1 | |
| End If | |
| End Sub | |
| Private Sub ImageFieldMerging(ByVal args As ImageFieldMergingArgs) Implements IFieldMergingCallback.ImageFieldMerging | |
| ' Do nothing. | |
| End Sub | |
| Private mBuilder As DocumentBuilder | |
| Private mRowIdx As Integer | |
| End Class | |
| ''' <summary> | |
| ''' Returns true if the value is odd; false if the value is even. | |
| ''' </summary> | |
| Private Shared Function IsOdd(value As Integer) As Boolean | |
| ' The code is a bit complex, but otherwise automatic conversion to VB does not work. | |
| Return ((value / 2) * 2).Equals(value) | |
| End Function | |
| ''' <summary> | |
| ''' Create DataTable and fill it with data. | |
| ''' In real life this DataTable should be filled from a database. | |
| ''' </summary> | |
| Private Shared Function GetSuppliersDataTable() As DataTable | |
| Dim dataTable As New DataTable("Suppliers") | |
| dataTable.Columns.Add("CompanyName") | |
| dataTable.Columns.Add("ContactName") | |
| For i As Integer = 0 To 9 | |
| Dim datarow As DataRow = dataTable.NewRow() | |
| dataTable.Rows.Add(datarow) | |
| datarow(0) = "Company " + i.ToString() | |
| datarow(1) = "Contact " + i.ToString() | |
| Next | |
| Return dataTable | |
| End Function |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_MailMergeAndReporting() | |
| Dim doc As New Document(dataDir & Convert.ToString("MailMerge.AlternatingRows.doc")) | |
| ' Add a handler for the MergeField event. | |
| doc.MailMerge.FieldMergingCallback = New HandleMergeFieldAlternatingRows() | |
| ' Execute mail merge with regions. | |
| Dim dataTable As DataTable = GetSuppliersDataTable() | |
| doc.MailMerge.ExecuteWithRegions(dataTable) | |
| dataDir = dataDir & Convert.ToString("MailMerge.AlternatingRows_out.doc") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Imports Aspose.Words.MailMerging |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Private Class HandleMergeField | |
| Implements IFieldMergingCallback | |
| ''' <summary> | |
| ''' This handler is called for every mail merge field found in the document, | |
| ''' for every record found in the data source. | |
| ''' </summary> | |
| Private Sub IFieldMergingCallback_FieldMerging(ByVal e As FieldMergingArgs) Implements IFieldMergingCallback.FieldMerging | |
| If mBuilder Is Nothing Then | |
| mBuilder = New DocumentBuilder(e.Document) | |
| End If | |
| ' We decided that we want all boolean values to be output as check box form fields. | |
| If TypeOf e.FieldValue Is Boolean Then | |
| ' Move the "cursor" to the current merge field. | |
| mBuilder.MoveToMergeField(e.FieldName) | |
| ' It is nice to give names to check boxes. Lets generate a name such as MyField21 or so. | |
| Dim checkBoxName As String = String.Format("{0}{1}", e.FieldName, e.RecordIndex) | |
| ' Insert a check box. | |
| mBuilder.InsertCheckBox(checkBoxName, CBool(e.FieldValue), 0) | |
| ' Nothing else to do for this field. | |
| Return | |
| End If | |
| ' We want to insert html during mail merge. | |
| If e.FieldName = "Body" Then | |
| mBuilder.MoveToMergeField(e.FieldName) | |
| mBuilder.InsertHtml(DirectCast(e.FieldValue, String)) | |
| End If | |
| ' Another example, we want the Subject field to come out as text input form field. | |
| If e.FieldName = "Subject" Then | |
| mBuilder.MoveToMergeField(e.FieldName) | |
| Dim textInputName As String = String.Format("{0}{1}", e.FieldName, e.RecordIndex) | |
| mBuilder.InsertTextInput(textInputName, TextFormFieldType.Regular, "", CStr(e.FieldValue), 0) | |
| End If | |
| End Sub | |
| Private Sub ImageFieldMerging(ByVal args As ImageFieldMergingArgs) Implements IFieldMergingCallback.ImageFieldMerging | |
| ' Do nothing. | |
| End Sub | |
| Private mBuilder As DocumentBuilder | |
| End Class |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_MailMergeAndReporting() | |
| Dim fileName As String = "Template.doc" | |
| ' Load the template document. | |
| Dim doc As New Document(dataDir & fileName) | |
| ' Setup mail merge event handler to do the custom work. | |
| doc.MailMerge.FieldMergingCallback = New HandleMergeField() | |
| ' Trim trailing and leading whitespaces mail merge values | |
| doc.MailMerge.TrimWhitespaces = False | |
| ' This is the data for mail merge. | |
| Dim fieldNames() As String = {"RecipientName", "SenderName", "FaxNumber", "PhoneNumber", "Subject", "Body", "Urgent", "ForReview", "PleaseComment"} | |
| Dim fieldValues() As Object = {"Josh", "Jenny", "123456789", "", "Hello", "<b>HTML Body Test message 1</b>", True, False, True} | |
| ' Execute the mail merge. | |
| doc.MailMerge.Execute(fieldNames, fieldValues) | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| ' Save the finished document. | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Public Class HandleMergeImageFieldFromBlob | |
| Implements IFieldMergingCallback | |
| Private Sub IFieldMergingCallback_FieldMerging(args As FieldMergingArgs) Implements IFieldMergingCallback.FieldMerging | |
| ' Do nothing. | |
| End Sub | |
| ''' <summary> | |
| ''' This is called when mail merge engine encounters Image:XXX merge field in the document. | |
| ''' You have a chance to return an Image object, file name or a stream that contains the image. | |
| ''' </summary> | |
| Private Sub IFieldMergingCallback_ImageFieldMerging(e As ImageFieldMergingArgs) Implements IFieldMergingCallback.ImageFieldMerging | |
| ' The field value is a byte array, just cast it and create a stream on it. | |
| Dim imageStream As New MemoryStream(DirectCast(e.FieldValue, Byte())) | |
| ' Now the mail merge engine will retrieve the image from the stream. | |
| e.ImageStream = imageStream | |
| End Sub | |
| End Class |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_MailMergeAndReporting() | |
| Dim doc As New Document(dataDir & Convert.ToString("MailMerge.MergeImage.doc")) | |
| ' Set up the event handler for image fields. | |
| doc.MailMerge.FieldMergingCallback = New HandleMergeImageFieldFromBlob() | |
| ' Open a database connection. | |
| Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + RunExamples.GetDataDir_Database() + "Northwind.mdb" | |
| Dim conn As New OleDbConnection(connString) | |
| conn.Open() | |
| ' Open the data reader. It needs to be in the normal mode that reads all record at once. | |
| Dim cmd As New OleDbCommand("SELECT * FROM Employees", conn) | |
| Dim dataReader As IDataReader = cmd.ExecuteReader() | |
| ' Perform mail merge. | |
| doc.MailMerge.ExecuteWithRegions(dataReader, "Employees") | |
| ' Close the database. | |
| conn.Close() | |
| dataDir = dataDir & Convert.ToString("MailMerge.MergeImage_out.doc") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_MailMergeAndReporting() | |
| Dim ds As New DataSet() | |
| ds.ReadXml(dataDir & Convert.ToString("Vendors.xml")) | |
| ' Open a template document. | |
| Dim doc As New Document(dataDir & Convert.ToString("VendorTemplate.doc")) | |
| doc.MailMerge.UseNonMergeFields = True | |
| ' Execute mail merge to fill the template with data from XML using DataSet. | |
| doc.MailMerge.ExecuteWithRegions(ds) | |
| dataDir = dataDir & Convert.ToString("MailMergeUsingMustacheSyntax_out.docx") | |
| ' Save the output document. | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_MailMergeAndReporting() | |
| ' Create the Dataset and read the XML. | |
| Dim pizzaDs As New DataSet() | |
| ' Note: The Datatable.TableNames and the DataSet.Relations are defined implicitly by .NET through ReadXml. | |
| ' To see examples of how to set up relations manually check the corresponding documentation of this sample | |
| pizzaDs.ReadXml(dataDir & "CustomerData.xml") | |
| Dim fileName As String = "Invoice Template.doc" | |
| ' Open the template document. | |
| Dim doc As New Document(dataDir & fileName) | |
| ' Trim trailing and leading whitespaces mail merge values | |
| doc.MailMerge.TrimWhitespaces = False | |
| ' Execute the nested mail merge with regions | |
| doc.MailMerge.ExecuteWithRegions(pizzaDs) | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| ' Save the output to file | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Public Function GetChildDataSource(ByVal tableName As String) As IMailMergeDataSource Implements IMailMergeDataSource.GetChildDataSource | |
| Select Case tableName | |
| ' Get the child collection to merge it with the region provided with tableName variable. | |
| Case "Order" | |
| Return New OrderMailMergeDataSource(mCustomers(mRecordIndex).Orders) | |
| Case Else | |
| Return Nothing | |
| End Select | |
| End Function |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_MailMergeAndReporting() | |
| Dim fileName As String = "NestedMailMerge.CustomDataSource.doc" | |
| ' Create some data that we will use in the mail merge. | |
| Dim customers As New CustomerList() | |
| customers.Add(New Customer("Thomas Hardy", "120 Hanover Sq., London")) | |
| customers.Add(New Customer("Paolo Accorti", "Via Monte Bianco 34, Torino")) | |
| ' Create some data for nesting in the mail merge. | |
| customers(0).Orders.Add(New Order("Rugby World Cup Cap", 2)) | |
| customers(0).Orders.Add(New Order("Rugby World Cup Ball", 1)) | |
| customers(1).Orders.Add(New Order("Rugby World Cup Guide", 1)) | |
| ' Open the template document. | |
| Dim doc As New Document(dataDir & fileName) | |
| ' To be able to mail merge from your own data source, it must be wrapped | |
| ' Into an object that implements the IMailMergeDataSource interface. | |
| Dim customersDataSource As New CustomerMailMergeDataSource(customers) | |
| ' Now you can pass your data source into Aspose.Words. | |
| doc.MailMerge.ExecuteWithRegions(customersDataSource) | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_MailMergeAndReporting() | |
| ' Open the database connection. | |
| Dim connString As String = (Convert.ToString("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=") & dataDir) + "Customers.mdb" | |
| Dim conn As New OleDbConnection(connString) | |
| conn.Open() | |
| ' Get data from a database. | |
| Dim cmd As New OleDbCommand("SELECT * FROM Customers", conn) | |
| Dim da As New OleDbDataAdapter(cmd) | |
| Dim data As New DataTable() | |
| da.Fill(data) | |
| ' Open the template document. | |
| Dim doc As New Document(dataDir & Convert.ToString("TestFile.doc")) | |
| Dim counter As Integer = 1 | |
| ' Loop though all records in the data source. | |
| For Each row As DataRow In data.Rows | |
| ' Clone the template instead of loading it from disk (for speed). | |
| Dim dstDoc As Document = DirectCast(doc.Clone(True), Document) | |
| ' Execute mail merge. | |
| dstDoc.MailMerge.Execute(row) | |
| ' Save the document. | |
| dstDoc.Save(String.Format(dataDir & Convert.ToString("TestFile_out{0}.doc"), System.Math.Max(System.Threading.Interlocked.Increment(counter), counter - 1))) | |
| Next |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' Set the appropriate mail merge clean up options to remove any unused regions from the document. | |
| doc.MailMerge.CleanupOptions = MailMergeCleanupOptions.RemoveUnusedRegions | |
| ' Doc.MailMerge.CleanupOptions = MailMergeCleanupOptions.RemoveContainingFields | |
| ' Doc.MailMerge.CleanupOptions = doc.MailMerge.CleanupOptions Or MailMergeCleanupOptions.RemoveStaticFields | |
| ' Doc.MailMerge.CleanupOptions = doc.MailMerge.CleanupOptions Or MailMergeCleanupOptions.RemoveEmptyParagraphs | |
| ' Doc.MailMerge.CleanupOptions = doc.MailMerge.CleanupOptions Or MailMergeCleanupOptions.RemoveUnusedFields |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_MailMergeAndReporting() | |
| Dim fileName As String = "TestFile.doc" | |
| ' Open the document. | |
| Dim doc As New Document(dataDir & fileName) | |
| ' Create a dummy data source containing no data. | |
| Dim data As New DataSet() | |
| ' Set the appropriate mail merge clean up options to remove any unused regions from the document. | |
| doc.MailMerge.CleanupOptions = MailMergeCleanupOptions.RemoveUnusedRegions | |
| ' Doc.MailMerge.CleanupOptions = MailMergeCleanupOptions.RemoveContainingFields | |
| ' Doc.MailMerge.CleanupOptions = doc.MailMerge.CleanupOptions Or MailMergeCleanupOptions.RemoveStaticFields | |
| ' Doc.MailMerge.CleanupOptions = doc.MailMerge.CleanupOptions Or MailMergeCleanupOptions.RemoveEmptyParagraphs | |
| ' Doc.MailMerge.CleanupOptions = doc.MailMerge.CleanupOptions Or MailMergeCleanupOptions.RemoveUnusedFields | |
| ' Execute mail merge which will have no effect as there is no data. However the regions found in the document will be removed | |
| ' Automatically as they are unused. | |
| doc.MailMerge.ExecuteWithRegions(data) | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| ' Save the output document to disk. | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_MailMergeAndReporting() | |
| ' Open an existing document. | |
| Dim doc As New Document(dataDir & Convert.ToString("MailMerge.ExecuteArray.doc")) | |
| doc.MailMerge.UseNonMergeFields = True | |
| ' Fill the fields in the document with user data. | |
| doc.MailMerge.Execute(New String() {"FullName", "Company", "Address", "Address2", "City"}, New Object() {"James Bond", "MI5 Headquarters", "Milbank", "", "London"}) | |
| dataDir = dataDir & Convert.ToString("MailMerge.ExecuteArray_out.doc") | |
| ' Send the document in Word format to the client browser with an option to save to disk or open inside the current browser. | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_MailMergeAndReporting() | |
| ' Create the Dataset and read the XML. | |
| Dim customersDs As New DataSet() | |
| customersDs.ReadXml(dataDir & "Customers.xml") | |
| Dim fileName As String = "TestFile.doc" | |
| ' Open a template document. | |
| Dim doc As New Document(dataDir & fileName) | |
| ' Execute mail merge to fill the template with data from XML using DataTable. | |
| doc.MailMerge.Execute(customersDs.Tables("Customer")) | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| ' Save the output document. | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithBookmarks() | |
| Dim doc As New Document(dataDir & Convert.ToString("Bookmarks.doc")) | |
| ' By index. | |
| Dim bookmark1 As Bookmark = doc.Range.Bookmarks(0) | |
| ' By name. | |
| Dim bookmark2 As Bookmark = doc.Range.Bookmarks("Bookmark2") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithBookmarks() | |
| Dim doc As New Document(dataDir & Convert.ToString("Bookmark.doc")) | |
| ' Use the indexer of the Bookmarks collection to obtain the desired bookmark. | |
| Dim bookmark As Bookmark = doc.Range.Bookmarks("MyBookmark") | |
| ' Get the name and text of the bookmark. | |
| Dim name As String = bookmark.Name | |
| Dim text As String = bookmark.Text | |
| ' Set the name and text of the bookmark. | |
| bookmark.Name = "RenamedBookmark" | |
| bookmark.Text = "This is a new bookmarked text." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithBookmarks() | |
| ' Create empty document | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| Dim table As Table = builder.StartTable() | |
| ' Insert a cell | |
| builder.InsertCell() | |
| ' Start bookmark here after calling InsertCell | |
| builder.StartBookmark("MyBookmark") | |
| builder.Write("This is row 1 cell 1") | |
| ' Insert a cell | |
| builder.InsertCell() | |
| builder.Write("This is row 1 cell 2") | |
| builder.EndRow() | |
| ' Insert a cell | |
| builder.InsertCell() | |
| builder.Writeln("This is row 2 cell 1") | |
| ' Insert a cell | |
| builder.InsertCell() | |
| builder.Writeln("This is row 2 cell 2") | |
| builder.EndRow() | |
| builder.EndTable() | |
| ' End of bookmark | |
| builder.EndBookmark("MyBookmark") | |
| dataDir = dataDir & Convert.ToString("Bookmark.Table_out.doc") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithBookmarks() | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| builder.StartBookmark("My Bookmark") | |
| builder.Writeln("Text inside a bookmark.") | |
| builder.StartBookmark("Nested Bookmark") | |
| builder.Writeln("Text inside a NestedBookmark.") | |
| builder.EndBookmark("Nested Bookmark") | |
| builder.Writeln("Text after Nested Bookmark.") | |
| builder.EndBookmark("My Bookmark") | |
| Dim options As New PdfSaveOptions() | |
| options.OutlineOptions.BookmarksOutlineLevels.Add("My Bookmark", 1) | |
| options.OutlineOptions.BookmarksOutlineLevels.Add("Nested Bookmark", 2) | |
| dataDir = dataDir & Convert.ToString("Create.Bookmark_out.pdf") | |
| doc.Save(dataDir, options) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithCharts() | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| Dim shape As Shape = builder.InsertChart(ChartType.Line, 432, 252) | |
| Dim chart As Chart = shape.Chart | |
| ' Determines whether the title shall be shown for this chart. Default is true. | |
| chart.Title.Show = True | |
| ' Setting chart Title. | |
| chart.Title.Text = "Sample Line Chart Title" | |
| ' Determines whether other chart elements shall be allowed to overlap title. | |
| chart.Title.Overlay = False | |
| ' Please note if null or empty value is specified as title text, auto generated title will be shown. | |
| ' Determines how legend shall be shown for this chart. | |
| chart.Legend.Position = LegendPosition.Left | |
| chart.Legend.Overlay = True | |
| dataDir = dataDir & Convert.ToString("SimpleLineChart_out.docx") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' Get chart series collection. | |
| Dim seriesColl As ChartSeriesCollection = chart.Series | |
| ' Check series count. | |
| Console.WriteLine(seriesColl.Count) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| ' Insert Column chart. | |
| Dim shape As Shape = builder.InsertChart(ChartType.Column, 432, 252) | |
| Dim chart As Chart = shape.Chart | |
| ' Use this overload to add series to any type of Bar, Column, Line and Surface charts. | |
| chart.Series.Add("AW Series 1", New String() {"AW Category 1", "AW Category 2"}, New Double() {1, 2}) | |
| dataDir = dataDir & Convert.ToString("TestInsertChartColumn_out.doc") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| ' Add chart with default data. You can specify different chart types and sizes. | |
| Dim shape As Shape = builder.InsertChart(ChartType.Column, 432, 252) | |
| ' Chart property of Shape contains all chart related options. | |
| Dim chart As Chart = shape.Chart | |
| ' Get chart series collection. | |
| Dim seriesColl As ChartSeriesCollection = chart.Series | |
| ' Check series count. | |
| Console.WriteLine(seriesColl.Count) | |
| ' Delete default generated series. | |
| seriesColl.Clear() | |
| ' Create category names array, in this example we have two categories. | |
| Dim categories As String() = New String() {"AW Category 1", "AW Category 2"} | |
| ' Adding new series. Please note, data arrays must not be empty and arrays must be the same size. | |
| seriesColl.Add("AW Series 1", categories, New Double() {1, 2}) | |
| seriesColl.Add("AW Series 2", categories, New Double() {3, 4}) | |
| seriesColl.Add("AW Series 3", categories, New Double() {5, 6}) | |
| seriesColl.Add("AW Series 4", categories, New Double() {7, 8}) | |
| seriesColl.Add("AW Series 5", categories, New Double() {9, 10}) | |
| dataDir = dataDir & Convert.ToString("TestInsertSimpleChartColumn_out.doc") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithCharts() | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| ' Insert Area chart. | |
| Dim shape As Shape = builder.InsertChart(ChartType.Area, 432, 252) | |
| Dim chart As Chart = shape.Chart | |
| ' Use this overload to add series to any type of Area, Radar and Stock charts. | |
| chart.Series.Add("AW Series 1", New DateTime() {New DateTime(2002, 5, 1), New DateTime(2002, 6, 1), New DateTime(2002, 7, 1), New DateTime(2002, 8, 1), New DateTime(2002, 9, 1)}, New Double() {32, 32, 28, 12, 15}) | |
| dataDir = dataDir & Convert.ToString("TestInsertAreaChart_out.docx") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithCharts() | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| ' Insert Bubble chart. | |
| Dim shape As Shape = builder.InsertChart(ChartType.Bubble, 432, 252) | |
| Dim chart As Chart = shape.Chart | |
| ' Use this overload to add series to any type of Bubble charts. | |
| chart.Series.Add("AW Series 1", New Double() {0.7, 1.8, 2.6}, New Double() {2.7, 3.2, 0.8}, New Double() {10, 4, 8}) | |
| dataDir = dataDir & Convert.ToString("TestInsertBubbleChart_out.docx") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithCharts() | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| ' Insert Scatter chart. | |
| Dim shape As Shape = builder.InsertChart(ChartType.Scatter, 432, 252) | |
| Dim chart As Chart = shape.Chart | |
| ' Use this overload to add series to any type of Scatter charts. | |
| chart.Series.Add("AW Series 1", New Double() {0.7, 1.8, 2.6}, New Double() {2.7, 3.2, 0.8}) | |
| dataDir = dataDir & Convert.ToString("TestInsertScatterChart_out.docx") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithCharts() | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| Dim shape As Shape = builder.InsertChart(ChartType.Bar, 432, 252) | |
| Dim chart As Chart = shape.Chart | |
| ' Get first series. | |
| Dim series0 As ChartSeries = shape.Chart.Series(0) | |
| Dim dataLabelCollection As ChartDataLabelCollection = series0.DataLabels | |
| ' Add data label to the first and second point of the first series. | |
| Dim chartDataLabel00 As ChartDataLabel = dataLabelCollection.Add(0) | |
| Dim chartDataLabel01 As ChartDataLabel = dataLabelCollection.Add(1) | |
| ' Set properties. | |
| chartDataLabel00.ShowLegendKey = True | |
| ' By default, when you add data labels to the data points in a pie chart, leader lines are displayed for data labels that are | |
| ' Positioned far outside the end of data points. Leader lines create a visual connection between a data label and its | |
| ' Corresponding data point. | |
| chartDataLabel00.ShowLeaderLines = True | |
| chartDataLabel00.ShowCategoryName = False | |
| chartDataLabel00.ShowPercentage = False | |
| chartDataLabel00.ShowSeriesName = True | |
| chartDataLabel00.ShowValue = True | |
| chartDataLabel00.Separator = "/" | |
| chartDataLabel01.ShowValue = True | |
| dataDir = dataDir & Convert.ToString("SimpleBarChart_out.docx") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithCharts() | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| Dim shape As Shape = builder.InsertChart(ChartType.Line, 432, 252) | |
| Dim chart As Chart = shape.Chart | |
| ' Get first series. | |
| Dim series0 As ChartSeries = shape.Chart.Series(0) | |
| ' Get second series. | |
| Dim series1 As ChartSeries = shape.Chart.Series(1) | |
| Dim dataPointCollection As ChartDataPointCollection = series0.DataPoints | |
| ' Add data point to the first and second point of the first series. | |
| Dim dataPoint00 As ChartDataPoint = dataPointCollection.Add(0) | |
| Dim dataPoint01 As ChartDataPoint = dataPointCollection.Add(1) | |
| ' Set explosion. | |
| dataPoint00.Explosion = 50 | |
| ' Set marker symbol and size. | |
| dataPoint00.Marker.Symbol = MarkerSymbol.Circle | |
| dataPoint00.Marker.Size = 15 | |
| dataPoint01.Marker.Symbol = MarkerSymbol.Diamond | |
| dataPoint01.Marker.Size = 20 | |
| ' Add data point to the third point of the second series. | |
| Dim dataPoint12 As ChartDataPoint = series1.DataPoints.Add(2) | |
| dataPoint12.InvertIfNegative = True | |
| dataPoint12.Marker.Symbol = MarkerSymbol.Star | |
| dataPoint12.Marker.Size = 20 | |
| dataDir = dataDir & Convert.ToString("SingleChartDataPoint_out.docx") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' Specifies whether by default the parent element shall inverts its colors if the value is negative. | |
| series0.InvertIfNegative = True | |
| ' Set default marker symbol and size. | |
| series0.Marker.Symbol = MarkerSymbol.Circle | |
| series0.Marker.Size = 15 | |
| series1.Marker.Symbol = MarkerSymbol.Star | |
| series1.Marker.Size = 10 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' Get first series. | |
| Dim series0 As ChartSeries = shape.Chart.Series(0) | |
| ' Get second series. | |
| Dim series1 As ChartSeries = shape.Chart.Series(1) | |
| ' Change first series name. | |
| series0.Name = "My Name1" | |
| ' Change second series name. | |
| series1.Name = "My Name2" | |
| ' You can also specify whether the line connecting the points on the chart shall be smoothed using Catmull-Rom splines. | |
| series0.Smooth = True | |
| series1.Smooth = True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithComments() | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| builder.Write("Some text is added.") | |
| Dim comment As New Comment(doc, "Awais Hafeez", "AH", DateTime.Today) | |
| builder.CurrentParagraph.AppendChild(comment) | |
| comment.Paragraphs.Add(New Paragraph(doc)) | |
| comment.FirstParagraph.Runs.Add(New Run(doc, "Comment text.")) | |
| dataDir = dataDir & Convert.ToString("Comments_out.doc") | |
| ' Save the document. | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| builder.Write("Some text is added.") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithComments() | |
| Dim doc As New Document() | |
| Dim para1 As New Paragraph(doc) | |
| Dim run1 As New Run(doc, "Some ") | |
| Dim run2 As New Run(doc, "text ") | |
| para1.AppendChild(run1) | |
| para1.AppendChild(run2) | |
| doc.FirstSection.Body.AppendChild(para1) | |
| Dim para2 As New Paragraph(doc) | |
| Dim run3 As New Run(doc, "is ") | |
| Dim run4 As New Run(doc, "added ") | |
| para2.AppendChild(run3) | |
| para2.AppendChild(run4) | |
| doc.FirstSection.Body.AppendChild(para2) | |
| Dim comment As New Comment(doc, "Awais Hafeez", "AH", DateTime.Today) | |
| comment.Paragraphs.Add(New Paragraph(doc)) | |
| comment.FirstParagraph.Runs.Add(New Run(doc, "Comment text.")) | |
| Dim commentRangeStart As New CommentRangeStart(doc, comment.Id) | |
| Dim commentRangeEnd As New CommentRangeEnd(doc, comment.Id) | |
| run1.ParentNode.InsertAfter(commentRangeStart, run1) | |
| run3.ParentNode.InsertAfter(commentRangeEnd, run3) | |
| commentRangeEnd.ParentNode.InsertAfter(comment, commentRangeEnd) | |
| dataDir = dataDir & Convert.ToString("Anchor.Comment_out.doc") | |
| ' Save the document. | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Private Shared Function ExtractComments(ByVal doc As Document) As ArrayList | |
| Dim collectedComments As New ArrayList() | |
| ' Collect all comments in the document | |
| Dim comments As NodeCollection = doc.GetChildNodes(NodeType.Comment, True) | |
| ' Look through all comments and gather information about them. | |
| For Each comment As Comment In comments | |
| collectedComments.Add(comment.Author & " " & comment.DateTime & " " & comment.ToString(SaveFormat.Text)) | |
| Next comment | |
| Return collectedComments | |
| End Function |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithComments() | |
| Dim fileName As String = "TestFile.doc" | |
| ' Open the document. | |
| Dim doc As New Document(dataDir & fileName) | |
| For Each comment As String In ExtractComments(doc) | |
| Console.Write(comment) | |
| Next comment | |
| ' Remove comments by the "pm" author. | |
| RemoveComments(doc, "pm") | |
| Console.WriteLine("Comments from ""pm"" are removed!") | |
| ' Extract the information about the comments of the "ks" author. | |
| For Each comment As String In ExtractComments(doc, "ks") | |
| Console.Write(comment) | |
| Next comment | |
| ' Remove all comments. | |
| RemoveComments(doc) | |
| Console.WriteLine("All comments are removed!") | |
| dataDir = dataDir + RunExamples.GetOutputFilePath(fileName) | |
| ' Save the document. | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Private Shared Sub RemoveComments(ByVal doc As Document) | |
| ' Collect all comments in the document | |
| Dim comments As NodeCollection = doc.GetChildNodes(NodeType.Comment, True) | |
| ' Remove all comments. | |
| comments.Clear() | |
| End Sub |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| Dim pageSetup As PageSetup = builder.PageSetup | |
| pageSetup.TopMargin = ConvertUtil.InchToPoint(1.0) | |
| pageSetup.BottomMargin = ConvertUtil.InchToPoint(1.0) | |
| pageSetup.LeftMargin = ConvertUtil.InchToPoint(1.5) | |
| pageSetup.RightMargin = ConvertUtil.InchToPoint(1.5) | |
| pageSetup.HeaderDistance = ConvertUtil.InchToPoint(0.2) | |
| pageSetup.FooterDistance = ConvertUtil.InchToPoint(0.2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim text As String = "test" & vbCr | |
| ' Replace "\r" control character with "\r\n" | |
| text = text.Replace(ControlChar.Cr, ControlChar.CrLf) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithDocument() | |
| Dim doc As New Document(dataDir & Convert.ToString("Document.doc")) | |
| ' Start tracking and make some revisions. | |
| doc.StartTrackRevisions("Author") | |
| doc.FirstSection.Body.AppendParagraph("Hello world!") | |
| ' Revisions will now show up as normal text in the output document. | |
| doc.AcceptAllRevisions() | |
| dataDir = dataDir & Convert.ToString("Document.AcceptedRevisions_out.doc") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithDocument() | |
| ' Load the template document. | |
| Dim doc As New Document(dataDir & Convert.ToString("TestFile.doc")) | |
| ' Get styles collection from document. | |
| Dim styles As StyleCollection = doc.Styles | |
| Dim styleName As String = "" | |
| ' Iterate through all the styles. | |
| For Each style As Style In styles | |
| If styleName = "" Then | |
| styleName = style.Name | |
| Else | |
| styleName = (styleName & Convert.ToString(", ")) + style.Name | |
| End If | |
| Next |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithDocument() | |
| Dim doc As New Document() | |
| doc.EnsureMinimum() | |
| Dim gs As New GroupShape(doc) | |
| Dim shape As New Shape(doc, Aspose.Words.Drawing.ShapeType.AccentBorderCallout1) | |
| shape.Width = 100 | |
| shape.Height = 100 | |
| gs.AppendChild(shape) | |
| Dim shape1 As New Shape(doc, Aspose.Words.Drawing.ShapeType.ActionButtonBeginning) | |
| shape1.Left = 100 | |
| shape1.Width = 100 | |
| shape1.Height = 200 | |
| gs.AppendChild(shape1) | |
| gs.Width = 200 | |
| gs.Height = 200 | |
| gs.CoordSize = New System.Drawing.Size(200, 200) | |
| Dim builder As New DocumentBuilder(doc) | |
| builder.InsertNode(gs) | |
| dataDir = dataDir & Convert.ToString("groupshape-doc_out.doc") | |
| ' Save the document to disk. | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithDocument() | |
| ' Open the empty document | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| Dim SdtCheckBox As New StructuredDocumentTag(doc, SdtType.Checkbox, MarkupLevel.Inline) | |
| ' Insert content control into the document | |
| builder.InsertNode(SdtCheckBox) | |
| dataDir = dataDir & Convert.ToString("CheckBoxTypeContentControl_out.docx") | |
| doc.Save(dataDir, SaveFormat.Docx) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithDocument() | |
| ' Load the document from disk. | |
| Dim doc As New Document(dataDir & Convert.ToString("TestFile.doc")) | |
| Dim clone As Document = doc.Clone() | |
| dataDir = dataDir & Convert.ToString("TestFile_clone_out.doc") | |
| ' Save the document to disk. | |
| clone.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithDocument() | |
| Dim doc As New Document() | |
| Dim sdt As New StructuredDocumentTag(doc, SdtType.ComboBox, MarkupLevel.Block) | |
| sdt.ListItems.Add(New SdtListItem("Choose an item", "-1")) | |
| sdt.ListItems.Add(New SdtListItem("Item 1", "1")) | |
| sdt.ListItems.Add(New SdtListItem("Item 2", "2")) | |
| doc.FirstSection.Body.AppendChild(sdt) | |
| dataDir = dataDir & Convert.ToString("ComboBoxContentControl_out.docx") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim docA As New Document(dataDir & Convert.ToString("TestFile.doc")) | |
| Dim docB As New Document(dataDir & Convert.ToString("TestFile - Copy.doc")) | |
| ' DocA now contains changes as revisions. | |
| docA.Compare(docB, "user", DateTime.Now) | |
| If docA.Revisions.Count = 0 Then | |
| Console.WriteLine("Documents are equal") | |
| Else | |
| Console.WriteLine("Documents are not equal") | |
| End If |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim docA As New Document(dataDir & Convert.ToString("TestFile.doc")) | |
| Dim docB As New Document(dataDir & Convert.ToString("TestFile - Copy.doc")) | |
| ' DocA now contains changes as revisions. | |
| docA.Compare(docB, "user", DateTime.Now) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document(dataDir & Convert.ToString("Properties.doc")) | |
| Dim props As CustomDocumentProperties = doc.CustomDocumentProperties | |
| If props("Authorized") Is Nothing Then | |
| props.Add("Authorized", True) | |
| props.Add("Authorized By", "John Smith") | |
| props.Add("Authorized Date", DateTime.Today) | |
| props.Add("Authorized Revision", doc.BuiltInDocumentProperties.RevisionNumber) | |
| props.Add("Authorized Amount", 123.45) | |
| End If |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Aspose.Words.Document(dataDir & Convert.ToString("Properties.doc")) | |
| doc.CustomDocumentProperties.Remove("Authorized Date") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim fileName As String = dataDir & Convert.ToString("Properties.doc") | |
| Dim doc As New Document(fileName) | |
| Console.WriteLine("1. Document name: {0}", fileName) | |
| Console.WriteLine("2. Built-in Properties") | |
| For Each prop As DocumentProperty In doc.BuiltInDocumentProperties | |
| Console.WriteLine("{0} : {1}", prop.Name, prop.Value) | |
| Next | |
| Console.WriteLine("3. Custom Properties") | |
| For Each prop As DocumentProperty In doc.CustomDocumentProperties | |
| Console.WriteLine("{0} : {1}", prop.Name, prop.Value) | |
| Next |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithDocument() | |
| ' Initialize document. | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| Dim table As Table = builder.StartTable() | |
| ' Insert a cell | |
| builder.InsertCell() | |
| ' Use fixed column widths. | |
| table.AutoFit(AutoFitBehavior.FixedColumnWidths) | |
| builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center | |
| builder.Write("This is row 1 cell 1") | |
| ' Insert a cell | |
| builder.InsertCell() | |
| builder.Write("This is row 1 cell 2") | |
| builder.EndRow() | |
| ' Insert a cell | |
| builder.InsertCell() | |
| ' Apply new row formatting | |
| builder.RowFormat.Height = 100 | |
| builder.RowFormat.HeightRule = HeightRule.Exactly | |
| builder.CellFormat.Orientation = TextOrientation.Upward | |
| builder.Writeln("This is row 2 cell 1") | |
| ' Insert a cell | |
| builder.InsertCell() | |
| builder.CellFormat.Orientation = TextOrientation.Downward | |
| builder.Writeln("This is row 2 cell 2") | |
| builder.EndRow() | |
| builder.EndTable() | |
| dataDir = dataDir & Convert.ToString("DocumentBuilderBuildTable_out.doc") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithDocument() | |
| ' Initialize document. | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| builder.StartBookmark("FineBookmark") | |
| builder.Writeln("This is just a fine bookmark.") | |
| builder.EndBookmark("FineBookmark") | |
| dataDir = dataDir & Convert.ToString("DocumentBuilderInsertBookmark_out.doc") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithDocument() | |
| ' Initialize document. | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| builder.Writeln("This is page 1.") | |
| builder.InsertBreak(BreakType.PageBreak) | |
| builder.Writeln("This is page 2.") | |
| builder.InsertBreak(BreakType.PageBreak) | |
| builder.Writeln("This is page 3.") | |
| dataDir = dataDir & Convert.ToString("DocumentBuilderInsertBreak_out.doc") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| builder.InsertCheckBox("CheckBox", True, True, 0) | |
| dataDir = dataDir & Convert.ToString("DocumentBuilderInsertCheckBoxFormField_out.doc") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| Dim items As String() = {"One", "Two", "Three"} | |
| builder.InsertComboBox("DropDown", items, 0) | |
| dataDir = dataDir & Convert.ToString("DocumentBuilderInsertComboBoxFormField_out.doc") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| builder.InsertHtml("<P align=' Right'>Paragraph right</P>" + "<b>Implicit paragraph left</b>" + "<div align=' Center'>Div center</div>" + "<h1 align=' Left'>Heading 1 left.</h1>") | |
| dataDir = dataDir & Convert.ToString("DocumentBuilderInsertHtml_out.doc") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| builder.Write("Please make sure to visit ") | |
| ' Specify font formatting for the hyperlink. | |
| builder.Font.Color = Color.Blue | |
| builder.Font.Underline = Underline.[Single] | |
| ' Insert the link. | |
| builder.InsertHyperlink("Aspose Website", "http://www.aspose.com", False) | |
| ' Revert to default formatting. | |
| builder.Font.ClearFormatting() | |
| builder.Write(" for more information.") | |
| dataDir = dataDir & Convert.ToString("DocumentBuilderInsertHyperlink_out.doc") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Aspose.Words.Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| builder.InsertOleObject("http://www.aspose.com", "htmlfile", True, True, Nothing) | |
| dataDir = dataDir & Convert.ToString("DocumentBuilderInsertOleObject_out.doc") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| ' Insert a table of contents at the beginning of the document. | |
| builder.InsertTableOfContents("\o ""1-3"" \h \z \u") | |
| ' Start the actual document content on the second page. | |
| builder.InsertBreak(BreakType.PageBreak) | |
| ' Build a document with complex structure by applying different heading styles thus creating TOC entries. | |
| builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1 | |
| builder.Writeln("Heading 1") | |
| builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading2 | |
| builder.Writeln("Heading 1.1") | |
| builder.Writeln("Heading 1.2") | |
| builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1 | |
| builder.Writeln("Heading 2") | |
| builder.Writeln("Heading 3") | |
| builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading2 | |
| builder.Writeln("Heading 3.1") | |
| builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading3 | |
| builder.Writeln("Heading 3.1.1") | |
| builder.Writeln("Heading 3.1.2") | |
| builder.Writeln("Heading 3.1.3") | |
| builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading2 | |
| builder.Writeln("Heading 3.2") | |
| builder.Writeln("Heading 3.3") | |
| doc.UpdateFields() | |
| dataDir = dataDir & Convert.ToString("DocumentBuilderInsertTableOfContents_out.doc") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| builder.InsertTextInput("TextInput", TextFormFieldType.Regular, "", "Hello", 0) | |
| dataDir = dataDir & Convert.ToString("DocumentBuilderInsertTextInputFormField_out.doc") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| builder.InsertImage(dataDir & Convert.ToString("Watermark.png"), RelativeHorizontalPosition.Margin, 100, RelativeVerticalPosition.Margin, 100, 200, _ | |
| 100, WrapType.Square) | |
| dataDir = dataDir & Convert.ToString("DocumentBuilderInsertFloatingImage_out.doc") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| builder.InsertImage(dataDir & Convert.ToString("Watermark.png")) | |
| dataDir = dataDir & Convert.ToString("DocumentBuilderInsertInlineImage_out.doc") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithDocument() | |
| ' Initialize document. | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| ' Specify font formatting | |
| Dim font As Aspose.Words.Font = builder.Font | |
| font.Size = 16 | |
| font.Bold = True | |
| font.Color = System.Drawing.Color.Blue | |
| font.Name = "Arial" | |
| font.Underline = Underline.Dash | |
| ' Specify paragraph formatting | |
| Dim paragraphFormat As ParagraphFormat = builder.ParagraphFormat | |
| paragraphFormat.FirstLineIndent = 8 | |
| paragraphFormat.Alignment = ParagraphAlignment.Justify | |
| paragraphFormat.KeepTogether = True | |
| builder.Writeln("A whole paragraph.") | |
| dataDir = dataDir & Convert.ToString("DocumentBuilderInsertParagraph_out.doc") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithDocument() | |
| ' Initialize document. | |
| Dim doc As New Document() | |
| ' Create a document builder to insert content with. | |
| Dim builder As New DocumentBuilder(doc) | |
| ' Insert a TC field at the current document builder position. | |
| builder.InsertField("TC ""Entry Text"" \f t") | |
| dataDir = dataDir & Convert.ToString("DocumentBuilderInsertTCField_out.doc") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document() | |
| Dim options As New FindReplaceOptions() | |
| options.ReplacingCallback = New InsertTCFieldHandler("Chapter 1", "\l 1") | |
| ' Insert a TC field which displays "Chapter 1" just before the text "The Beginning" in the document. | |
| doc.Range.Replace(New Regex("The Beginning"), "", options) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Public Class InsertTCFieldHandler | |
| Implements IReplacingCallback | |
| ' Store the text and switches to be used for the TC fields. | |
| Private mFieldText As String | |
| Private mFieldSwitches As String | |
| ''' <summary> | |
| ''' The switches to use for each TC field. Can be an empty string or null. | |
| ''' </summary> | |
| Public Sub New(switches As String) | |
| Me.New(String.Empty, switches) | |
| mFieldSwitches = switches | |
| End Sub | |
| ''' <summary> | |
| ''' The display text and switches to use for each TC field. Display name can be an empty string or null. | |
| ''' </summary> | |
| Public Sub New(text As String, switches As String) | |
| mFieldText = text | |
| mFieldSwitches = switches | |
| End Sub | |
| Private Function IReplacingCallback_Replacing(args As ReplacingArgs) As ReplaceAction Implements IReplacingCallback.Replacing | |
| ' Create a builder to insert the field. | |
| Dim builder As New DocumentBuilder(DirectCast(args.MatchNode.Document, Aspose.Words.Document)) | |
| ' Move to the first node of the match. | |
| builder.MoveTo(args.MatchNode) | |
| ' If the user specified text to be used in the field as display text then use that, otherwise use the | |
| ' Match string as the display text. | |
| Dim insertText As String | |
| If Not String.IsNullOrEmpty(mFieldText) Then | |
| insertText = mFieldText | |
| Else | |
| insertText = args.Match.Value | |
| End If | |
| ' Insert the TC field before this node using the specified string as the display text and user defined switches. | |
| builder.InsertField(String.Format("TC ""{0}"" {1}", insertText, mFieldSwitches)) | |
| ' We have done what we want so skip replacement. | |
| Return ReplaceAction.Skip | |
| End Function | |
| End Class |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithDocument() | |
| ' Initialize document. | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| ' Insert a table of contents at the beginning of the document. | |
| builder.InsertTableOfContents("\o ""1-3"" \h \z \u") | |
| ' The newly inserted table of contents will be initially empty. | |
| ' It needs to be populated by updating the fields in the document. | |
| doc.UpdateFields() | |
| dataDir = dataDir & Convert.ToString("DocumentBuilderInsertTOC_out.doc") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| doc.UpdateFields() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' Shows how to access the current node in a document builder. | |
| Dim doc As Document = New Aspose.Words.Document(dataDir & Convert.ToString("DocumentBuilder.doc")) | |
| Dim builder As New DocumentBuilder(doc) | |
| Dim curNode As Node = builder.CurrentNode | |
| Dim curParagraph As Paragraph = builder.CurrentParagraph |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document(dataDir & Convert.ToString("DocumentBuilder.doc")) | |
| Dim builder As New DocumentBuilder(doc) | |
| builder.MoveToBookmark("CoolBookmark") | |
| builder.Writeln("This is a very cool bookmark.") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document(dataDir & Convert.ToString("DocumentBuilder.doc")) | |
| Dim builder As New DocumentBuilder(doc) | |
| builder.MoveToBookmark("CoolBookmark", False, True) | |
| builder.Writeln("This is a very cool bookmark.") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document(dataDir & Convert.ToString("DocumentBuilder.doc")) | |
| Dim builder As New DocumentBuilder(doc) | |
| builder.MoveToDocumentEnd() | |
| Console.WriteLine(vbLf & "This is the end of the document.") | |
| builder.MoveToDocumentStart() | |
| Console.WriteLine(vbLf & "This is the beginning of the document.") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document(dataDir & Convert.ToString("DocumentBuilder.doc")) | |
| Dim builder As New DocumentBuilder(doc) | |
| builder.MoveToMergeField("NiceMergeField") | |
| builder.Writeln("This is a very nice merge field.") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document(dataDir & Convert.ToString("DocumentBuilder.doc")) | |
| Dim builder As New DocumentBuilder(doc) | |
| builder.MoveTo(doc.FirstSection.Body.LastParagraph) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document(dataDir & Convert.ToString("DocumentBuilder.doc")) | |
| Dim builder As New DocumentBuilder(doc) | |
| ' Parameters are 0-index. Moves to third paragraph. | |
| builder.MoveToParagraph(2, 0) | |
| builder.Writeln("This is the 3rd paragraph.") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document(dataDir & Convert.ToString("DocumentBuilder.doc")) | |
| Dim builder As New DocumentBuilder(doc) | |
| ' Parameters are 0-index. Moves to third section. | |
| builder.MoveToSection(2) | |
| builder.Writeln("This is the 3rd section.") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document(dataDir & Convert.ToString("DocumentBuilder.doc")) | |
| Dim builder As New DocumentBuilder(doc) | |
| ' All parameters are 0-index. Moves to the 2nd table, 3rd row, 5th cell. | |
| builder.MoveToCell(1, 2, 4, 0) | |
| builder.Writeln("Hello World!") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| ' Set paragraph borders | |
| Dim borders As BorderCollection = builder.ParagraphFormat.Borders | |
| borders.DistanceFromText = 20 | |
| borders(BorderType.Left).LineStyle = LineStyle.[Double] | |
| borders(BorderType.Right).LineStyle = LineStyle.[Double] | |
| borders(BorderType.Top).LineStyle = LineStyle.[Double] | |
| borders(BorderType.Bottom).LineStyle = LineStyle.[Double] | |
| ' Set paragraph shading | |
| Dim shading As Shading = builder.ParagraphFormat.Shading | |
| shading.Texture = TextureIndex.TextureDiagonalCross | |
| shading.BackgroundPatternColor = System.Drawing.Color.LightCoral | |
| shading.ForegroundPatternColor = System.Drawing.Color.LightSalmon | |
| builder.Write("I' M a formatted paragraph with double border and nice shading.") | |
| dataDir = dataDir & Convert.ToString("DocumentBuilderApplyBordersAndShadingToParagraph_out.doc") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| ' Set paragraph style | |
| builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Title | |
| builder.Write("Hello") | |
| dataDir = dataDir & Convert.ToString("DocumentBuilderApplyParagraphStyle_out.doc") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| ' Set font formatting properties | |
| Dim font As Aspose.Words.Font = builder.Font | |
| font.Bold = True | |
| font.Color = System.Drawing.Color.DarkBlue | |
| font.Italic = True | |
| font.Name = "Arial" | |
| font.Size = 24 | |
| font.Spacing = 5 | |
| font.Underline = Underline.[Double] | |
| ' Output formatted text | |
| builder.Writeln("I' M a very nice formatted string.") | |
| dataDir = dataDir & Convert.ToString("DocumentBuilderSetFontFormatting_out.doc") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| builder.ListFormat.ApplyNumberDefault() | |
| builder.Writeln("Item 1") | |
| builder.Writeln("Item 2") | |
| builder.ListFormat.ListIndent() | |
| builder.Writeln("Item 2.1") | |
| builder.Writeln("Item 2.2") | |
| builder.ListFormat.ListIndent() | |
| builder.Writeln("Item 2.2.1") | |
| builder.Writeln("Item 2.2.2") | |
| builder.ListFormat.ListOutdent() | |
| builder.Writeln("Item 2.3") | |
| builder.ListFormat.ListOutdent() | |
| builder.Writeln("Item 3") | |
| builder.ListFormat.RemoveNumbers() | |
| dataDir = dataDir & Convert.ToString("DocumentBuilderSetMultilevelListFormatting_out.doc") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| ' Set page properties | |
| builder.PageSetup.Orientation = Orientation.Landscape | |
| builder.PageSetup.LeftMargin = 50 | |
| builder.PageSetup.PaperSize = PaperSize.Paper10x14 | |
| dataDir = dataDir & Convert.ToString("DocumentBuilderSetPageSetupAndSectionFormatting_out.doc") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| ' Set paragraph formatting properties | |
| Dim paragraphFormat As ParagraphFormat = builder.ParagraphFormat | |
| paragraphFormat.Alignment = ParagraphAlignment.Center | |
| paragraphFormat.LeftIndent = 50 | |
| paragraphFormat.RightIndent = 50 | |
| paragraphFormat.SpaceAfter = 25 | |
| ' Output text | |
| builder.Writeln("I' M a very nice formatted paragraph. I' M intended to demonstrate how the left and right indents affect word wrapping.") | |
| builder.Writeln("I' M another nice formatted paragraph. I' M intended to demonstrate how the space after paragraph looks like.") | |
| dataDir = dataDir & Convert.ToString("DocumentBuilderSetParagraphFormatting_out.doc") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| builder.StartTable() | |
| builder.InsertCell() | |
| ' Set the cell formatting | |
| Dim cellFormat As CellFormat = builder.CellFormat | |
| cellFormat.Width = 250 | |
| cellFormat.LeftPadding = 30 | |
| cellFormat.RightPadding = 30 | |
| cellFormat.TopPadding = 30 | |
| cellFormat.BottomPadding = 30 | |
| builder.Writeln("I' M a wonderful formatted cell.") | |
| builder.EndRow() | |
| builder.EndTable() | |
| dataDir = dataDir & Convert.ToString("DocumentBuilderSetTableCellFormatting_out.doc") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| Dim table As Table = builder.StartTable() | |
| builder.InsertCell() | |
| ' Set the row formatting | |
| Dim rowFormat As RowFormat = builder.RowFormat | |
| rowFormat.Height = 100 | |
| rowFormat.HeightRule = HeightRule.Exactly | |
| ' These formatting properties are set on the table and are applied to all rows in the table. | |
| table.LeftPadding = 30 | |
| table.RightPadding = 30 | |
| table.TopPadding = 30 | |
| table.BottomPadding = 30 | |
| builder.Writeln("I' M a wonderful formatted row.") | |
| builder.EndRow() | |
| builder.EndTable() | |
| dataDir = dataDir & Convert.ToString("DocumentBuilderSetTableRowFormatting_out.doc") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Public Shared Function ExtractContent(ByVal startNode As Node, ByVal endNode As Node, ByVal isInclusive As Boolean) As ArrayList | |
| ' First check that the nodes passed to this method are valid for use. | |
| VerifyParameterNodes(startNode, endNode) | |
| ' Create a list to store the extracted nodes. | |
| Dim nodes As New ArrayList() | |
| ' Keep a record of the original nodes passed to this method so we can split marker nodes if needed. | |
| Dim originalStartNode As Node = startNode | |
| Dim originalEndNode As Node = endNode | |
| ' Extract content based on block level nodes (paragraphs and tables). Traverse through parent nodes to find them. | |
| ' We will split the content of first and last nodes depending if the marker nodes are inline | |
| Do While startNode.ParentNode.NodeType <> NodeType.Body | |
| startNode = startNode.ParentNode | |
| Loop | |
| Do While endNode.ParentNode.NodeType <> NodeType.Body | |
| endNode = endNode.ParentNode | |
| Loop | |
| Dim isExtracting As Boolean = True | |
| Dim isStartingNode As Boolean = True | |
| Dim isEndingNode As Boolean = False | |
| ' The current node we are extracting from the document. | |
| Dim currNode As Node = startNode | |
| ' Begin extracting content. Process all block level nodes and specifically split the first and last nodes when needed so paragraph formatting is retained. | |
| ' Method is little more complex than a regular extractor as we need to factor in extracting using inline nodes, fields, bookmarks etc as to make it really useful. | |
| Do While isExtracting | |
| ' Clone the current node and its children to obtain a copy. | |
| Dim cloneNode As CompositeNode = CType(currNode.Clone(True), CompositeNode) | |
| isEndingNode = currNode.Equals(endNode) | |
| If isStartingNode OrElse isEndingNode Then | |
| ' We need to process each marker separately so pass it off to a separate method instead. | |
| If isStartingNode Then | |
| ProcessMarker(cloneNode, nodes, originalStartNode, isInclusive, isStartingNode, isEndingNode) | |
| isStartingNode = False | |
| End If | |
| ' Conditional needs to be separate as the block level start and end markers maybe the same node. | |
| If isEndingNode Then | |
| ProcessMarker(cloneNode, nodes, originalEndNode, isInclusive, isStartingNode, isEndingNode) | |
| isExtracting = False | |
| End If | |
| Else | |
| ' Node is not a start or end marker, simply add the copy to the list. | |
| nodes.Add(cloneNode) | |
| End If | |
| ' Move to the next node and extract it. If next node is null that means the rest of the content is found in a different section. | |
| If currNode.NextSibling Is Nothing AndAlso isExtracting Then | |
| ' Move to the next section. | |
| Dim nextSection As Section = CType(currNode.GetAncestor(NodeType.Section).NextSibling, Section) | |
| currNode = nextSection.Body.FirstChild | |
| Else | |
| ' Move to the next node in the body. | |
| currNode = currNode.NextSibling | |
| End If | |
| Loop | |
| ' Return the nodes between the node markers. | |
| Return nodes | |
| End Function |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Private Shared Sub VerifyParameterNodes(ByVal startNode As Node, ByVal endNode As Node) | |
| ' The order in which these checks are done is important. | |
| If startNode Is Nothing Then | |
| Throw New ArgumentException("Start node cannot be null") | |
| End If | |
| If endNode Is Nothing Then | |
| Throw New ArgumentException("End node cannot be null") | |
| End If | |
| If (Not startNode.Document.Equals(endNode.Document)) Then | |
| Throw New ArgumentException("Start node and end node must belong to the same document") | |
| End If | |
| If startNode.GetAncestor(NodeType.Body) Is Nothing OrElse endNode.GetAncestor(NodeType.Body) Is Nothing Then | |
| Throw New ArgumentException("Start node and end node must be a child or descendant of a body") | |
| End If | |
| ' Check the end node is after the start node in the DOM tree | |
| ' First check if they are in different sections, then if they' Re not check their position in the body of the same section they are in. | |
| Dim startSection As Section = CType(startNode.GetAncestor(NodeType.Section), Section) | |
| Dim endSection As Section = CType(endNode.GetAncestor(NodeType.Section), Section) | |
| Dim startIndex As Integer = startSection.ParentNode.IndexOf(startSection) | |
| Dim endIndex As Integer = endSection.ParentNode.IndexOf(endSection) | |
| If startIndex = endIndex Then | |
| If startSection.Body.IndexOf(startNode) > endSection.Body.IndexOf(endNode) Then | |
| Throw New ArgumentException("The end node must be after the start node in the body") | |
| End If | |
| ElseIf startIndex > endIndex Then | |
| Throw New ArgumentException("The section of end node must be after the section start node") | |
| End If | |
| End Sub | |
| ''' <summary> | |
| ''' Checks if a node passed is an inline node. | |
| ''' </summary> | |
| Private Shared Function IsInline(ByVal node As Node) As Boolean | |
| ' Test if the node is desendant of a Paragraph or Table node and also is not a paragraph or a table a paragraph inside a comment class which is decesant of a pararaph is possible. | |
| Return ((node.GetAncestor(NodeType.Paragraph) IsNot Nothing OrElse node.GetAncestor(NodeType.Table) IsNot Nothing) AndAlso Not (node.NodeType = NodeType.Paragraph OrElse node.NodeType = NodeType.Table)) | |
| End Function | |
| ''' <summary> | |
| ''' Removes the content before or after the marker in the cloned node depending on the type of marker. | |
| ''' </summary> | |
| Private Shared Sub ProcessMarker(ByVal cloneNode As CompositeNode, ByVal nodes As ArrayList, ByVal node As Node, ByVal isInclusive As Boolean, ByVal isStartMarker As Boolean, ByVal isEndMarker As Boolean) | |
| ' If we are dealing with a block level node just see if it should be included and add it to the list. | |
| If (Not IsInline(node)) Then | |
| ' Don' T add the node twice if the markers are the same node | |
| If Not (isStartMarker AndAlso isEndMarker) Then | |
| If isInclusive Then | |
| nodes.Add(cloneNode) | |
| End If | |
| End If | |
| Return | |
| End If | |
| ' If a marker is a FieldStart node check if it' S to be included or not. | |
| ' We assume for simplicity that the FieldStart and FieldEnd appear in the same paragraph. | |
| If node.NodeType = NodeType.FieldStart Then | |
| ' If the marker is a start node and is not be included then skip to the end of the field. | |
| ' If the marker is an end node and it is to be included then move to the end field so the field will not be removed. | |
| If (isStartMarker AndAlso (Not isInclusive)) OrElse ((Not isStartMarker) AndAlso isInclusive) Then | |
| Do While node.NextSibling IsNot Nothing AndAlso node.NodeType <> NodeType.FieldEnd | |
| node = node.NextSibling | |
| Loop | |
| End If | |
| End If | |
| ' If either marker is part of a comment then to include the comment itself we need to move the pointer forward to the Comment | |
| ' Node found after the CommentRangeEnd node. | |
| If node.NodeType = NodeType.CommentRangeEnd Then | |
| Do While node.NextSibling IsNot Nothing AndAlso node.NodeType <> NodeType.Comment | |
| node = node.NextSibling | |
| Loop | |
| End If | |
| ' Find the corresponding node in our cloned node by index and return it. | |
| ' If the start and end node are the same some child nodes might already have been removed. Subtract the | |
| ' Difference to get the right index. | |
| Dim indexDiff As Integer = node.ParentNode.ChildNodes.Count - cloneNode.ChildNodes.Count | |
| ' Child node count identical. | |
| If indexDiff = 0 Then | |
| node = cloneNode.ChildNodes(node.ParentNode.IndexOf(node)) | |
| Else | |
| node = cloneNode.ChildNodes(node.ParentNode.IndexOf(node) - indexDiff) | |
| End If | |
| ' Remove the nodes up to/from the marker. | |
| Dim isSkip As Boolean = False | |
| Dim isProcessing As Boolean = True | |
| Dim isRemoving As Boolean = isStartMarker | |
| Dim nextNode As Node = cloneNode.FirstChild | |
| Do While isProcessing AndAlso nextNode IsNot Nothing | |
| Dim currentNode As Node = nextNode | |
| isSkip = False | |
| If currentNode.Equals(node) Then | |
| If isStartMarker Then | |
| isProcessing = False | |
| If isInclusive Then | |
| isRemoving = False | |
| End If | |
| Else | |
| isRemoving = True | |
| If isInclusive Then | |
| isSkip = True | |
| End If | |
| End If | |
| End If | |
| nextNode = nextNode.NextSibling | |
| If isRemoving AndAlso (Not isSkip) Then | |
| currentNode.Remove() | |
| End If | |
| Loop | |
| ' After processing the composite node may become empty. If it has don' T include it. | |
| If Not (isStartMarker AndAlso isEndMarker) Then | |
| If cloneNode.HasChildNodes Then | |
| nodes.Add(cloneNode) | |
| End If | |
| End If | |
| End Sub |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Public Shared Function GenerateDocument(ByVal srcDoc As Document, ByVal nodes As ArrayList) As Document | |
| ' Create a blank document. | |
| Dim dstDoc As New Document() | |
| ' Remove the first paragraph from the empty document. | |
| dstDoc.FirstSection.Body.RemoveAllChildren() | |
| ' Import each node from the list into the new document. Keep the original formatting of the node. | |
| Dim importer As New NodeImporter(srcDoc, dstDoc, ImportFormatMode.KeepSourceFormatting) | |
| For Each node As Node In nodes | |
| Dim importNode As Node = importer.ImportNode(node, True) | |
| dstDoc.FirstSection.Body.AppendChild(importNode) | |
| Next node | |
| ' Return the generated document. | |
| Return dstDoc | |
| End Function |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document(dataDir & "TestFile.doc") | |
| Dim startPara As Paragraph = CType(doc.LastSection.GetChild(NodeType.Paragraph, 2, True), Paragraph) | |
| Dim endTable As Table = CType(doc.LastSection.GetChild(NodeType.Table, 0, True), Table) | |
| ' Extract the content between these nodes in the document. Include these markers in the extraction. | |
| Dim extractedNodes As ArrayList = ExtractContent(startPara, endTable, True) | |
| ' Lets reverse the array to make inserting the content back into the document easier. | |
| extractedNodes.Reverse() | |
| Do While extractedNodes.Count > 0 | |
| ' Insert the last node from the reversed list | |
| endTable.ParentNode.InsertAfter(CType(extractedNodes(0), Node), endTable) | |
| ' Remove this node from the list after insertion. | |
| extractedNodes.RemoveAt(0) | |
| Loop | |
| ' Save the generated document to disk. | |
| doc.Save(dataDir & "TestFile.DuplicatedContent_out.doc") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document(dataDir & "TestFile.doc") | |
| ' Retrieve the bookmark from the document. | |
| Dim bookmark As Aspose.Words.Bookmark = doc.Range.Bookmarks("Bookmark1") | |
| ' We use the BookmarkStart and BookmarkEnd nodes as markers. | |
| Dim bookmarkStart As BookmarkStart = bookmark.BookmarkStart | |
| Dim bookmarkEnd As BookmarkEnd = bookmark.BookmarkEnd | |
| ' Firstly extract the content between these nodes including the bookmark. | |
| Dim extractedNodesInclusive As ArrayList = ExtractContent(bookmarkStart, bookmarkEnd, True) | |
| Dim dstDoc As Document = GenerateDocument(doc, extractedNodesInclusive) | |
| dstDoc.Save(dataDir & "TestFile.BookmarkInclusive_out.doc") | |
| ' Secondly extract the content between these nodes this time without including the bookmark. | |
| Dim extractedNodesExclusive As ArrayList = ExtractContent(bookmarkStart, bookmarkEnd, False) | |
| dstDoc = GenerateDocument(doc, extractedNodesExclusive) | |
| dstDoc.Save(dataDir & "TestFile.BookmarkExclusive_out.doc") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document(dataDir & "TestFile.doc") | |
| ' This is a quick way of getting both comment nodes. | |
| ' Your code should have a proper method of retrieving each corresponding start and end node. | |
| Dim commentStart As CommentRangeStart = CType(doc.GetChild(NodeType.CommentRangeStart, 0, True), CommentRangeStart) | |
| Dim commentEnd As CommentRangeEnd = CType(doc.GetChild(NodeType.CommentRangeEnd, 0, True), CommentRangeEnd) | |
| ' Firstly extract the content between these nodes including the comment as well. | |
| Dim extractedNodesInclusive As ArrayList = ExtractContent(commentStart, commentEnd, True) | |
| Dim dstDoc As Document = GenerateDocument(doc, extractedNodesInclusive) | |
| dstDoc.Save(dataDir & "TestFile.CommentInclusive_out.doc") | |
| ' Secondly extract the content between these nodes without the comment. | |
| Dim extractedNodesExclusive As ArrayList = ExtractContent(commentStart, commentEnd, False) | |
| dstDoc = GenerateDocument(doc, extractedNodesExclusive) | |
| dataDir = dataDir & "TestFile.CommentExclusive_out.doc" | |
| dstDoc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' Load in the document | |
| Dim doc As New Document(dataDir & "TestFile.doc") | |
| ' Gather the nodes. The GetChild method uses 0-based index | |
| Dim startPara As Paragraph = CType(doc.FirstSection.GetChild(NodeType.Paragraph, 6, True), Paragraph) | |
| Dim endPara As Paragraph = CType(doc.FirstSection.GetChild(NodeType.Paragraph, 10, True), Paragraph) | |
| ' Extract the content between these nodes in the document. Include these markers in the extraction. | |
| Dim extractedNodes As ArrayList = ExtractContent(startPara, endPara, True) | |
| ' Insert the content into a new separate document and save it to disk. | |
| Dim dstDoc As Document = GenerateDocument(doc, extractedNodes) | |
| dstDoc.Save(dataDir & "TestFile.Paragraphs_out.doc") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' Load in the document | |
| Dim doc As New Document(dataDir & "TestFile.doc") | |
| ' Gather a list of the paragraphs using the respective heading styles. | |
| Dim parasStyleHeading1 As ArrayList = ParagraphsByStyleName(doc, "Heading 1") | |
| Dim parasStyleHeading3 As ArrayList = ParagraphsByStyleName(doc, "Heading 3") | |
| ' Use the first instance of the paragraphs with those styles. | |
| Dim startPara1 As Node = CType(parasStyleHeading1(0), Node) | |
| Dim endPara1 As Node = CType(parasStyleHeading3(0), Node) | |
| ' Extract the content between these nodes in the document. Don' T include these markers in the extraction. | |
| Dim extractedNodes As ArrayList = ExtractContent(startPara1, endPara1, False) | |
| ' Insert the content into a new separate document and save it to disk. | |
| Dim dstDoc As Document = GenerateDocument(doc, extractedNodes) | |
| dstDoc.Save(dataDir & "TestFile.Styles_out.doc") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' Load in the document | |
| Dim doc As New Document(dataDir & "TestFile.doc") | |
| ' Retrieve a paragraph from the first section. | |
| Dim para As Paragraph = CType(doc.GetChild(NodeType.Paragraph, 7, True), Paragraph) | |
| ' Use some runs for extraction. | |
| Dim startRun As Run = para.Runs(1) | |
| Dim endRun As Run = para.Runs(4) | |
| ' Extract the content between these nodes in the document. Include these markers in the extraction. | |
| Dim extractedNodes As ArrayList = ExtractContent(startRun, endRun, True) | |
| ' Get the node from the list. There should only be one paragraph returned in the list. | |
| Dim node As Node = CType(extractedNodes(0), Node) | |
| ' Print the text of this node to the console. | |
| Console.WriteLine(node.ToString(SaveFormat.Text)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document(dataDir & "TestFile.doc") | |
| ' Use a document builder to retrieve the field start of a merge field. | |
| Dim builder As New DocumentBuilder(doc) | |
| ' Pass the first boolean parameter to get the DocumentBuilder to move to the FieldStart of the field. | |
| ' We could also get FieldStarts of a field using GetChildNode method as in the other examples. | |
| builder.MoveToMergeField("Fullname", False, False) | |
| ' The builder cursor should be positioned at the start of the field. | |
| Dim startField As FieldStart = CType(builder.CurrentNode, FieldStart) | |
| Dim endPara As Paragraph = CType(doc.FirstSection.GetChild(NodeType.Paragraph, 5, True), Paragraph) | |
| ' Extract the content between these nodes in the document. Don' T include these markers in the extraction. | |
| Dim extractedNodes As ArrayList = ExtractContent(startField, endPara, False) | |
| ' Insert the content into a new separate document and save it to disk. | |
| Dim dstDoc As Document = GenerateDocument(doc, extractedNodes) | |
| dstDoc.Save(dataDir & "TestFile.Fields_out.pdf") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithDocument() | |
| ' Open the document we want to convert. | |
| Dim doc As New Document(dataDir & Convert.ToString("Visitor.ToText.doc")) | |
| ' Create an object that inherits from the DocumentVisitor class. | |
| Dim myConverter As New MyDocToTxtWriter() | |
| ' This is the well known Visitor pattern. Get the model to accept a visitor. | |
| ' The model will iterate through itself by calling the corresponding methods | |
| ' On the visitor object (this is called visiting). | |
| ' | |
| ' Note that every node in the object model has the Accept method so the visiting | |
| ' Can be executed not only for the whole document, but for any node in the document. | |
| doc.Accept(myConverter) | |
| ' Once the visiting is complete, we can retrieve the result of the operation, | |
| ' That in this example, has accumulated in the visitor. | |
| Console.WriteLine(myConverter.GetText()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ''' <summary> | |
| ''' Simple implementation of saving a document in the plain text format. Implemented as a Visitor. | |
| ''' </summary> | |
| Friend Class MyDocToTxtWriter | |
| Inherits DocumentVisitor | |
| Public Sub New() | |
| mIsSkipText = False | |
| mBuilder = New StringBuilder() | |
| End Sub | |
| ''' <summary> | |
| ''' Gets the plain text of the document that was accumulated by the visitor. | |
| ''' </summary> | |
| Public Function GetText() As String | |
| Return mBuilder.ToString() | |
| End Function | |
| ''' <summary> | |
| ''' Called when a Run node is encountered in the document. | |
| ''' </summary> | |
| Public Overrides Function VisitRun(run As Run) As VisitorAction | |
| AppendText(run.Text) | |
| ' Let the visitor continue visiting other nodes. | |
| Return VisitorAction.[Continue] | |
| End Function | |
| ''' <summary> | |
| ''' Called when a FieldStart node is encountered in the document. | |
| ''' </summary> | |
| Public Overrides Function VisitFieldStart(fieldStart As FieldStart) As VisitorAction | |
| ' In Microsoft Word, a field code (such as "MERGEFIELD FieldName") follows | |
| ' After a field start character. We want to skip field codes and output field | |
| ' Result only, therefore we use a flag to suspend the output while inside a field code. | |
| ' | |
| ' Note this is a very simplistic implementation and will not work very well | |
| ' If you have nested fields in a document. | |
| mIsSkipText = True | |
| Return VisitorAction.[Continue] | |
| End Function | |
| ''' <summary> | |
| ''' Called when a FieldSeparator node is encountered in the document. | |
| ''' </summary> | |
| Public Overrides Function VisitFieldSeparator(fieldSeparator As FieldSeparator) As VisitorAction | |
| ' Once reached a field separator node, we enable the output because we are | |
| ' Now entering the field result nodes. | |
| mIsSkipText = False | |
| Return VisitorAction.[Continue] | |
| End Function | |
| ''' <summary> | |
| ''' Called when a FieldEnd node is encountered in the document. | |
| ''' </summary> | |
| Public Overrides Function VisitFieldEnd(fieldEnd As FieldEnd) As VisitorAction | |
| ' Make sure we enable the output when reached a field end because some fields | |
| ' Do not have field separator and do not have field result. | |
| mIsSkipText = False | |
| Return VisitorAction.[Continue] | |
| End Function | |
| ''' <summary> | |
| ''' Called when visiting of a Paragraph node is ended in the document. | |
| ''' </summary> | |
| Public Overrides Function VisitParagraphEnd(paragraph As Paragraph) As VisitorAction | |
| ' When outputting to plain text we output Cr+Lf characters. | |
| AppendText(ControlChar.CrLf) | |
| Return VisitorAction.[Continue] | |
| End Function | |
| Public Overrides Function VisitBodyStart(body As Body) As VisitorAction | |
| ' We can detect beginning and end of all composite nodes such as Section, Body, | |
| ' Table, Paragraph etc and provide custom handling for them. | |
| mBuilder.Append("*** Body Started ***" & vbCr & vbLf) | |
| Return VisitorAction.[Continue] | |
| End Function | |
| Public Overrides Function VisitBodyEnd(body As Body) As VisitorAction | |
| mBuilder.Append("*** Body Ended ***" & vbCr & vbLf) | |
| Return VisitorAction.[Continue] | |
| End Function | |
| ''' <summary> | |
| ''' Called when a HeaderFooter node is encountered in the document. | |
| ''' </summary> | |
| Public Overrides Function VisitHeaderFooterStart(headerFooter As HeaderFooter) As VisitorAction | |
| ' Returning this value from a visitor method causes visiting of this | |
| ' Node to stop and move on to visiting the next sibling node. | |
| ' The net effect in this example is that the text of headers and footers | |
| ' Is not included in the resulting output. | |
| Return VisitorAction.SkipThisNode | |
| End Function | |
| ''' <summary> | |
| ''' Adds text to the current output. Honours the enabled/disabled output flag. | |
| ''' </summary> | |
| Private Sub AppendText(text As String) | |
| If Not mIsSkipText Then | |
| mBuilder.Append(text) | |
| End If | |
| End Sub | |
| Private ReadOnly mBuilder As StringBuilder | |
| Private mIsSkipText As Boolean | |
| End Class |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document() | |
| ' Enter a dummy field into the document. | |
| Dim builder As New DocumentBuilder(doc) | |
| builder.InsertField("MERGEFIELD Field") | |
| ' GetText will retrieve all field codes and special characters | |
| Console.WriteLine("GetText() Result: " + doc.GetText()) | |
| ' ToString will export the node to the specified format. When converted to text it will not retrieve fields code | |
| ' Or special characters, but will still contain some natural formatting characters such as paragraph markers etc. | |
| ' This is the same as "viewing" the document as if it was opened in a text editor. | |
| Console.WriteLine("ToString() Result: " + doc.ToString(SaveFormat.Text)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithDocument() | |
| Dim doc As New Document(dataDir & Convert.ToString("Document.doc")) | |
| ' Set custom barcode generator | |
| doc.FieldOptions.BarcodeGenerator = New CustomBarcodeGenerator() | |
| doc.Save(dataDir & Convert.ToString("GenerateACustomBarCodeImage_out.pdf")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Public Class CustomBarcodeGenerator | |
| Implements IBarcodeGenerator | |
| ' Converts barcode type from Word to Aspose.BarCode. | |
| Private Shared Function ConvertBarcodeType(inputCode As String) As Symbology | |
| If inputCode Is Nothing Then | |
| Return Integer.MinValue | |
| End If | |
| Dim type As String = inputCode.ToUpper() | |
| Select Case type | |
| Case "QR" | |
| Return Symbology.QR | |
| Case "CODE128" | |
| Return Symbology.Code128 | |
| Case "CODE39" | |
| Return Symbology.Code39Standard | |
| Case "EAN8" | |
| Return Symbology.EAN8 | |
| Case "EAN13" | |
| Return Symbology.EAN13 | |
| Case "UPCA" | |
| Return Symbology.UPCA | |
| Case "UPCE" | |
| Return Symbology.UPCE | |
| Case "ITF14" | |
| Return Symbology.ITF14 | |
| Case "CASE" | |
| Exit Select | |
| End Select | |
| Return Integer.MinValue | |
| End Function | |
| ' Converts barcode image height from Word units to Aspose.BarCode units. | |
| Private Shared Function ConvertSymbolHeight(heightInTwipsString As String) As Single | |
| ' Input value is in 1/1440 inches (twips) | |
| Dim heightInTwips As Integer = Integer.MinValue | |
| Integer.TryParse(heightInTwipsString, heightInTwips) | |
| If heightInTwips = Integer.MinValue Then | |
| Throw New Exception((Convert.ToString("Error! Incorrect height - ") & heightInTwipsString) + ".") | |
| End If | |
| ' Convert to mm | |
| Return CSng(heightInTwips * 25.4 / 1440) | |
| End Function | |
| ' Converts barcode image color from Word to Aspose.BarCode. | |
| Private Shared Function ConvertColor(inputColor As String) As Color | |
| ' Input should be from "0x000000" to "0xFFFFFF" | |
| Dim color__1 As Integer = Integer.MinValue | |
| Integer.TryParse(inputColor.Replace("0x", ""), color__1) | |
| If color__1 = Integer.MinValue Then | |
| Throw New Exception((Convert.ToString("Error! Incorrect color - ") & inputColor) + ".") | |
| End If | |
| Return Color.FromArgb(color__1 >> 16, (color__1 And &HFF00) >> 8, color__1 And &HFF) | |
| ' Backword conversion - | |
| 'return string.Format("0x{0,6:X6}", mControl.ForeColor.ToArgb() & 0xFFFFFF); | |
| End Function | |
| ' Converts bar code scaling factor from percents to float. | |
| Private Shared Function ConvertScalingFactor(scalingFactor As String) As Single | |
| Dim isParsed As Boolean = False | |
| Dim percents As Integer = Integer.MinValue | |
| Integer.TryParse(scalingFactor, percents) | |
| If percents <> Integer.MinValue Then | |
| If percents >= 10 AndAlso percents <= 10000 Then | |
| isParsed = True | |
| End If | |
| End If | |
| If Not isParsed Then | |
| Throw New Exception((Convert.ToString("Error! Incorrect scaling factor - ") & scalingFactor) + ".") | |
| End If | |
| Return percents / 100.0F | |
| End Function | |
| ' Implementation of the GetBarCodeImage() method for IBarCodeGenerator interface. | |
| Public Function GetBarcodeImage(parameters As BarcodeParameters) As Image | |
| If parameters.BarcodeType Is Nothing OrElse parameters.BarcodeValue Is Nothing Then | |
| Return Nothing | |
| End If | |
| Dim builder As New BarCodeBuilder() | |
| builder.SymbologyType = ConvertBarcodeType(parameters.BarcodeType) | |
| If builder.SymbologyType = CType(Integer.MinValue, Symbology) Then | |
| Return Nothing | |
| End If | |
| builder.CodeText = parameters.BarcodeValue | |
| If builder.SymbologyType = Symbology.QR Then | |
| builder.Display2DText = parameters.BarcodeValue | |
| End If | |
| If parameters.ForegroundColor IsNot Nothing Then | |
| builder.ForeColor = ConvertColor(parameters.ForegroundColor) | |
| End If | |
| If parameters.BackgroundColor IsNot Nothing Then | |
| builder.BackColor = ConvertColor(parameters.BackgroundColor) | |
| End If | |
| If parameters.SymbolHeight IsNot Nothing Then | |
| builder.ImageHeight = ConvertSymbolHeight(parameters.SymbolHeight) | |
| builder.AutoSize = False | |
| End If | |
| builder.CodeLocation = CodeLocation.None | |
| If parameters.DisplayText Then | |
| builder.CodeLocation = CodeLocation.Below | |
| End If | |
| builder.CaptionAbove.Text = "" | |
| Const scale As Single = 0.4F | |
| ' Empiric scaling factor for converting Word barcode to Aspose.BarCode | |
| Dim xdim As Single = 1.0F | |
| If builder.SymbologyType = Symbology.QR Then | |
| builder.AutoSize = False | |
| builder.ImageWidth *= scale | |
| builder.ImageHeight = builder.ImageWidth | |
| xdim = builder.ImageHeight / 25 | |
| builder.xDimension = InlineAssignHelper(builder.yDimension, xdim) | |
| End If | |
| If parameters.ScalingFactor IsNot Nothing Then | |
| Dim scalingFactor As Single = ConvertScalingFactor(parameters.ScalingFactor) | |
| builder.ImageHeight *= scalingFactor | |
| If builder.SymbologyType = Symbology.QR Then | |
| builder.ImageWidth = builder.ImageHeight | |
| builder.xDimension = InlineAssignHelper(builder.yDimension, xdim * scalingFactor) | |
| End If | |
| builder.AutoSize = False | |
| End If | |
| Return builder.BarCodeImage | |
| End Function | |
| Private Function IBarcodeGenerator_GetBarcodeImage(parameters As BarcodeParameters) As Image Implements IBarcodeGenerator.GetBarcodeImage | |
| Throw New NotImplementedException() | |
| End Function | |
| Public Function GetOldBarcodeImage(parameters As BarcodeParameters) As Image | |
| Throw New NotImplementedException() | |
| End Function | |
| Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, value As T) As T | |
| target = value | |
| Return value | |
| End Function | |
| Private Function IBarcodeGenerator_GetOldBarcodeImage(parameters As BarcodeParameters) As Image Implements IBarcodeGenerator.GetOldBarcodeImage | |
| Throw New NotImplementedException() | |
| End Function | |
| End Class |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithDocument() | |
| ' Load the template document. | |
| Dim doc As New Document(dataDir & Convert.ToString("TestFile.doc")) | |
| Dim variables As String = "" | |
| For Each entry As DictionaryEntry In doc.Variables | |
| Dim name As String = entry.Key.ToString() | |
| Dim value As String = entry.Value.ToString() | |
| If variables = "" Then | |
| ' Do something useful. | |
| variables = Convert.ToString((Convert.ToString("Name: ") & name) + "," + "Value: {1}") & value | |
| Else | |
| variables = Convert.ToString((Convert.ToString(variables & Convert.ToString("Name: ")) & name) + "," + "Value: {1}") & value | |
| End If | |
| Next |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ''' <summary> | |
| ''' Inserts content of the external document after the specified node. | |
| ''' Section breaks and section formatting of the inserted document are ignored. | |
| ''' </summary> | |
| ''' <param name="insertAfterNode">Node in the destination document after which the content | |
| ''' Should be inserted. This node should be a block level node (paragraph or table).</param> | |
| ''' <param name="srcDoc">The document to insert.</param> | |
| Private Shared Sub InsertDocument(insertAfterNode As Node, srcDoc As Document) | |
| ' Make sure that the node is either a paragraph or table. | |
| If (Not insertAfterNode.NodeType.Equals(NodeType.Paragraph)) And (Not insertAfterNode.NodeType.Equals(NodeType.Table)) Then | |
| Throw New ArgumentException("The destination node should be either a paragraph or table.") | |
| End If | |
| ' We will be inserting into the parent of the destination paragraph. | |
| Dim dstStory As CompositeNode = insertAfterNode.ParentNode | |
| ' This object will be translating styles and lists during the import. | |
| Dim importer As New NodeImporter(srcDoc, insertAfterNode.Document, ImportFormatMode.KeepSourceFormatting) | |
| ' Loop through all sections in the source document. | |
| For Each srcSection As Section In srcDoc.Sections | |
| ' Loop through all block level nodes (paragraphs and tables) in the body of the section. | |
| For Each srcNode As Node In srcSection.Body | |
| ' Let' S skip the node if it is a last empty paragraph in a section. | |
| If srcNode.NodeType.Equals(NodeType.Paragraph) Then | |
| Dim para As Paragraph = DirectCast(srcNode, Paragraph) | |
| If para.IsEndOfSection AndAlso Not para.HasChildNodes Then | |
| Continue For | |
| End If | |
| End If | |
| ' This creates a clone of the node, suitable for insertion into the destination document. | |
| Dim newNode As Node = importer.ImportNode(srcNode, True) | |
| ' Insert new node after the reference node. | |
| dstStory.InsertAfter(newNode, insertAfterNode) | |
| insertAfterNode = newNode | |
| Next | |
| Next | |
| End Sub |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim mainDoc As New Document(dataDir & Convert.ToString("InsertDocument1.doc")) | |
| Dim subDoc As New Document(dataDir & Convert.ToString("InsertDocument2.doc")) | |
| Dim bookmark As Bookmark = mainDoc.Range.Bookmarks("insertionPlace") | |
| InsertDocument(bookmark.BookmarkStart.ParentNode, subDoc) | |
| dataDir = dataDir & Convert.ToString("InsertDocumentAtBookmark_out.doc") | |
| mainDoc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' Open the main document. | |
| Dim mainDoc As New Document(dataDir & Convert.ToString("InsertDocument1.doc")) | |
| ' Add a handler to MergeField event | |
| mainDoc.MailMerge.FieldMergingCallback = New InsertDocumentAtMailMergeHandler() | |
| ' The main document has a merge field in it called "Document_1". | |
| ' The corresponding data for this field contains fully qualified path to the document | |
| ' That should be inserted to this field. | |
| mainDoc.MailMerge.Execute(New String() {"Document_1"}, New String() {dataDir & Convert.ToString("InsertDocument2.doc")}) | |
| dataDir = dataDir & Convert.ToString("InsertDocumentAtMailMerge_out.doc") | |
| mainDoc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Private Class InsertDocumentAtMailMergeBlobHandler | |
| Implements IFieldMergingCallback | |
| ''' <summary> | |
| ''' This handler makes special processing for the "Document_1" field. | |
| ''' The field value contains the path to load the document. | |
| ''' We load the document and insert it into the current merge field. | |
| ''' </summary> | |
| Private Sub IFieldMergingCallback_FieldMerging(e As FieldMergingArgs) Implements IFieldMergingCallback.FieldMerging | |
| If e.DocumentFieldName = "Document_1" Then | |
| ' Use document builder to navigate to the merge field with the specified name. | |
| Dim builder As New DocumentBuilder(e.Document) | |
| builder.MoveToMergeField(e.DocumentFieldName) | |
| ' Load the document from the blob field. | |
| Dim stream As New MemoryStream(DirectCast(e.FieldValue, Byte())) | |
| Dim subDoc As New Document(stream) | |
| ' Insert the document. | |
| InsertDocument(builder.CurrentParagraph, subDoc) | |
| ' The paragraph that contained the merge field might be empty now and you probably want to delete it. | |
| If Not builder.CurrentParagraph.HasChildNodes Then | |
| builder.CurrentParagraph.Remove() | |
| End If | |
| ' Indicate to the mail merge engine that we have inserted what we wanted. | |
| e.Text = Nothing | |
| End If | |
| End Sub | |
| Private Sub IFieldMergingCallback_ImageFieldMerging(args As ImageFieldMergingArgs) Implements IFieldMergingCallback.ImageFieldMerging | |
| ' Do nothing. | |
| End Sub | |
| End Class |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Private Class InsertDocumentAtMailMergeHandler | |
| Implements IFieldMergingCallback | |
| ''' <summary> | |
| ''' This handler makes special processing for the "Document_1" field. | |
| ''' The field value contains the path to load the document. | |
| ''' We load the document and insert it into the current merge field. | |
| ''' </summary> | |
| Private Sub IFieldMergingCallback_FieldMerging(e As FieldMergingArgs) Implements IFieldMergingCallback.FieldMerging | |
| If e.DocumentFieldName = "Document_1" Then | |
| ' Use document builder to navigate to the merge field with the specified name. | |
| Dim builder As New DocumentBuilder(e.Document) | |
| builder.MoveToMergeField(e.DocumentFieldName) | |
| ' The name of the document to load and insert is stored in the field value. | |
| Dim subDoc As New Aspose.Words.Document(DirectCast(e.FieldValue, String)) | |
| ' Insert the document. | |
| InsertDocument(builder.CurrentParagraph, subDoc) | |
| ' The paragraph that contained the merge field might be empty now and you probably want to delete it. | |
| If Not builder.CurrentParagraph.HasChildNodes Then | |
| builder.CurrentParagraph.Remove() | |
| End If | |
| ' Indicate to the mail merge engine that we have inserted what we wanted. | |
| e.Text = Nothing | |
| End If | |
| End Sub | |
| Private Sub IFieldMergingCallback_ImageFieldMerging(args As ImageFieldMergingArgs) Implements IFieldMergingCallback.ImageFieldMerging | |
| ' Do nothing. | |
| End Sub | |
| End Class |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim mainDoc As New Document(dataDir & Convert.ToString("InsertDocument1.doc")) | |
| Dim options As New FindReplaceOptions() | |
| options.ReplacingCallback = New InsertDocumentAtReplaceHandler() | |
| mainDoc.Range.Replace(New Regex("\[MY_DOCUMENT\]"), "", options) | |
| dataDir = dataDir & Convert.ToString("InsertDocumentAtReplace_out.doc") | |
| mainDoc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Private Class InsertDocumentAtReplaceHandler | |
| Implements IReplacingCallback | |
| Private Function IReplacingCallback_Replacing(e As ReplacingArgs) As ReplaceAction Implements IReplacingCallback.Replacing | |
| Dim subDoc As New Document(RunExamples.GetDataDir_WorkingWithDocument() + "InsertDocument2.doc") | |
| ' Insert a document after the paragraph, containing the match text. | |
| Dim para As Paragraph = DirectCast(e.MatchNode.ParentNode, Paragraph) | |
| InsertDocument(para, subDoc) | |
| ' Remove the paragraph with the match text. | |
| para.Remove() | |
| Return ReplaceAction.Skip | |
| End Function | |
| End Class |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ''' <summary> | |
| ''' Inserts content of the external document after the specified node. | |
| ''' </summary> | |
| ''' <param name="insertAfterNode">Node in the destination document after which the content | |
| ''' Should be inserted. This node should be a block level node (paragraph or table).</param> | |
| ''' <param name="srcDoc">The document to insert.</param> | |
| Private Shared Sub InsertDocumentWithSectionFormatting(insertAfterNode As Node, srcDoc As Document) | |
| ' Make sure that the node is either a pargraph or table. | |
| If (Not insertAfterNode.NodeType.Equals(NodeType.Paragraph)) And (Not insertAfterNode.NodeType.Equals(NodeType.Table)) Then | |
| Throw New ArgumentException("The destination node should be either a paragraph or table.") | |
| End If | |
| ' Document to insert srcDoc into. | |
| Dim dstDoc As Document = DirectCast(insertAfterNode.Document, Document) | |
| ' To retain section formatting, split the current section into two at the marker node and then import the content from srcDoc as whole sections. | |
| ' The section of the node which the insert marker node belongs to | |
| Dim currentSection As Section = DirectCast(insertAfterNode.GetAncestor(NodeType.Section), Section) | |
| ' Don' T clone the content inside the section, we just want the properties of the section retained. | |
| Dim cloneSection As Section = DirectCast(currentSection.Clone(False), Section) | |
| ' However make sure the clone section has a body, but no empty first paragraph. | |
| cloneSection.EnsureMinimum() | |
| cloneSection.Body.FirstParagraph.Remove() | |
| ' Insert the cloned section into the document after the original section. | |
| insertAfterNode.Document.InsertAfter(cloneSection, currentSection) | |
| ' Append all nodes after the marker node to the new section. This will split the content at the section level at | |
| ' The marker so the sections from the other document can be inserted directly. | |
| Dim currentNode As Node = insertAfterNode.NextSibling | |
| While currentNode IsNot Nothing | |
| Dim nextNode As Node = currentNode.NextSibling | |
| cloneSection.Body.AppendChild(currentNode) | |
| currentNode = nextNode | |
| End While | |
| ' This object will be translating styles and lists during the import. | |
| Dim importer As New NodeImporter(srcDoc, dstDoc, ImportFormatMode.UseDestinationStyles) | |
| ' Loop through all sections in the source document. | |
| For Each srcSection As Section In srcDoc.Sections | |
| Dim newNode As Node = importer.ImportNode(srcSection, True) | |
| ' Append each section to the destination document. Start by inserting it after the split section. | |
| dstDoc.InsertAfter(newNode, currentSection) | |
| currentSection = DirectCast(newNode, Section) | |
| Next | |
| End Sub |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document(inputFileName) | |
| Dim protectionType As ProtectionType = doc.ProtectionType |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document(inputFileName) | |
| doc.Protect(ProtectionType.AllowOnlyFormFields, "password") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document(inputFileName) | |
| doc.Unprotect() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim fileName As String = "TestFile.doc" | |
| ' Open the document. | |
| Dim doc As New Document(dataDir & fileName) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Private Shared Sub RemovePageBreaks(ByVal doc As Document) | |
| ' Retrieve all paragraphs in the document. | |
| Dim paragraphs As NodeCollection = doc.GetChildNodes(NodeType.Paragraph, True) | |
| ' Iterate through all paragraphs | |
| For Each para As Paragraph In paragraphs | |
| ' If the paragraph has a page break before set then clear it. | |
| If para.ParagraphFormat.PageBreakBefore Then | |
| para.ParagraphFormat.PageBreakBefore = False | |
| End If | |
| ' Check all runs in the paragraph for page breaks and remove them. | |
| For Each run As Run In para.Runs | |
| If run.Text.Contains(ControlChar.PageBreak) Then | |
| run.Text = run.Text.Replace(ControlChar.PageBreak, String.Empty) | |
| End If | |
| Next run | |
| Next para | |
| End Sub |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Private Shared Sub RemoveSectionBreaks(ByVal doc As Document) | |
| ' Loop through all sections starting from the section that precedes the last one | |
| ' And moving to the first section. | |
| For i As Integer = doc.Sections.Count - 2 To 0 Step -1 | |
| ' Copy the content of the current section to the beginning of the last section. | |
| doc.LastSection.PrependContent(doc.Sections(i)) | |
| ' Remove the copied section. | |
| doc.Sections(i).Remove() | |
| Next i | |
| End Sub |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithStyles() | |
| ' Open a document which contains a TOC. | |
| Dim doc As New Document(dataDir & Convert.ToString("Document.TableOfContents.doc")) | |
| ' Remove the first table of contents from the document. | |
| RemoveTableOfContents(doc, 0) | |
| dataDir = dataDir & Convert.ToString("Document.TableOfContentsRemoveToc_out.doc") | |
| ' Save the output. | |
| doc.Save(dataDir) | |
| Console.WriteLine(Convert.ToString(vbLf & "Specified TOC from a document removed successfully." & vbLf & "File saved at ") & dataDir) | |
| End Sub | |
| ''' <summary> | |
| ''' Removes the specified table of contents field from the document. | |
| ''' </summary> | |
| ''' <param name="doc">The document to remove the field from.</param> | |
| ''' <param name="index">The zero-based index of the TOC to remove.</param> | |
| Public Shared Sub RemoveTableOfContents(doc As Document, index As Integer) | |
| ' Store the FieldStart nodes of TOC fields in the document for quick access. | |
| Dim fieldStarts As New ArrayList() | |
| ' This is a list to store the nodes found inside the specified TOC. They will be removed | |
| ' At the end of this method. | |
| Dim nodeList As New ArrayList() | |
| For Each start As FieldStart In doc.GetChildNodes(NodeType.FieldStart, True) | |
| If start.FieldType = FieldType.FieldTOC Then | |
| ' Add all FieldStarts which are of type FieldTOC. | |
| fieldStarts.Add(start) | |
| End If | |
| Next | |
| ' Ensure the TOC specified by the passed index exists. | |
| If index > fieldStarts.Count - 1 Then | |
| Throw New ArgumentOutOfRangeException("TOC index is out of range") | |
| End If | |
| Dim isRemoving As Boolean = True | |
| ' Get the FieldStart of the specified TOC. | |
| Dim currentNode As Node = DirectCast(fieldStarts(index), Node) | |
| While isRemoving | |
| ' It is safer to store these nodes and delete them all at once later. | |
| nodeList.Add(currentNode) | |
| currentNode = currentNode.NextPreOrder(doc) | |
| ' Once we encounter a FieldEnd node of type FieldTOC then we know we are at the end | |
| ' Of the current TOC and we can stop here. | |
| If currentNode.NodeType = NodeType.FieldEnd Then | |
| Dim fieldEnd As FieldEnd = DirectCast(currentNode, FieldEnd) | |
| If fieldEnd.FieldType = FieldType.FieldTOC Then | |
| isRemoving = False | |
| End If | |
| End If | |
| End While | |
| ' Remove all nodes found in the specified TOC. | |
| For Each node As Node In nodeList | |
| node.Remove() | |
| Next | |
| End Sub |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithDocument() | |
| Dim doc As New Document() | |
| Dim sdtRichText As New StructuredDocumentTag(doc, SdtType.RichText, MarkupLevel.Block) | |
| Dim para As New Paragraph(doc) | |
| Dim run As New Run(doc) | |
| run.Text = "Hello World" | |
| run.Font.Color = Color.Green | |
| para.Runs.Add(run) | |
| sdtRichText.ChildNodes.Add(para) | |
| doc.FirstSection.Body.AppendChild(sdtRichText) | |
| dataDir = dataDir & Convert.ToString("RichTextBoxContentControl_out.docx") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithDocument() | |
| ' Load the template document. | |
| Dim doc As New Document(dataDir & Convert.ToString("TestFile.doc")) | |
| ' Set view option. | |
| doc.ViewOptions.ViewType = ViewType.PageLayout | |
| doc.ViewOptions.ZoomPercent = 50 | |
| dataDir = dataDir & Convert.ToString("TestFile.SetZoom_out.doc") | |
| ' Save the finished document. | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' Open an existing document | |
| Dim doc As New Document(dataDir & Convert.ToString("CheckBoxTypeContentControl.docx")) | |
| For Each sdt As StructuredDocumentTag In doc.GetChildNodes(NodeType.StructuredDocumentTag, True) | |
| If sdt.SdtType = SdtType.PlainText Then | |
| sdt.RemoveAllChildren() | |
| Dim para As Paragraph = TryCast(sdt.AppendChild(New Paragraph(doc)), Paragraph) | |
| Dim run As New Run(doc, "new text goes here") | |
| para.AppendChild(run) | |
| ElseIf sdt.SdtType = SdtType.DropDownList Then | |
| Dim secondItem As SdtListItem = sdt.ListItems(2) | |
| sdt.ListItems.SelectedValue = secondItem | |
| ElseIf sdt.SdtType = SdtType.Picture Then | |
| Dim shape As Shape = DirectCast(sdt.GetChild(NodeType.Shape, 0, True), Shape) | |
| If shape.HasImage Then | |
| shape.ImageData.SetImage(dataDir & Convert.ToString("Watermark.png")) | |
| End If | |
| End If | |
| Next | |
| dataDir = dataDir & Convert.ToString("ModifyContentControls_out.docx") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' Open an existing document | |
| Dim doc As New Document(dataDir & Convert.ToString("CheckBoxTypeContentControl.docx")) | |
| Dim builder As New DocumentBuilder(doc) | |
| ' Get the first content control from the document | |
| Dim SdtCheckBox As StructuredDocumentTag = DirectCast(doc.GetChild(NodeType.StructuredDocumentTag, 0, True), StructuredDocumentTag) | |
| ' StructuredDocumentTag.Checked property gets/sets current state of the Checkbox SDT | |
| If SdtCheckBox.SdtType = SdtType.Checkbox Then | |
| SdtCheckBox.Checked = True | |
| End If | |
| dataDir = dataDir & Convert.ToString("SetCurrentStateOfCheckBox_out.docx") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithDocument() | |
| ' Initialize document. | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| ' Specify font formatting before adding text. | |
| Dim font As Aspose.Words.Font = builder.Font | |
| font.Size = 16 | |
| font.Bold = True | |
| font.Color = Color.Blue | |
| font.Name = "Arial" | |
| font.Underline = Underline.Dash | |
| builder.Write("Sample text.") | |
| dataDir = dataDir & Convert.ToString("WriteAndFont_out.doc") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithFields() | |
| ' We will test this functionality creating a document with two fields with date formatting | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| ' Insert content with German locale. | |
| builder.Font.LocaleId = 1031 | |
| builder.InsertField("MERGEFIELD Date1 \@ ""dddd, d MMMM yyyy""") | |
| builder.Write(" - ") | |
| builder.InsertField("MERGEFIELD Date2 \@ ""dddd, d MMMM yyyy""") | |
| ' Shows how to specify where the culture used for date formatting during field update and mail merge is chosen from. | |
| ' Set the culture used during field update to the culture used by the field. | |
| doc.FieldOptions.FieldUpdateCultureSource = FieldUpdateCultureSource.FieldCode | |
| doc.MailMerge.Execute(New String() {"Date2"}, New Object() {New DateTime(2011, 1, 1)}) | |
| dataDir = dataDir & Convert.ToString("Field.ChangeFieldUpdateCultureSource_out.doc") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| ' Insert content with German locale. | |
| builder.Font.LocaleId = 1031 | |
| builder.InsertField("MERGEFIELD Date1 \@ ""dddd, d MMMM yyyy""") | |
| builder.Write(" - ") | |
| builder.InsertField("MERGEFIELD Date2 \@ ""dddd, d MMMM yyyy""") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithFields() | |
| ' Create a blank document. | |
| Dim doc As New Document() | |
| Dim b As New DocumentBuilder(doc) | |
| b.InsertField("MERGEFIELD Date") | |
| ' Store the current culture so it can be set back once mail merge is complete. | |
| Dim currentCulture As CultureInfo = Thread.CurrentThread.CurrentCulture | |
| ' Set to German language so dates and numbers are formatted using this culture during mail merge. | |
| Thread.CurrentThread.CurrentCulture = New CultureInfo("de-DE") | |
| ' Execute mail merge. | |
| doc.MailMerge.Execute(New String() {"Date"}, New Object() {DateTime.Now}) | |
| ' Restore the original culture. | |
| Thread.CurrentThread.CurrentCulture = currentCulture | |
| doc.Save(dataDir & Convert.ToString("Field.ChangeLocale_out.doc")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithFields() | |
| Dim fileName As String = "TestFile.doc" | |
| Dim doc As New Document(dataDir & fileName) | |
| ' Pass the appropriate parameters to convert all IF fields encountered in the document (including headers and footers) to static text. | |
| FieldsHelper.ConvertFieldsToStaticText(doc, FieldType.FieldIf) | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| ' Save the document with fields transformed to disk. | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Public Class FieldsHelper | |
| Inherits DocumentVisitor | |
| ''' <summary> | |
| ''' Converts any fields of the specified type found in the descendants of the node into static text. | |
| ''' </summary> | |
| ''' <param name="compositeNode">The node in which all descendants of the specified FieldType will be converted to static text.</param> | |
| ''' <param name="targetFieldType">The FieldType of the field to convert to static text.</param> | |
| Public Shared Sub ConvertFieldsToStaticText(ByVal compositeNode As CompositeNode, ByVal targetFieldType As FieldType) | |
| Dim originalNodeText As String = compositeNode.ToString(SaveFormat.Text) ' ExSkip | |
| Dim helper As New FieldsHelper(targetFieldType) | |
| compositeNode.Accept(helper) | |
| Debug.Assert(originalNodeText.Equals(compositeNode.ToString(SaveFormat.Text)), "Error: Text of the node converted differs from the original") ' ExSkip | |
| For Each node As Node In compositeNode.GetChildNodes(NodeType.Any, True) ' ExSkip | |
| Debug.Assert(Not (TypeOf node Is FieldChar AndAlso (CType(node, FieldChar)).FieldType.Equals(targetFieldType)), "Error: A field node that should be removed still remains.") ' ExSkip | |
| Next node | |
| End Sub | |
| Private Sub New(ByVal targetFieldType As FieldType) | |
| mTargetFieldType = targetFieldType | |
| End Sub | |
| Public Overrides Function VisitFieldStart(ByVal fieldStart As FieldStart) As VisitorAction | |
| ' We must keep track of the starts and ends of fields incase of any nested fields. | |
| If fieldStart.FieldType.Equals(mTargetFieldType) Then | |
| mFieldDepth += 1 | |
| fieldStart.Remove() | |
| Else | |
| ' This removes the field start if it' S inside a field that is being converted. | |
| CheckDepthAndRemoveNode(fieldStart) | |
| End If | |
| Return VisitorAction.Continue | |
| End Function | |
| Public Overrides Function VisitFieldSeparator(ByVal fieldSeparator As FieldSeparator) As VisitorAction | |
| ' When visiting a field separator we should decrease the depth level. | |
| If fieldSeparator.FieldType.Equals(mTargetFieldType) Then | |
| mFieldDepth -= 1 | |
| fieldSeparator.Remove() | |
| Else | |
| ' This removes the field separator if it' S inside a field that is being converted. | |
| CheckDepthAndRemoveNode(fieldSeparator) | |
| End If | |
| Return VisitorAction.Continue | |
| End Function | |
| Public Overrides Function VisitFieldEnd(ByVal fieldEnd As FieldEnd) As VisitorAction | |
| If fieldEnd.FieldType.Equals(mTargetFieldType) Then | |
| fieldEnd.Remove() | |
| Else | |
| CheckDepthAndRemoveNode(fieldEnd) ' This removes the field end if it' S inside a field that is being converted. | |
| End If | |
| Return VisitorAction.Continue | |
| End Function | |
| Public Overrides Function VisitRun(ByVal run As Run) As VisitorAction | |
| ' Remove the run if it is between the FieldStart and FieldSeparator of the field being converted. | |
| CheckDepthAndRemoveNode(run) | |
| Return VisitorAction.Continue | |
| End Function | |
| Public Overrides Function VisitParagraphEnd(ByVal paragraph As Paragraph) As VisitorAction | |
| If mFieldDepth > 0 Then | |
| ' The field code that is being converted continues onto another paragraph. We | |
| ' Need to copy the remaining content from this paragraph onto the next paragraph. | |
| Dim nextParagraph As Node = paragraph.NextSibling | |
| ' Skip ahead to the next available paragraph. | |
| Do While nextParagraph IsNot Nothing AndAlso nextParagraph.NodeType <> NodeType.Paragraph | |
| nextParagraph = nextParagraph.NextSibling | |
| Loop | |
| ' Copy all of the nodes over. Keep a list of these nodes so we know not to remove them. | |
| Do While paragraph.HasChildNodes | |
| mNodesToSkip.Add(paragraph.LastChild) | |
| CType(nextParagraph, Paragraph).PrependChild(paragraph.LastChild) | |
| Loop | |
| paragraph.Remove() | |
| End If | |
| Return VisitorAction.Continue | |
| End Function | |
| Public Overrides Function VisitTableStart(ByVal table As Table) As VisitorAction | |
| CheckDepthAndRemoveNode(table) | |
| Return VisitorAction.Continue | |
| End Function | |
| ''' <summary> | |
| ''' Checks whether the node is inside a field or should be skipped and then removes it if necessary. | |
| ''' </summary> | |
| Private Sub CheckDepthAndRemoveNode(ByVal node As Node) | |
| If mFieldDepth > 0 AndAlso (Not mNodesToSkip.Contains(node)) Then | |
| node.Remove() | |
| End If | |
| End Sub | |
| Private mFieldDepth As Integer = 0 | |
| Private mNodesToSkip As New ArrayList() | |
| Private mTargetFieldType As FieldType | |
| End Class |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithFields() | |
| Dim fileName As String = "TestFile.doc" | |
| Dim doc As New Document(dataDir & fileName) | |
| ' Pass the appropriate parameters to convert all IF fields encountered in the document (including headers and footers) to static text. | |
| FieldsHelper.ConvertFieldsToStaticText(doc, FieldType.FieldIf) | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| ' Save the document with fields transformed to disk. | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithFields() | |
| Dim fileName As String = "TestFile.doc" | |
| Dim doc As New Document(dataDir & fileName) | |
| ' Pass the appropriate parameters to convert all IF fields to static text that are encountered only in the last | |
| ' Paragraph of the document. | |
| FieldsHelper.ConvertFieldsToStaticText(doc.FirstSection.Body.LastParagraph, FieldType.FieldIf) | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| ' Save the document with fields transformed to disk. | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithFields() | |
| Dim doc As New Document(dataDir & Convert.ToString("FormFields.doc")) | |
| Dim documentFormFields As FormFieldCollection = doc.Range.FormFields | |
| Dim formField1 As FormField = documentFormFields(3) | |
| Dim formField2 As FormField = documentFormFields("Text2") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithFields() | |
| Dim doc As New Document(dataDir & Convert.ToString("FormFields.doc")) | |
| Dim formFields As FormFieldCollection = doc.Range.FormFields | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithFields() | |
| Dim doc As New Document(dataDir & Convert.ToString("FormFields.doc")) | |
| Dim formField As FormField = doc.Range.FormFields(3) | |
| If formField.Type.Equals(FieldType.FieldFormTextInput) Then | |
| formField.Result = "My name is " + formField.Name | |
| End If |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document() | |
| ' Shows how to delete all merge fields from a document without executing mail merge. | |
| doc.MailMerge.DeleteFields() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document() | |
| ' Shows how to get names of all merge fields in a document. | |
| Dim fieldNames As String() = doc.MailMerge.GetFieldNames() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document() | |
| ' Shows how to add a mapping when a merge field in a document and a data field in a data source have different names. | |
| doc.MailMerge.MappedDataFields.Add("MyFieldName_InDocument", "MyFieldName_InDataSource") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithFields() | |
| Dim doc As New Document(dataDir & Convert.ToString("in.doc")) | |
| ' Get paragraph you want to append this Advance field to | |
| Dim para As Paragraph = DirectCast(doc.GetChildNodes(NodeType.Paragraph, True)(1), Paragraph) | |
| ' We want to insert an Advance field like this: | |
| ' { ADVANCE \\d 10 \\l 10 \\r -3.3 \\u 0 \\x 100 \\y 100 } | |
| ' Create instance of FieldAdvance class and lets build the above field code | |
| Dim field As FieldAdvance = DirectCast(para.AppendField(FieldType.FieldAdvance, False), FieldAdvance) | |
| ' { ADVANCE \\d 10 " } | |
| field.DownOffset = "10" | |
| ' { ADVANCE \\d 10 \\l 10 } | |
| field.LeftOffset = "10" | |
| ' { ADVANCE \\d 10 \\l 10 \\r -3.3 } | |
| field.RightOffset = "-3.3" | |
| ' { ADVANCE \\d 10 \\l 10 \\r -3.3 \\u 0 } | |
| field.UpOffset = "0" | |
| ' { ADVANCE \\d 10 \\l 10 \\r -3.3 \\u 0 \\x 100 } | |
| field.HorizontalPosition = "100" | |
| ' { ADVANCE \\d 10 \\l 10 \\r -3.3 \\u 0 \\x 100 \\y 100 } | |
| field.VerticalPosition = "100" | |
| ' Finally update this Advance field | |
| field.Update() | |
| dataDir = dataDir & Convert.ToString("InsertAdvanceFieldWithOutDocumentBuilder_out.doc") | |
| doc.Save(dataDir) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithFields() | |
| Dim doc As New Document(dataDir & Convert.ToString("in.doc")) | |
| ' Get paragraph you want to append this Ask field to | |
| Dim para As Paragraph = DirectCast(doc.GetChildNodes(NodeType.Paragraph, True)(1), Paragraph) | |
| ' We want to insert an Ask field like this: | |
| ' { ASK \"Test 1\" Test2 \\d Test3 \\o } | |
| ' Create instance of FieldAsk class and lets build the above field code | |
| Dim field As FieldAsk = DirectCast(para.AppendField(FieldType.FieldAsk, False), FieldAsk) | |
| ' { ASK \"Test 1\" " } | |
| field.BookmarkName = "Test 1" | |
| ' { ASK \"Test 1\" Test2 } | |
| field.PromptText = "Test2" | |
| ' { ASK \"Test 1\" Test2 \\d Test3 } | |
| field.DefaultResponse = "Test3" | |
| ' { ASK \"Test 1\" Test2 \\d Test3 \\o } | |
| field.PromptOnceOnMailMerge = True | |
| ' Finally update this Ask field | |
| field.Update() | |
| dataDir = dataDir & Convert.ToString("InsertASKFieldWithOutDocumentBuilder_out.doc") | |
| doc.Save(dataDir) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithFields() | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| builder.InsertField("MERGEFIELD MyFieldName \* MERGEFORMAT") | |
| dataDir = dataDir & Convert.ToString("InsertField_out.docx") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithFields() | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| Dim items As String() = {"One", "Two", "Three"} | |
| builder.InsertComboBox("DropDown", items, 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithFields() | |
| Dim doc As New Document(dataDir & Convert.ToString("in.doc")) | |
| Dim builder As New DocumentBuilder(doc) | |
| ' Get paragraph you want to append this merge field to | |
| Dim para As Paragraph = DirectCast(doc.GetChildNodes(NodeType.Paragraph, True)(1), Paragraph) | |
| ' Move cursor to this paragraph | |
| builder.MoveTo(para) | |
| ' We want to insert a mail merge address block like this: | |
| ' { ADDRESSBLOCK \\c 1 \\d \\e Test2 \\f Test3 \\l \"Test 4\" } | |
| ' Create instance of FieldAddressBlock class and lets build the above field code | |
| Dim field As FieldAddressBlock = DirectCast(builder.InsertField(FieldType.FieldAddressBlock, False), FieldAddressBlock) | |
| ' { ADDRESSBLOCK \\c 1" } | |
| field.IncludeCountryOrRegionName = "1" | |
| ' { ADDRESSBLOCK \\c 1 \\d" } | |
| field.FormatAddressOnCountryOrRegion = True | |
| ' { ADDRESSBLOCK \\c 1 \\d \\e Test2 } | |
| field.ExcludedCountryOrRegionName = "Test2" | |
| ' { ADDRESSBLOCK \\c 1 \\d \\e Test2 \\f Test3 } | |
| field.NameAndAddressFormat = "Test3" | |
| ' { ADDRESSBLOCK \\c 1 \\d \\e Test2 \\f Test3 \\l \"Test 4\" } | |
| field.LanguageId = "Test 4" | |
| ' Finally update this merge field | |
| field.Update() | |
| dataDir = dataDir & Convert.ToString("InsertMailMergeAddressBlockFieldUsingDOM_out.doc") | |
| doc.Save(dataDir) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithFields() | |
| Dim doc As New Document(dataDir & Convert.ToString("in.doc")) | |
| Dim builder As New DocumentBuilder(doc) | |
| ' Get paragraph you want to append this merge field to | |
| Dim para As Paragraph = DirectCast(doc.GetChildNodes(NodeType.Paragraph, True)(1), Paragraph) | |
| ' Move cursor to this paragraph | |
| builder.MoveTo(para) | |
| ' We want to insert a merge field like this: | |
| ' { " MERGEFIELD Test1 \\b Test2 \\f Test3 \\m \\v" } | |
| ' Create instance of FieldMergeField class and lets build the above field code | |
| Dim field As FieldMergeField = DirectCast(builder.InsertField(FieldType.FieldMergeField, False), FieldMergeField) | |
| ' { " MERGEFIELD Test1" } | |
| field.FieldName = "Test1" | |
| ' { " MERGEFIELD Test1 \\b Test2" } | |
| field.TextBefore = "Test2" | |
| ' { " MERGEFIELD Test1 \\b Test2 \\f Test3 } | |
| field.TextAfter = "Test3" | |
| ' { " MERGEFIELD Test1 \\b Test2 \\f Test3 \\m" } | |
| field.IsMapped = True | |
| ' { " MERGEFIELD Test1 \\b Test2 \\f Test3 \\m \\v" } | |
| field.IsVerticalFormatting = True | |
| ' Finally update this merge field | |
| field.Update() | |
| dataDir = dataDir & Convert.ToString("InsertMergeFieldUsingDOM_out.doc") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithFields() | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| ' Insert a few page breaks (just for testing) | |
| For i As Integer = 0 To 4 | |
| builder.InsertBreak(BreakType.PageBreak) | |
| Next i | |
| ' Move the DocumentBuilder cursor into the primary footer. | |
| builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary) | |
| ' We want to insert a field like this: | |
| ' { IF {PAGE} <> {NUMPAGES} "See Next Page" "Last Page" } | |
| Dim field As Field = builder.InsertField("IF ") | |
| builder.MoveTo(field.Separator) | |
| builder.InsertField("PAGE") | |
| builder.Write(" <> ") | |
| builder.InsertField("NUMPAGES") | |
| builder.Write(" ""See Next Page"" ""Last Page"" ") | |
| ' Finally update the outer field to recalcaluate the final value. Doing this will automatically update | |
| ' The inner fields at the same time. | |
| field.Update() | |
| dataDir = dataDir & "InsertNestedFields_out.docx" | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithFields() | |
| Dim doc As New Document(dataDir & "Field.RemoveField.doc") | |
| Dim field As Field = doc.Range.Fields(0) | |
| ' Calling this method completely removes the field from the document. | |
| field.Remove() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ''' <summary> | |
| ''' Represents a facade object for a merge field in a Microsoft Word document. | |
| ''' </summary> | |
| Friend Class MergeField | |
| Friend Sub New(fieldStart As FieldStart) | |
| If fieldStart.Equals(Nothing) Then | |
| Throw New ArgumentNullException("fieldStart") | |
| End If | |
| If Not fieldStart.FieldType.Equals(FieldType.FieldMergeField) Then | |
| Throw New ArgumentException("Field start type must be FieldMergeField.") | |
| End If | |
| mFieldStart = fieldStart | |
| ' Find the field separator node. | |
| mFieldSeparator = fieldStart.GetField().Separator | |
| If mFieldSeparator Is Nothing Then | |
| Throw New InvalidOperationException("Cannot find field separator.") | |
| End If | |
| mFieldEnd = fieldStart.GetField().[End] | |
| End Sub | |
| ''' <summary> | |
| ''' Gets or sets the name of the merge field. | |
| ''' </summary> | |
| Friend Property Name() As String | |
| Get | |
| Return DirectCast(mFieldStart, FieldStart).GetField().Result.Replace("«", "").Replace("»", "") | |
| End Get | |
| Set(value As String) | |
| ' Merge field name is stored in the field result which is a Run | |
| ' Node between field separator and field end. | |
| Dim fieldResult As Run = DirectCast(mFieldSeparator.NextSibling, Run) | |
| fieldResult.Text = String.Format("«{0}»", value) | |
| ' But sometimes the field result can consist of more than one run, delete these runs. | |
| RemoveSameParent(fieldResult.NextSibling, mFieldEnd) | |
| UpdateFieldCode(value) | |
| End Set | |
| End Property | |
| Private Sub UpdateFieldCode(fieldName As String) | |
| ' Field code is stored in a Run node between field start and field separator. | |
| Dim fieldCode As Run = DirectCast(mFieldStart.NextSibling, Run) | |
| Dim match As Match = gRegex.Match(DirectCast(mFieldStart, FieldStart).GetField().GetFieldCode()) | |
| Dim newFieldCode As String = String.Format(" {0}{1} ", match.Groups("start").Value, fieldName) | |
| fieldCode.Text = newFieldCode | |
| ' But sometimes the field code can consist of more than one run, delete these runs. | |
| RemoveSameParent(fieldCode.NextSibling, mFieldSeparator) | |
| End Sub | |
| ''' <summary> | |
| ''' Removes nodes from start up to but not including the end node. | |
| ''' Start and end are assumed to have the same parent. | |
| ''' </summary> | |
| Private Shared Sub RemoveSameParent(ByVal startNode As Aspose.Words.Node, ByVal endNode As Aspose.Words.Node) | |
| If (endNode IsNot Nothing) AndAlso (startNode.ParentNode IsNot endNode.ParentNode) Then | |
| Throw New ArgumentException("Start and end nodes are expected to have the same parent.") | |
| End If | |
| Dim curChild As Aspose.Words.Node = startNode | |
| Do While (curChild IsNot Nothing) AndAlso (curChild IsNot endNode) | |
| Dim nextChild As Aspose.Words.Node = curChild.NextSibling | |
| curChild.Remove() | |
| curChild = nextChild | |
| Loop | |
| End Sub | |
| Private ReadOnly mFieldStart As Node | |
| Private ReadOnly mFieldSeparator As Node | |
| Private ReadOnly mFieldEnd As Node | |
| Private Shared ReadOnly gRegex As New Regex("\s*(?<start>MERGEFIELD\s|)(\s|)(?<name>\S+)\s+") | |
| End Class |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithFields() | |
| ' Specify your document name here. | |
| Dim doc As New Document(dataDir & Convert.ToString("RenameMergeFields.doc")) | |
| ' Select all field start nodes so we can find the merge fields. | |
| Dim fieldStarts As NodeCollection = doc.GetChildNodes(NodeType.FieldStart, True) | |
| For Each fieldStart As FieldStart In fieldStarts | |
| If fieldStart.FieldType.Equals(FieldType.FieldMergeField) Then | |
| Dim mergeField As New MergeField(fieldStart) | |
| mergeField.Name = mergeField.Name & Convert.ToString("_Renamed") | |
| End If | |
| Next | |
| dataDir = dataDir & Convert.ToString("RenameMergeFields_out.doc") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithFields() | |
| Dim doc As New Document(dataDir & Convert.ToString("Rendering.doc")) | |
| ' This updates all fields in the document. | |
| doc.UpdateFields() | |
| dataDir = dataDir & Convert.ToString("Rendering.UpdateFields_out.pdf") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_FindAndReplace() | |
| Dim fileName As String = "TestFile.doc" | |
| Dim doc As New Document(dataDir & fileName) | |
| Dim options As New FindReplaceOptions() | |
| options.ReplacingCallback = New ReplaceEvaluatorFindAndHighlight() | |
| ' We want the "your document" phrase to be highlighted. | |
| Dim regex As New Regex("your document", RegexOptions.IgnoreCase) | |
| doc.Range.Replace(regex, "", options) | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| ' Save the output document. | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Private Class ReplaceEvaluatorFindAndHighlight | |
| Implements IReplacingCallback | |
| ''' <summary> | |
| ''' This method is called by the Aspose.Words find and replace engine for each match. | |
| ''' This method highlights the match string, even if it spans multiple runs. | |
| ''' </summary> | |
| Private Function IReplacingCallback_Replacing(ByVal e As ReplacingArgs) As ReplaceAction Implements IReplacingCallback.Replacing | |
| ' This is a Run node that contains either the beginning or the complete match. | |
| Dim currentNode As Node = e.MatchNode | |
| ' The first (and may be the only) run can contain text before the match, | |
| ' In this case it is necessary to split the run. | |
| If e.MatchOffset > 0 Then | |
| currentNode = SplitRun(CType(currentNode, Run), e.MatchOffset) | |
| End If | |
| ' This array is used to store all nodes of the match for further highlighting. | |
| Dim runs As New ArrayList() | |
| ' Find all runs that contain parts of the match string. | |
| Dim remainingLength As Integer = e.Match.Value.Length | |
| Do While (remainingLength > 0) AndAlso (currentNode IsNot Nothing) AndAlso (currentNode.GetText().Length <= remainingLength) | |
| runs.Add(currentNode) | |
| remainingLength = remainingLength - currentNode.GetText().Length | |
| ' Select the next Run node. | |
| ' Have to loop because there could be other nodes such as BookmarkStart etc. | |
| Do | |
| currentNode = currentNode.NextSibling | |
| Loop While (currentNode IsNot Nothing) AndAlso (currentNode.NodeType <> NodeType.Run) | |
| Loop | |
| ' Split the last run that contains the match if there is any text left. | |
| If (currentNode IsNot Nothing) AndAlso (remainingLength > 0) Then | |
| SplitRun(CType(currentNode, Run), remainingLength) | |
| runs.Add(currentNode) | |
| End If | |
| ' Now highlight all runs in the sequence. | |
| For Each run As Run In runs | |
| run.Font.HighlightColor = Color.Yellow | |
| Next run | |
| ' Signal to the replace engine to do nothing because we have already done all what we wanted. | |
| Return ReplaceAction.Skip | |
| End Function | |
| End Class |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ''' <summary> | |
| ''' Splits text of the specified run into two runs. | |
| ''' Inserts the new run just after the specified run. | |
| ''' </summary> | |
| Private Shared Function SplitRun(ByVal run As Run, ByVal position As Integer) As Run | |
| Dim afterRun As Run = CType(run.Clone(True), Run) | |
| afterRun.Text = run.Text.Substring(position) | |
| run.Text = run.Text.Substring(0, position) | |
| run.ParentNode.InsertAfter(afterRun, run) | |
| Return afterRun | |
| End Function |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Private Class MyReplaceEvaluator | |
| Implements IReplacingCallback | |
| ''' <summary> | |
| ''' This is called during a replace operation each time a match is found. | |
| ''' This method appends a number to the match string and returns it as a replacement string. | |
| ''' </summary> | |
| Private Function IReplacingCallback_Replacing(e As ReplacingArgs) As ReplaceAction Implements IReplacingCallback.Replacing | |
| e.Replacement = e.Match.ToString() + mMatchNumber.ToString() | |
| mMatchNumber += 1 | |
| Return ReplaceAction.Replace | |
| End Function | |
| Private mMatchNumber As Integer | |
| End Class |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_FindAndReplace() | |
| Dim doc As New Document(dataDir & Convert.ToString("Range.ReplaceWithEvaluator.doc")) | |
| Dim options As New FindReplaceOptions() | |
| options.ReplacingCallback = New MyReplaceEvaluator() | |
| doc.Range.Replace(New Regex("[s|m]ad"), "", options) | |
| dataDir = dataDir & Convert.ToString("Range.ReplaceWithEvaluator_out.doc") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_FindAndReplace() | |
| Dim doc As New Document(dataDir & Convert.ToString("Document.doc")) | |
| doc.Range.Replace(New Regex("[s|m]ad"), "bad", New FindReplaceOptions(FindReplaceDirection.Forward)) | |
| dataDir = dataDir & Convert.ToString("ReplaceWithRegex_out.doc") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_FindAndReplace() | |
| Dim fileName As String = "Document.doc" | |
| Dim doc As New Document(dataDir & fileName) | |
| doc.Range.Replace("sad", "bad", New FindReplaceOptions(FindReplaceDirection.Forward)) | |
| dataDir = dataDir & Convert.ToString("ReplaceWithString_out.doc") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithHyperlink() | |
| Dim NewUrl As String = "http://www.aspose.com" | |
| Dim NewName As String = "Aspose - The .NET & Java Component Publisher" | |
| Dim doc As New Document(dataDir & Convert.ToString("ReplaceHyperlinks.doc")) | |
| ' Hyperlinks in a Word documents are fields. | |
| For Each field As Field In doc.Range.Fields | |
| If field.Type = FieldType.FieldHyperlink Then | |
| Dim hyperlink As FieldHyperlink = DirectCast(field, FieldHyperlink) | |
| ' Some hyperlinks can be local (links to bookmarks inside the document), ignore these. | |
| If hyperlink.SubAddress IsNot Nothing Then | |
| Continue For | |
| End If | |
| hyperlink.Address = NewUrl | |
| hyperlink.Result = NewName | |
| End If | |
| Next | |
| dataDir = dataDir & Convert.ToString("ReplaceHyperlinks_out.doc") | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Public Class AddWatermark | |
| Public Shared Sub Run() | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithImages() | |
| Dim fileName As String = "TestFile.Watermark.doc" | |
| Dim doc As New Document(dataDir & fileName) | |
| InsertWatermarkText(doc, "CONFIDENTIAL") | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| doc.Save(dataDir) | |
| Console.WriteLine(vbNewLine & "Inserted images on each page of the document successfully." & vbNewLine & "File saved at " + dataDir) | |
| End Sub | |
| ''' <summary> | |
| ''' Inserts a watermark into a document. | |
| ''' </summary> | |
| ''' <param name="doc">The input document.</param> | |
| ''' <param name="watermarkText">Text of the watermark.</param> | |
| Private Shared Sub InsertWatermarkText(ByVal doc As Document, ByVal watermarkText As String) | |
| ' Create a watermark shape. This will be a WordArt shape. | |
| ' You are free to try other shape types as watermarks. | |
| Dim watermark As New Shape(doc, ShapeType.TextPlainText) | |
| ' Set up the text of the watermark. | |
| watermark.TextPath.Text = watermarkText | |
| watermark.TextPath.FontFamily = "Arial" | |
| watermark.Width = 500 | |
| watermark.Height = 100 | |
| ' Text will be directed from the bottom-left to the top-right corner. | |
| watermark.Rotation = -40 | |
| ' Remove the following two lines if you need a solid black text. | |
| watermark.Fill.Color = Color.Gray ' Try LightGray to get more Word-style watermark | |
| watermark.StrokeColor = Color.Gray ' Try LightGray to get more Word-style watermark | |
| ' Place the watermark in the page center. | |
| watermark.RelativeHorizontalPosition = RelativeHorizontalPosition.Page | |
| watermark.RelativeVerticalPosition = RelativeVerticalPosition.Page | |
| watermark.WrapType = WrapType.None | |
| watermark.VerticalAlignment = VerticalAlignment.Center | |
| watermark.HorizontalAlignment = HorizontalAlignment.Center | |
| ' Create a new paragraph and append the watermark to this paragraph. | |
| Dim watermarkPara As New Paragraph(doc) | |
| watermarkPara.AppendChild(watermark) | |
| ' Insert the watermark into all headers of each document section. | |
| For Each sect As Section In doc.Sections | |
| ' There could be up to three different headers in each section, since we want | |
| ' The watermark to appear on all pages, insert into all headers. | |
| InsertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HeaderPrimary) | |
| InsertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HeaderFirst) | |
| InsertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HeaderEven) | |
| Next sect | |
| End Sub | |
| Private Shared Sub InsertWatermarkIntoHeader(ByVal watermarkPara As Paragraph, ByVal sect As Section, ByVal headerType As HeaderFooterType) | |
| Dim header As HeaderFooter = sect.HeadersFooters(headerType) | |
| If header Is Nothing Then | |
| ' There is no header of the specified type in the current section, create it. | |
| header = New HeaderFooter(sect.Document, headerType) | |
| sect.HeadersFooters.Add(header) | |
| End If | |
| ' Insert a clone of the watermark into the header. | |
| header.AppendChild(watermarkPara.Clone(True)) | |
| End Sub | |
| End Class |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithImages() | |
| Dim doc As New Document(dataDir & Convert.ToString("Image.SampleImages.doc")) | |
| Dim shapes As NodeCollection = doc.GetChildNodes(NodeType.Shape, True) | |
| Dim imageIndex As Integer = 0 | |
| For Each shape As Shape In shapes | |
| If shape.HasImage Then | |
| Dim imageFileName As String = String.Format("Image.ExportImages.{0}_out{1}", imageIndex, FileFormatUtil.ImageTypeToExtension(shape.ImageData.ImageType)) | |
| shape.ImageData.Save(dataDir & imageFileName) | |
| imageIndex += 1 | |
| End If | |
| Next |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithImages() | |
| ' Create a blank documenet. | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| ' The number of pages the document should have. | |
| Dim numPages As Integer = 4 | |
| ' The document starts with one section, insert the barcode into this existing section. | |
| InsertBarcodeIntoFooter(builder, doc.FirstSection, 1, HeaderFooterType.FooterPrimary) | |
| For i As Integer = 1 To numPages - 1 | |
| ' Clone the first section and add it into the end of the document. | |
| Dim cloneSection As Section = DirectCast(doc.FirstSection.Clone(False), Section) | |
| cloneSection.PageSetup.SectionStart = SectionStart.NewPage | |
| doc.AppendChild(cloneSection) | |
| ' Insert the barcode and other information into the footer of the section. | |
| InsertBarcodeIntoFooter(builder, cloneSection, i, HeaderFooterType.FooterPrimary) | |
| Next | |
| dataDir = dataDir & Convert.ToString("Document_out.docx") | |
| ' Save the document as a PDF to disk. You can also save this directly to a stream. | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Public Shared Sub Run() | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithImages() | |
| Dim fileName As String = "RemoveWatermark.docx" | |
| Dim doc As New Document(dataDir & fileName) | |
| RemoveWatermarkText(doc) | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| doc.Save(dataDir) | |
| End Sub | |
| Private Shared Sub RemoveWatermarkText(doc As Document) | |
| For Each hf As HeaderFooter In doc.GetChildNodes(NodeType.HeaderFooter, True) | |
| For Each shape As Shape In hf.GetChildNodes(NodeType.Shape, True) | |
| If shape.Name.Contains("WaterMark") Then | |
| shape.Remove() | |
| End If | |
| Next | |
| Next | |
| End Sub |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_JoiningAndAppending() | |
| Dim fileName As String = "TestFile.Destination.doc" | |
| Dim dstDoc As New Document(dataDir & fileName) | |
| Dim srcDoc As New Document(dataDir & "TestFile.Source.doc") | |
| Dim mode As ImportFormatMode = ImportFormatMode.KeepSourceFormatting | |
| ' Loop through all sections in the source document. | |
| ' Section nodes are immediate children of the Document node so we can just enumerate the Document. | |
| For Each srcSection As Section In srcDoc | |
| ' Because we are copying a section from one document to another, | |
| ' It is required to import the Section node into the destination document. | |
| ' This adjusts any document-specific references to styles, lists, etc. | |
| ' | |
| ' Importing a node creates a copy of the original node, but the copy | |
| ' Is ready to be inserted into the destination document. | |
| Dim dstSection As Node = dstDoc.ImportNode(srcSection, True, mode) | |
| ' Now the new section node can be appended to the destination document. | |
| dstDoc.AppendChild(dstSection) | |
| Next | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| ' Save the joined document | |
| dstDoc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_JoiningAndAppending() | |
| Dim fileName As String = "TestFile.Destination.doc" | |
| Dim dstDoc As New Document(dataDir & fileName) | |
| Dim srcDoc As New Document(dataDir & "TestFile.Source.doc") | |
| ' The destination document is not actually empty which often causes a blank page to appear before the appended document | |
| ' This is due to the base document having an empty section and the new document being started on the next page. | |
| ' Remove all content from the destination document before appending. | |
| dstDoc.RemoveAllChildren() | |
| dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting) | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| dstDoc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_JoiningAndAppending() | |
| Dim fileName As String = "TestFile.Destination.doc" | |
| Dim dstDoc As New Document(dataDir & fileName) | |
| Dim srcDoc As New Document(dataDir & "TestFile.Source.doc") | |
| ' Restart the page numbering on the start of the source document. | |
| srcDoc.FirstSection.PageSetup.RestartPageNumbering = True | |
| srcDoc.FirstSection.PageSetup.PageStartingNumber = 1 | |
| ' Append the source document to the end of the destination document. | |
| dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting) | |
| ' After joining the documents the NUMPAGE fields will now display the total number of pages which | |
| ' Is undesired behavior. Call this method to fix them by replacing them with PAGEREF fields. | |
| ConvertNumPageFieldsToPageRef(dstDoc) | |
| ' This needs to be called in order to update the new fields with page numbers. | |
| dstDoc.UpdatePageLayout() | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| dstDoc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ''' <summary> | |
| ''' Replaces all NUMPAGES fields in the document with PAGEREF fields. The replacement field displays the total number | |
| ''' Of pages in the sub document instead of the total pages in the document. | |
| ''' </summary> | |
| ''' <param name="doc">The combined document to process</param> | |
| Public Shared Sub ConvertNumPageFieldsToPageRef(ByVal doc As Document) | |
| ' This is the prefix for each bookmark which signals where page numbering restarts. | |
| ' The underscore "_" at the start inserts this bookmark as hidden in MS Word. | |
| Const bookmarkPrefix As String = "_SubDocumentEnd" | |
| ' Field name of the NUMPAGES field. | |
| Const numPagesFieldName As String = "NUMPAGES" | |
| ' Field name of the PAGEREF field. | |
| Const pageRefFieldName As String = "PAGEREF" | |
| ' Create a new DocumentBuilder which is used to insert the bookmarks and replacement fields. | |
| Dim builder As New DocumentBuilder(doc) | |
| ' Defines the number of page restarts that have been encountered and therefore the number of "sub" documents | |
| ' Found within this document. | |
| Dim subDocumentCount As Integer = 0 | |
| ' Iterate through all sections in the document. | |
| For Each section As Section In doc.Sections | |
| ' This section has it' S page numbering restarted so we will treat this as the start of a sub document. | |
| ' Any PAGENUM fields in this inner document must be converted to special PAGEREF fields to correct numbering. | |
| If section.PageSetup.RestartPageNumbering Then | |
| ' Don' T do anything if this is the first section in the document. This part of the code will insert the bookmark marking | |
| ' The end of the previous sub document so therefore it is not applicable for first section in the document. | |
| If (Not section.Equals(doc.FirstSection)) Then | |
| ' Get the previous section and the last node within the body of that section. | |
| Dim prevSection As Section = CType(section.PreviousSibling, Section) | |
| Dim lastNode As Node = prevSection.Body.LastChild | |
| ' Use the DocumentBuilder to move to this node and insert the bookmark there. | |
| ' This bookmark represents the end of the sub document. | |
| builder.MoveTo(lastNode) | |
| builder.StartBookmark(bookmarkPrefix & subDocumentCount) | |
| builder.EndBookmark(bookmarkPrefix & subDocumentCount) | |
| ' Increase the subdocument count to insert the correct bookmarks. | |
| subDocumentCount += 1 | |
| End If | |
| End If | |
| ' The last section simply needs the ending bookmark to signal that it is the end of the current sub document. | |
| If section.Equals(doc.LastSection) Then | |
| ' Insert the bookmark at the end of the body of the last section. | |
| ' Don' T increase the count this time as we are just marking the end of the document. | |
| Dim lastNode As Node = doc.LastSection.Body.LastChild | |
| builder.MoveTo(lastNode) | |
| builder.StartBookmark(bookmarkPrefix & subDocumentCount) | |
| builder.EndBookmark(bookmarkPrefix & subDocumentCount) | |
| End If | |
| ' Iterate through each NUMPAGES field in the section and replace the field with a PAGEREF field referring to the bookmark of the current subdocument | |
| ' This bookmark is positioned at the end of the sub document but does not exist yet. It is inserted when a section with restart page numbering or the last | |
| ' Section is encountered. | |
| Dim nodes() As Node = section.GetChildNodes(NodeType.FieldStart, True).ToArray() | |
| For Each fieldStart As FieldStart In nodes | |
| If fieldStart.FieldType = FieldType.FieldNumPages Then | |
| ' Get the field code. | |
| Dim fieldCode As String = GetFieldCode(fieldStart) | |
| ' Since the NUMPAGES field does not take any additional parameters we can assume the remaining part of the field | |
| ' Code after the fieldname are the switches. We will use these to help recreate the NUMPAGES field as a PAGEREF field. | |
| Dim fieldSwitches As String = fieldCode.Replace(numPagesFieldName, "").Trim() | |
| ' Inserting the new field directly at the FieldStart node of the original field will cause the new field to | |
| ' Not pick up the formatting of the original field. To counter this insert the field just before the original field | |
| Dim previousNode As Node = fieldStart.PreviousSibling | |
| ' If a previous run cannot be found then we are forced to use the FieldStart node. | |
| If previousNode Is Nothing Then | |
| previousNode = fieldStart | |
| End If | |
| ' Insert a PAGEREF field at the same position as the field. | |
| builder.MoveTo(previousNode) | |
| ' This will insert a new field with a code like " PAGEREF _SubDocumentEnd0 *\MERGEFORMAT ". | |
| Dim newField As Field = builder.InsertField(String.Format(" {0} {1}{2} {3} ", pageRefFieldName, bookmarkPrefix, subDocumentCount, fieldSwitches)) | |
| ' The field will be inserted before the referenced node. Move the node before the field instead. | |
| previousNode.ParentNode.InsertBefore(previousNode, newField.Start) | |
| ' Remove the original NUMPAGES field from the document. | |
| RemoveField(fieldStart) | |
| End If | |
| Next fieldStart | |
| Next section | |
| End Sub |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ''' <summary> | |
| ''' Removes the Field from the document | |
| ''' </summary> | |
| ''' <param name="fieldStart">The field start node of the field to remove.</param> | |
| Private Shared Sub RemoveField(ByVal fieldStart As FieldStart) | |
| Dim currentNode As Node = fieldStart | |
| Dim isRemoving As Boolean = True | |
| Do While currentNode IsNot Nothing AndAlso isRemoving | |
| If currentNode.NodeType = NodeType.FieldEnd Then | |
| isRemoving = False | |
| End If | |
| Dim nextNode As Node = currentNode.NextPreOrder(currentNode.Document) | |
| currentNode.Remove() | |
| currentNode = nextNode | |
| Loop | |
| End Sub | |
| ''' <summary> | |
| ''' Retrieves the field code from a field. | |
| ''' </summary> | |
| ''' <param name="fieldStart">The field start of the field which to gather the field code from</param> | |
| ''' <returns></returns> | |
| Private Shared Function GetFieldCode(ByVal fieldStart As FieldStart) As String | |
| Dim builder As New StringBuilder() | |
| Dim node As Node = fieldStart | |
| Do While node IsNot Nothing AndAlso node.NodeType <> NodeType.FieldSeparator AndAlso node.NodeType <> NodeType.FieldEnd | |
| ' Use text only of Run nodes to avoid duplication. | |
| If node.NodeType = NodeType.Run Then | |
| builder.Append(node.GetText()) | |
| End If | |
| node = node.NextPreOrder(node.Document) | |
| Loop | |
| Return builder.ToString() | |
| End Function |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_JoiningAndAppending() | |
| Dim fileName As String = "TestFile.Destination.doc" | |
| Dim dstDoc As New Document(dataDir & fileName) | |
| Dim srcDoc As New Document(dataDir & "TestFile.Source.doc") | |
| ' Set the source document to continue straight after the end of the destination document. | |
| ' If some page setup settings are different then this may not work and the source document will appear | |
| ' On a new page. | |
| srcDoc.FirstSection.PageSetup.SectionStart = SectionStart.Continuous | |
| ' To ensure this does not happen when the source document has different page setup settings make sure the | |
| ' Settings are identical between the last section of the destination document. | |
| ' If there are further continuous sections that follow on in the source document then this will need to be | |
| ' Repeated for those sections as well. | |
| srcDoc.FirstSection.PageSetup.PageWidth = dstDoc.LastSection.PageSetup.PageWidth | |
| srcDoc.FirstSection.PageSetup.PageHeight = dstDoc.LastSection.PageSetup.PageHeight | |
| srcDoc.FirstSection.PageSetup.Orientation = dstDoc.LastSection.PageSetup.Orientation | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting) | |
| dstDoc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_JoiningAndAppending() | |
| Dim fileName As String = "TestFile.Destination.doc" | |
| Dim dstDoc As New Document(dataDir & fileName) | |
| Dim srcDoc As New Document(dataDir & "TestFile.Source.doc") | |
| ' Make the document appear straight after the destination documents content. | |
| srcDoc.FirstSection.PageSetup.SectionStart = SectionStart.Continuous | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| ' Append the source document using the original styles found in the source document. | |
| dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting) | |
| dstDoc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_JoiningAndAppending() | |
| Dim fileName As String = "TestFile.Destination.doc" | |
| Dim dstDoc As New Document(dataDir & fileName) | |
| Dim srcDoc As New Document(dataDir & "TestFile.Source.doc") | |
| ' Set the appended document to start on a new page. | |
| srcDoc.FirstSection.PageSetup.SectionStart = SectionStart.NewPage | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| ' Append the source document using the original styles found in the source document. | |
| dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting) | |
| dstDoc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_JoiningAndAppending() | |
| Dim fileName As String = "TestFile.Destination.doc" | |
| Dim dstDoc As New Document(dataDir & fileName) | |
| Dim srcDoc As New Document(dataDir & "TestFile.Source.doc") | |
| ' Keep the formatting from the source document when appending it to the destination document. | |
| dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting) | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| ' Save the joined document to disk. | |
| dstDoc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_JoiningAndAppending() | |
| Dim fileName As String = "TestFile.Destination.doc" | |
| Dim dstDoc As New Document(dataDir & fileName) | |
| Dim srcDoc As New Document(dataDir & "TestFile.Source.doc") | |
| ' Set the source document to appear straight after the destination document' S content. | |
| srcDoc.FirstSection.PageSetup.SectionStart = SectionStart.Continuous | |
| ' Iterate through all sections in the source document. | |
| For Each para As Paragraph In srcDoc.GetChildNodes(NodeType.Paragraph, True) | |
| para.ParagraphFormat.KeepWithNext = True | |
| Next para | |
| dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting) | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| dstDoc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_JoiningAndAppending() | |
| Dim fileName As String = "TestFile.Destination.doc" | |
| Dim dstDoc As New Document(dataDir & fileName) | |
| Dim srcDoc As New Document(dataDir & "TestFile.Source.doc") | |
| ' Append the content of the document so it flows continuously. | |
| srcDoc.FirstSection.PageSetup.SectionStart = SectionStart.Continuous | |
| dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting) | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| dstDoc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_JoiningAndAppending() | |
| Dim fileName As String = "TestFile.Destination.doc" | |
| Dim dstDoc As New Document(dataDir & fileName) | |
| Dim srcDoc As New Document(dataDir & "TestFile.Source.doc") | |
| ' Set the source document to continue straight after the end of the destination document. | |
| srcDoc.FirstSection.PageSetup.SectionStart = SectionStart.Continuous | |
| ' Keep track of the lists that are created. | |
| Dim newLists As New Hashtable() | |
| ' Iterate through all paragraphs in the document. | |
| For Each para As Paragraph In srcDoc.GetChildNodes(NodeType.Paragraph, True) | |
| If para.IsListItem Then | |
| Dim listId As Integer = para.ListFormat.List.ListId | |
| ' Check if the destination document contains a list with this ID already. If it does then this may | |
| ' Cause the two lists to run together. Create a copy of the list in the source document instead. | |
| If dstDoc.Lists.GetListByListId(listId) IsNot Nothing Then | |
| Dim currentList As List | |
| ' A newly copied list already exists for this ID, retrieve the stored list and use it on | |
| ' The current paragraph. | |
| If newLists.Contains(listId) Then | |
| currentList = CType(newLists(listId), List) | |
| Else | |
| ' Add a copy of this list to the document and store it for later reference. | |
| currentList = srcDoc.Lists.AddCopy(para.ListFormat.List) | |
| newLists.Add(listId, currentList) | |
| End If | |
| ' Set the list of this paragraph to the copied list. | |
| para.ListFormat.List = currentList | |
| End If | |
| End If | |
| Next para | |
| ' Append the source document to end of the destination document. | |
| dstDoc.AppendDocument(srcDoc, ImportFormatMode.UseDestinationStyles) | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| ' Save the combined document to disk. | |
| dstDoc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_JoiningAndAppending() | |
| Dim fileName As String = "TestFile.Destination.doc" | |
| Dim dstDoc As New Document(dataDir & fileName) | |
| Dim srcDoc As New Document(dataDir & "TestFile.Source.doc") | |
| ' Set the appended document to appear on the next page. | |
| srcDoc.FirstSection.PageSetup.SectionStart = SectionStart.NewPage | |
| ' Restart the page numbering for the document to be appended. | |
| srcDoc.FirstSection.PageSetup.RestartPageNumbering = True | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting) | |
| dstDoc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_JoiningAndAppending() | |
| Dim fileName As String = "TestFile.Destination.doc" | |
| Dim dstDoc As New Document(dataDir & fileName) | |
| Dim srcDoc As New Document(dataDir & "TestFile.Source.doc") | |
| ' If the destination document is rendered to PDF, image etc or UpdatePageLayout is called before the source document | |
| ' Is appended then any changes made after will not be reflected in the rendered output. | |
| dstDoc.UpdatePageLayout() | |
| ' Join the documents. | |
| dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting) | |
| ' For the changes to be updated to rendered output, UpdatePageLayout must be called again. | |
| ' If not called again the appended document will not appear in the output of the next rendering. | |
| dstDoc.UpdatePageLayout() | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| ' Save the joined document to PDF. | |
| dstDoc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_JoiningAndAppending() | |
| Dim fileName As String = "TestFile.Destination.doc" | |
| Dim dstDoc As New Document(dataDir & fileName) | |
| Dim srcDoc As New Document(dataDir & "TestFile.Source.doc") | |
| ' Append the source document using the styles of the destination document. | |
| dstDoc.AppendDocument(srcDoc, ImportFormatMode.UseDestinationStyles) | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| ' Save the joined document to disk. | |
| dstDoc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document() | |
| Dim para As New Paragraph(doc) | |
| Dim section As Aspose.Words.Section = doc.LastSection | |
| section.Body.AppendChild(para) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document() | |
| Dim paragraph As Paragraph = DirectCast(doc.GetChild(NodeType.Paragraph, 0, True), Paragraph) | |
| Dim children As NodeCollection = paragraph.ChildNodes | |
| For Each child As Aspose.Words.Node In children | |
| ' Paragraph may contain children of various types such as runs, shapes and so on. | |
| If child.NodeType.Equals(NodeType.Run) Then | |
| ' Say we found the node that we want, do something useful. | |
| Dim run As Run = DirectCast(child, Run) | |
| Console.WriteLine(run.Text) | |
| End If | |
| Next |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' Create a new empty document. It has one section. | |
| Dim doc As New Document() | |
| ' The section is the first child node of the document. | |
| Dim section As Aspose.Words.Node = doc.FirstChild | |
| ' The section' S parent node is the document. | |
| Console.WriteLine("Section parent is the document: " & (doc Is section.ParentNode)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document() | |
| Dim paragraph As Paragraph = DirectCast(doc.GetChild(NodeType.Paragraph, 0, True), Paragraph) | |
| Dim children As NodeCollection = paragraph.ChildNodes | |
| For i As Integer = 0 To children.Count - 1 | |
| Dim child As Aspose.Words.Node = children(i) | |
| ' Paragraph may contain children of various types such as runs, shapes and so on. | |
| If child.NodeType.Equals(NodeType.Run) Then | |
| ' Say we found the node that we want, do something useful. | |
| Dim run As Run = DirectCast(child, Run) | |
| Console.WriteLine(run.Text) | |
| End If | |
| Next |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' Open a file from disk. | |
| Dim doc As New Document() | |
| ' Creating a new node of any type requires a document passed into the constructor. | |
| Dim para As New Paragraph(doc) | |
| ' The new paragraph node does not yet have a parent. | |
| Console.WriteLine("Paragraph has no parent node: " & (para.ParentNode Is Nothing)) | |
| ' But the paragraph node knows its document. | |
| Console.WriteLine("Both nodes' Documents are the same: " & (para.Document Is doc)) | |
| ' The fact that a node always belongs to a document allows us to access and modify | |
| ' Properties that reference the document-wide data such as styles or lists. | |
| para.ParagraphFormat.StyleName = "Heading 1" | |
| ' Now add the paragraph to the main text of the first section. | |
| doc.FirstSection.Body.AppendChild(para) | |
| ' The paragraph node is now a child of the Body node. | |
| Console.WriteLine("Paragraph has a parent node: " & (para.ParentNode IsNot Nothing)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Public Shared Sub RecurseAllNodes() | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithNode() | |
| ' Open a document. | |
| Dim doc As New Document(dataDir & Convert.ToString("Node.RecurseAllNodes.doc")) | |
| ' Invoke the recursive function that will walk the tree. | |
| TraverseAllNodes(doc) | |
| End Sub | |
| ''' <summary> | |
| ''' A simple function that will walk through all children of a specified node recursively | |
| ''' And print the type of each node to the screen. | |
| ''' </summary> | |
| Public Shared Sub TraverseAllNodes(parentNode As CompositeNode) | |
| ' This is the most efficient way to loop through immediate children of a node. | |
| Dim childNode As Aspose.Words.Node = parentNode.FirstChild | |
| While childNode IsNot Nothing | |
| ' Do some useful work. | |
| Console.WriteLine(Aspose.Words.Node.NodeTypeToString(childNode.NodeType)) | |
| ' Recurse into the node if it is a composite node. | |
| If childNode.IsComposite Then | |
| TraverseAllNodes(DirectCast(childNode, CompositeNode)) | |
| End If | |
| childNode = childNode.NextSibling | |
| End While | |
| End Sub |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document() | |
| Dim section As Section = doc.FirstSection | |
| ' Quick typed access to the Body child node of the Section. | |
| Dim body As Body = section.Body | |
| ' Quick typed access to all Table child nodes contained in the Body. | |
| Dim tables As TableCollection = body.Tables | |
| For Each table As Table In tables | |
| ' Quick typed access to the first row of the table. | |
| If table.FirstRow IsNot Nothing Then | |
| table.FirstRow.Remove() | |
| End If | |
| ' Quick typed access to the last row of the table. | |
| If table.LastRow IsNot Nothing Then | |
| table.LastRow.Remove() | |
| End If | |
| Next |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document() | |
| ' Returns NodeType.Document | |
| Dim type As NodeType = doc.NodeType |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithRanges() | |
| Dim doc As New Document(dataDir & Convert.ToString("Document.doc")) | |
| doc.Sections(0).Range.Delete() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithRanges() | |
| Dim doc As New Document(dataDir & Convert.ToString("Document.doc")) | |
| Dim text As String = doc.Range.Text |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document(dataDir) | |
| Dim sectionToAdd As New Section(doc) | |
| doc.Sections.Add(sectionToAdd) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document(dataDir) | |
| doc.Sections.Clear() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document(dataDir) | |
| doc.Sections.RemoveAt(0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithSections() | |
| Dim doc As New Document(dataDir & Convert.ToString("Section.AppendContent.doc")) | |
| ' This is the section that we will append and prepend to. | |
| Dim section As Section = doc.Sections(2) | |
| ' This copies content of the 1st section and inserts it at the beginning of the specified section. | |
| Dim sectionToPrepend As Section = doc.Sections(0) | |
| section.PrependContent(sectionToPrepend) | |
| ' This copies content of the 2nd section and inserts it at the end of the specified section. | |
| Dim sectionToAppend As Section = doc.Sections(1) | |
| section.AppendContent(sectionToAppend) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithSections() | |
| Dim doc As New Document(dataDir & Convert.ToString("Document.doc")) | |
| Dim cloneSection As Section = doc.Sections(0).Clone() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithSections() | |
| Dim srcDoc As New Document(dataDir & Convert.ToString("Document.doc")) | |
| Dim dstDoc As New Document() | |
| Dim sourceSection As Section = srcDoc.Sections(0) | |
| Dim newSection As Section = DirectCast(dstDoc.ImportNode(sourceSection, True), Section) | |
| dstDoc.Sections.Add(newSection) | |
| dataDir = dataDir & Convert.ToString("Document.Copy_out.doc") | |
| dstDoc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithSections() | |
| Dim doc As New Document(dataDir & Convert.ToString("Document.doc")) | |
| Dim section As Section = doc.Sections(0) | |
| section.ClearContent() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithSections() | |
| Dim doc As New Document(dataDir & Convert.ToString("Document.doc")) | |
| Dim section As Section = doc.Sections(0) | |
| section.PageSetup.LeftMargin = 90 | |
| ' 3.17 cm | |
| section.PageSetup.RightMargin = 90 | |
| ' 3.17 cm | |
| section.PageSetup.TopMargin = 72 | |
| ' 2.54 cm | |
| section.PageSetup.BottomMargin = 72 | |
| ' 2.54 cm | |
| section.PageSetup.HeaderDistance = 35.4 | |
| ' 1.25 cm | |
| section.PageSetup.FooterDistance = 35.4 | |
| ' 1.25 cm | |
| section.PageSetup.TextColumns.Spacing = 35.4 | |
| ' 1.25 cm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document() | |
| ' Retrieve the style used for the first level of the TOC and change the formatting of the style. | |
| doc.Styles(StyleIdentifier.Toc1).Font.Bold = True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithStyles() | |
| Dim fileName As String = "Document.TableOfContents.doc" | |
| ' Open the document. | |
| Dim doc As New Document(dataDir & fileName) | |
| ' Iterate through all paragraphs in the document | |
| For Each para As Paragraph In doc.GetChildNodes(NodeType.Paragraph, True) | |
| ' Check if this paragraph is formatted using the TOC result based styles. This is any style between TOC and TOC9. | |
| If para.ParagraphFormat.Style.StyleIdentifier >= StyleIdentifier.Toc1 AndAlso para.ParagraphFormat.Style.StyleIdentifier <= StyleIdentifier.Toc9 Then | |
| ' Get the first tab used in this paragraph, this should be the tab used to align the page numbers. | |
| Dim tab As TabStop = para.ParagraphFormat.TabStops(0) | |
| ' Remove the old tab from the collection. | |
| para.ParagraphFormat.TabStops.RemoveByPosition(tab.Position) | |
| ' Insert a new tab using the same properties but at a modified position. | |
| ' We could also change the separators used (dots) by passing a different Leader type | |
| para.ParagraphFormat.TabStops.Add(tab.Position - 50, tab.Alignment, tab.Leader) | |
| End If | |
| Next | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithStyles() | |
| Dim fileName As String = "TestFile.doc" | |
| ' Open the document. | |
| Dim doc As New Document(dataDir & fileName) | |
| ' Define style names as they are specified in the Word document. | |
| Const paraStyle As String = "Heading 1" | |
| Const runStyle As String = "Intense Emphasis" | |
| ' Collect paragraphs with defined styles. | |
| ' Show the number of collected paragraphs and display the text of this paragraphs. | |
| Dim paragraphs As ArrayList = ParagraphsByStyleName(doc, paraStyle) | |
| Console.WriteLine(String.Format("Paragraphs with ""{0}"" styles ({1}):", paraStyle, paragraphs.Count)) | |
| For Each paragraph As Paragraph In paragraphs | |
| Console.Write(paragraph.ToString(SaveFormat.Text)) | |
| Next paragraph | |
| ' Collect runs with defined styles. | |
| ' Show the number of collected runs and display the text of this runs. | |
| Dim runs As ArrayList = RunsByStyleName(doc, runStyle) | |
| Console.WriteLine(String.Format(Constants.vbLf & "Runs with ""{0}"" styles ({1}):", runStyle, runs.Count)) | |
| For Each run As Run In runs | |
| Console.WriteLine(run.Range.Text) | |
| Next run |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Public Shared Function ParagraphsByStyleName(ByVal doc As Document, ByVal styleName As String) As ArrayList | |
| ' Create an array to collect paragraphs of the specified style. | |
| Dim paragraphsWithStyle As New ArrayList() | |
| ' Get all paragraphs from the document. | |
| Dim paragraphs As NodeCollection = doc.GetChildNodes(NodeType.Paragraph, True) | |
| ' Look through all paragraphs to find those with the specified style. | |
| For Each paragraph As Paragraph In paragraphs | |
| If paragraph.ParagraphFormat.Style.Name = styleName Then | |
| paragraphsWithStyle.Add(paragraph) | |
| End If | |
| Next paragraph | |
| Return paragraphsWithStyle | |
| End Function |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Public Shared Function RunsByStyleName(ByVal doc As Document, ByVal styleName As String) As ArrayList | |
| ' Create an array to collect runs of the specified style. | |
| Dim runsWithStyle As New ArrayList() | |
| ' Get all runs from the document. | |
| Dim runs As NodeCollection = doc.GetChildNodes(NodeType.Run, True) | |
| ' Look through all runs to find those with the specified style. | |
| For Each run As Run In runs | |
| If run.Font.Style.Name = styleName Then | |
| runsWithStyle.Add(run) | |
| End If | |
| Next run | |
| Return runsWithStyle | |
| End Function |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ''' <summary> | |
| ''' Represents a facade object for a column of a table in a Microsoft Word document. | |
| ''' </summary> | |
| Friend Class Column | |
| Private Sub New(table As Table, columnIndex As Integer) | |
| If table Is Nothing Then | |
| Throw New ArgumentException("table") | |
| End If | |
| mTable = table | |
| mColumnIndex = columnIndex | |
| End Sub | |
| ''' <summary> | |
| ''' Returns a new column facade from the table and supplied zero-based index. | |
| ''' </summary> | |
| Public Shared Function FromIndex(table As Table, columnIndex As Integer) As Column | |
| Return New Column(table, columnIndex) | |
| End Function | |
| ''' <summary> | |
| ''' Returns the cells which make up the column. | |
| ''' </summary> | |
| Public ReadOnly Property Cells() As Cell() | |
| Get | |
| Return DirectCast(GetColumnCells().ToArray(GetType(Cell)), Cell()) | |
| End Get | |
| End Property | |
| ''' <summary> | |
| ''' Returns the index of the given cell in the column. | |
| ''' </summary> | |
| Public Function IndexOf(cell As Cell) As Integer | |
| Return GetColumnCells().IndexOf(cell) | |
| End Function | |
| ''' <summary> | |
| ''' Inserts a brand new column before this column into the table. | |
| ''' </summary> | |
| Public Function InsertColumnBefore() As Column | |
| Dim columnCells As Cell() = Cells | |
| If columnCells.Length = 0 Then | |
| Throw New ArgumentException("Column must not be empty") | |
| End If | |
| ' Create a clone of this column. | |
| For Each cell As Cell In columnCells | |
| cell.ParentRow.InsertBefore(cell.Clone(False), cell) | |
| Next | |
| ' This is the new column. | |
| Dim column As New Column(columnCells(0).ParentRow.ParentTable, mColumnIndex) | |
| ' We want to make sure that the cells are all valid to work with (have at least one paragraph). | |
| For Each cell As Cell In column.Cells | |
| cell.EnsureMinimum() | |
| Next | |
| ' Increase the index which this column represents since there is now one extra column infront. | |
| mColumnIndex += 1 | |
| Return column | |
| End Function | |
| ''' <summary> | |
| ''' Removes the column from the table. | |
| ''' </summary> | |
| Public Sub Remove() | |
| For Each cell As Cell In Cells | |
| cell.Remove() | |
| Next | |
| End Sub | |
| ''' <summary> | |
| ''' Returns the text of the column. | |
| ''' </summary> | |
| Public Function ToTxt() As String | |
| Dim builder As New StringBuilder() | |
| For Each cell As Cell In Cells | |
| builder.Append(cell.ToString(SaveFormat.Text)) | |
| Next | |
| Return builder.ToString() | |
| End Function | |
| ''' <summary> | |
| ''' Provides an up-to-date collection of cells which make up the column represented by this facade. | |
| ''' </summary> | |
| Private Function GetColumnCells() As ArrayList | |
| Dim columnCells As New ArrayList() | |
| For Each row As Row In mTable.Rows | |
| Dim cell As Cell = row.Cells(mColumnIndex) | |
| If cell IsNot Nothing Then | |
| columnCells.Add(cell) | |
| End If | |
| Next | |
| Return columnCells | |
| End Function | |
| Private mColumnIndex As Integer | |
| Private mTable As Table | |
| End Class |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' Get the second column in the table. | |
| Dim column__1 As Column = Column.FromIndex(table, 0) | |
| ' Print the plain text of the column to the screen. | |
| Console.WriteLine(column__1.ToTxt()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' Get the first table in the document. | |
| Dim table As Table = DirectCast(doc.GetChild(NodeType.Table, 0, True), Table) | |
| ' Get the second column in the table. | |
| Dim column__1 As Column = Column.FromIndex(table, 0) | |
| ' Print the plain text of the column to the screen. | |
| Console.WriteLine(column__1.ToTxt()) | |
| ' Create a new column to the left of this column. | |
| ' This is the same as using the "Insert Column Before" command in Microsoft Word. | |
| Dim newColumn As Column = column__1.InsertColumnBefore() | |
| ' Add some text to each of the column cells. | |
| For Each cell As Cell In newColumn.Cells | |
| cell.FirstParagraph.AppendChild(New Run(doc, "Column Text " + newColumn.IndexOf(cell).ToString())) | |
| Next |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' Get the second table in the document. | |
| Dim table As Table = DirectCast(doc.GetChild(NodeType.Table, 1, True), Table) | |
| ' Get the third column from the table and remove it. | |
| Dim column__1 As Column = Column.FromIndex(table, 2) | |
| column__1.Remove() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document(dataDir & Convert.ToString("Table.EmptyTable.doc")) | |
| Dim table As Table = DirectCast(doc.GetChild(NodeType.Table, 0, True), Table) | |
| ' Align the table to the center of the page. | |
| table.Alignment = TableAlignment.Center | |
| ' Clear any existing borders from the table. | |
| table.ClearBorders() | |
| ' Set a green border around the table but not inside. | |
| table.SetBorder(BorderType.Left, LineStyle.[Single], 1.5, Color.Green, True) | |
| table.SetBorder(BorderType.Right, LineStyle.[Single], 1.5, Color.Green, True) | |
| table.SetBorder(BorderType.Top, LineStyle.[Single], 1.5, Color.Green, True) | |
| table.SetBorder(BorderType.Bottom, LineStyle.[Single], 1.5, Color.Green, True) | |
| ' Fill the cells with a light green solid color. | |
| table.SetShading(TextureIndex.TextureSolid, Color.LightGreen, Color.Empty) | |
| dataDir = dataDir & Convert.ToString("Table.SetOutlineBorders_out.doc") | |
| ' Save the document to disk. | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| Dim table As Table = builder.StartTable() | |
| builder.InsertCell() | |
| ' Set the row formatting | |
| Dim rowFormat As RowFormat = builder.RowFormat | |
| rowFormat.Height = 100 | |
| rowFormat.HeightRule = HeightRule.Exactly | |
| ' These formatting properties are set on the table and are applied to all rows in the table. | |
| table.LeftPadding = 30 | |
| table.RightPadding = 30 | |
| table.TopPadding = 30 | |
| table.BottomPadding = 30 | |
| builder.Writeln("I' M a wonderful formatted row.") | |
| builder.EndRow() | |
| builder.EndTable() | |
| dataDir = dataDir & Convert.ToString("Table.ApplyRowFormatting_out.doc") | |
| ' Save the document to disk. | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document(dataDir & Convert.ToString("Table.EmptyTable.doc")) | |
| Dim table As Table = DirectCast(doc.GetChild(NodeType.Table, 0, True), Table) | |
| ' Clear any existing borders from the table. | |
| table.ClearBorders() | |
| ' Set a green border around and inside the table. | |
| table.SetBorders(LineStyle.[Single], 1.5, Color.Green) | |
| dataDir = dataDir & Convert.ToString("Table.SetAllBorders_out.doc") | |
| ' Save the document to disk. | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| Dim table As Table = builder.StartTable() | |
| builder.InsertCell() | |
| ' Set the borders for the entire table. | |
| table.SetBorders(LineStyle.[Single], 2.0, Color.Black) | |
| ' Set the cell shading for this cell. | |
| builder.CellFormat.Shading.BackgroundPatternColor = Color.Red | |
| builder.Writeln("Cell #1") | |
| builder.InsertCell() | |
| ' Specify a different cell shading for the second cell. | |
| builder.CellFormat.Shading.BackgroundPatternColor = Color.Green | |
| builder.Writeln("Cell #2") | |
| ' End this row. | |
| builder.EndRow() | |
| ' Clear the cell formatting from previous operations. | |
| builder.CellFormat.ClearFormatting() | |
| ' Create the second row. | |
| builder.InsertCell() | |
| ' Create larger borders for the first cell of this row. This will be different. | |
| ' Compared to the borders set for the table. | |
| builder.CellFormat.Borders.Left.LineWidth = 4.0 | |
| builder.CellFormat.Borders.Right.LineWidth = 4.0 | |
| builder.CellFormat.Borders.Top.LineWidth = 4.0 | |
| builder.CellFormat.Borders.Bottom.LineWidth = 4.0 | |
| builder.Writeln("Cell #3") | |
| builder.InsertCell() | |
| ' Clear the cell formatting from the previous cell. | |
| builder.CellFormat.ClearFormatting() | |
| builder.Writeln("Cell #4") | |
| ' Save finished document. | |
| doc.Save(dataDir & Convert.ToString("Table.SetBordersAndShading_out.doc")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document(dataDir & Convert.ToString("Table.Document.doc")) | |
| Dim table As Table = DirectCast(doc.GetChild(NodeType.Table, 0, True), Table) | |
| ' Retrieve the first cell in the table. | |
| Dim firstCell As Cell = table.FirstRow.FirstCell | |
| ' Modify some cell level properties. | |
| firstCell.CellFormat.Width = 30 | |
| ' In points | |
| firstCell.CellFormat.Orientation = TextOrientation.Downward | |
| firstCell.CellFormat.Shading.ForegroundPatternColor = Color.LightGreen |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document(dataDir & Convert.ToString("Table.Document.doc")) | |
| Dim table As Table = DirectCast(doc.GetChild(NodeType.Table, 0, True), Table) | |
| ' Retrieve the first row in the table. | |
| Dim firstRow As Row = table.FirstRow | |
| ' Modify some row level properties. | |
| firstRow.RowFormat.Borders.LineStyle = LineStyle.None | |
| firstRow.RowFormat.HeightRule = HeightRule.Auto | |
| firstRow.RowFormat.AllowBreakAcrossPages = True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document() | |
| Dim builder As New DocumentBuilder(doc) | |
| Dim table As Table = builder.StartTable() | |
| ' We must insert at least one row first before setting any table formatting. | |
| builder.InsertCell() | |
| ' Set the table style used based of the unique style identifier. | |
| ' Note that not all table styles are available when saving as .doc format. | |
| table.StyleIdentifier = StyleIdentifier.MediumShading1Accent1 | |
| ' Apply which features should be formatted by the style. | |
| table.StyleOptions = TableStyleOptions.FirstColumn Or TableStyleOptions.RowBands Or TableStyleOptions.FirstRow | |
| table.AutoFit(AutoFitBehavior.AutoFitToContents) | |
| ' Continue with building the table as normal. | |
| builder.Writeln("Item") | |
| builder.CellFormat.RightPadding = 40 | |
| builder.InsertCell() | |
| builder.Writeln("Quantity (kg)") | |
| builder.EndRow() | |
| builder.InsertCell() | |
| builder.Writeln("Apples") | |
| builder.InsertCell() | |
| builder.Writeln("20") | |
| builder.EndRow() | |
| builder.InsertCell() | |
| builder.Writeln("Bananas") | |
| builder.InsertCell() | |
| builder.Writeln("40") | |
| builder.EndRow() | |
| builder.InsertCell() | |
| builder.Writeln("Carrots") | |
| builder.InsertCell() | |
| builder.Writeln("50") | |
| builder.EndRow() | |
| dataDir = dataDir & Convert.ToString("DocumentBuilder.SetTableStyle_out.docx") | |
| ' Save the document to disk. | |
| doc.Save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| Dim doc As New Document(dataDir & Convert.ToString("Table.TableStyle.docx")) | |
| ' Get the first cell of the first table in the document. | |
| Dim table As Table = DirectCast(doc.GetChild(NodeType.Table, 0, True), Table) | |
| Dim firstCell As Cell = table.FirstRow.FirstCell | |
| ' First print the color of the cell shading. This should be empty as the current shading | |
| ' Is stored in the table style. | |
| Dim cellShadingBefore As Color = firstCell.CellFormat.Shading.BackgroundPatternColor | |
| Console.WriteLine("Cell shading before style expansion: " + cellShadingBefore.ToString()) | |
| ' Expand table style formatting to direct formatting. | |
| doc.ExpandTableStylesToDirectFormatting() | |
| ' Now print the cell shading after expanding table styles. A blue background pattern color | |
| ' Should have been applied from the table style. | |
| Dim cellShadingAfter As Color = firstCell.CellFormat.Shading.BackgroundPatternColor | |
| Console.WriteLine("Cell shading after style expansion: " + cellShadingAfter.ToString()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithTables() | |
| Dim fileName As String = "TestFile.doc" | |
| ' Open the document | |
| Dim doc As New Document(dataDir & fileName) | |
| Dim table As Table = CType(doc.GetChild(NodeType.Table, 0, True), Table) | |
| ' Auto fit the table to the cell contents | |
| table.AutoFit(AutoFitBehavior.AutoFitToContents) | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| ' Save the document to disk. | |
| doc.Save(dataDir) | |
| Debug.Assert(doc.FirstSection.Body.Tables(0).PreferredWidth.Type = PreferredWidthType.Auto, "PreferredWidth type is not auto") | |
| Debug.Assert(doc.FirstSection.Body.Tables(0).FirstRow.FirstCell.CellFormat.PreferredWidth.Type = PreferredWidthType.Auto, "PrefferedWidth on cell is not auto") | |
| Debug.Assert(doc.FirstSection.Body.Tables(0).FirstRow.FirstCell.CellFormat.PreferredWidth.Value = 0, "PreferredWidth value is not 0") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
| ' The path to the documents directory. | |
| Dim dataDir As String = RunExamples.GetDataDir_WorkingWithTables() | |
| Dim fileName As String = "TestFile.doc" | |
| ' Open the document | |
| Dim doc As New Document(dataDir & fileName) | |
| Dim table As Table = CType(doc.GetChild(NodeType.Table, 0, True), Table) | |
| ' Disable autofitting on this table. | |
| table.AutoFit(AutoFitBehavior.FixedColumnWidths) | |
| dataDir = dataDir & RunExamples.GetOutputFilePath(fileName) | |
| ' Save the document to disk. | |
| doc.Save(dataDir) | |
| ' ExEnd | |
| Debug.Assert(doc.FirstSection.Body.Tables(0).PreferredWidth.Type = PreferredWidthType.Auto, "PreferredWidth type is not auto") | |
| Debug.Assert(doc.FirstSection.Body.Tables(0).PreferredWidth.Value = 0, "PreferredWidth value is not 0") | |
| Debug.Assert(doc.FirstSection.Body.Tables(0).FirstRow.FirstCell.CellFormat.Width = 69.2, "Cell width is not correct.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment