diff --git a/Document-Processing/Word/Conversions/Word-To-Image/NET/Assemblies-required-word-to-image.md b/Document-Processing/Word/Conversions/Word-To-Image/NET/Assemblies-required-word-to-image.md index c10a126e4d..e5f70cf3fc 100644 --- a/Document-Processing/Word/Conversions/Word-To-Image/NET/Assemblies-required-word-to-image.md +++ b/Document-Processing/Word/Conversions/Word-To-Image/NET/Assemblies-required-word-to-image.md @@ -26,7 +26,7 @@ Syncfusion.DocIO.Base
Syncfusion.Compression.Base
Syncfusion.OfficeChart Syncfusion.DocIO.ClientProfile
Syncfusion.Compression.Base
Syncfusion.OfficeChart.Base
-{{'[ASP.NET Core](https://help.syncfusion.com/document-processing/word/conversions/word-to-image/net/convert-word-document-to-image-in-asp-net-core)' | markdownify}}, {{'[Xamarin](https://help.syncfusion.com/document-processing/word/conversions/word-to-image/net/convert-word-document-to-image-in-xamarin)' | markdownify}} and {{'[Blazor](https://help.syncfusion.com/document-processing/word/conversions/word-to-image/net/convert-word-document-to-image-in-blazor)' | markdownify}}
+{{'[ASP.NET Core](https://help.syncfusion.com/document-processing/word/conversions/word-to-image/net/convert-word-document-to-image-in-asp-net-core)' | markdownify}} and {{'[Blazor](https://help.syncfusion.com/document-processing/word/conversions/word-to-image/net/convert-word-document-to-image-in-blazor)' | markdownify}}
Syncfusion.DocIO.Portable
Syncfusion.Compression.Portable
Syncfusion.OfficeChart.Portable
Syncfusion.Pdf.Portable
Syncfusion.DocIORenderer.Portable
Syncfusion.Pdf.Imaging.Portable
Syncfusion.MetafileRenderer.Portable
SkiaSharp.HarfBuzz
Syncfusion.SkiaSharpHelper.Portable @@ -57,6 +57,10 @@ Assembly
{{'[ASP.NET](https://help.syncfusion.com/document-processing/word/conversions/word-to-image/net/convert-word-document-to-image-in-asp-net)' | markdownify}}
Syncfusion.DocIO.Base
Syncfusion.Compression.Base
Syncfusion.OfficeChart.Base
+ + +{{'[Xamarin](https://help.syncfusion.com/document-processing/word/conversions/word-to-image/net/convert-word-document-to-image-in-xamarin)' | markdownify}}
+Syncfusion.DocIO.Portable
Syncfusion.Compression.Portable
Syncfusion.OfficeChart.Portable
Syncfusion.Pdf.Portable
Syncfusion.DocIORenderer.Portable
Syncfusion.Pdf.Imaging.Portable
Syncfusion.MetafileRenderer.Portable
SkiaSharp.HarfBuzz
Syncfusion.SkiaSharpHelper.Portable
N> 1. Starting with the v24.1.x, if you reference "Syncfusion.DocIORenderer", you have to add the "Syncfusion.Pdf.Imaging" assembly reference in your projects to perform Word to Image conversion. diff --git a/Document-Processing/Word/Conversions/Word-To-Image/NET/Nuget-packages-required-word-to-image.md b/Document-Processing/Word/Conversions/Word-To-Image/NET/Nuget-packages-required-word-to-image.md index 9e267a5a87..70b69ca2fb 100644 --- a/Document-Processing/Word/Conversions/Word-To-Image/NET/Nuget-packages-required-word-to-image.md +++ b/Document-Processing/Word/Conversions/Word-To-Image/NET/Nuget-packages-required-word-to-image.md @@ -97,17 +97,6 @@ Install-Package Syncfusion.DocIORenderer.Net.Core -Xamarin - - -Syncfusion.Xamarin.DocIORenderer.nupkg - - -Install-Package Syncfusion.Xamarin.DocIORenderer - - - - Windows UI Library (WinUI)
.NET Multi-platform App UI (.NET MAUI) @@ -150,6 +139,17 @@ Syncfusion.DocIO.AspNet.nupkg Install-Package Syncfusion.DocIO.AspNet + + +{{'[Xamarin](https://help.syncfusion.com/document-processing/word/conversions/word-to-image/net/convert-word-document-to-image-in-xamarin)' | markdownify}}
+ + +Syncfusion.Xamarin.DocIORenderer.nupkg + + +Install-Package Syncfusion.Xamarin.DocIORenderer + + ### Additional NuGet packages required for Linux diff --git a/Document-Processing/Word/Conversions/Word-To-PDF/NET/Assemblies-required-word-to-pdf.md b/Document-Processing/Word/Conversions/Word-To-PDF/NET/Assemblies-required-word-to-pdf.md index c5c6f7d580..d8010cdf1d 100644 --- a/Document-Processing/Word/Conversions/Word-To-PDF/NET/Assemblies-required-word-to-pdf.md +++ b/Document-Processing/Word/Conversions/Word-To-PDF/NET/Assemblies-required-word-to-pdf.md @@ -26,7 +26,7 @@ Syncfusion.DocIO.Base
Syncfusion.Compression.Base
Syncfusion.OfficeChart Syncfusion.DocIO.ClientProfile
Syncfusion.Compression.Base
Syncfusion.OfficeChart.Base
Syncfusion.Pdf.ClientProfile
Syncfusion.DocToPdfConverter.ClientProfile
-{{'[ASP.NET Core](https://help.syncfusion.com/document-processing/word/conversions/word-to-pdf/net/convert-word-document-to-pdf-in-asp-net-core)' | markdownify}}, {{'[Xamarin](https://help.syncfusion.com/document-processing/word/conversions/word-to-pdf/net/convert-word-document-to-pdf-in-xamarin)' | markdownify}} and {{'[Blazor](https://help.syncfusion.com/document-processing/word/conversions/word-to-pdf/net/convert-word-document-to-pdf-in-blazor)' | markdownify}}
+{{'[ASP.NET Core](https://help.syncfusion.com/document-processing/word/conversions/word-to-pdf/net/convert-word-document-to-pdf-in-asp-net-core)' | markdownify}} and {{'[Blazor](https://help.syncfusion.com/document-processing/word/conversions/word-to-pdf/net/convert-word-document-to-pdf-in-blazor)' | markdownify}}
Syncfusion.DocIO.Portable
Syncfusion.Compression.Portable
Syncfusion.OfficeChart.Portable
Syncfusion.Pdf.Portable
Syncfusion.DocIORenderer.Portable
Syncfusion.Pdf.Imaging.Portable
Syncfusion.MetafileRenderer.Portable
SkiaSharp.HarfBuzz
Syncfusion.SkiaSharpHelper.Portable @@ -57,6 +57,10 @@ Assembly
{{'[ASP.NET](https://help.syncfusion.com/document-processing/word/conversions/word-to-pdf/net/convert-word-document-to-pdf-in-asp-net)' | markdownify}}
Syncfusion.DocIO.Base
Syncfusion.Compression.Base
Syncfusion.OfficeChart.Base
Syncfusion.Pdf.Base
Syncfusion.DocToPdfConverter.Base
+ + +{{'[Xamarin](https://help.syncfusion.com/document-processing/word/conversions/word-to-pdf/net/convert-word-document-to-pdf-in-xamarin)' | markdownify}}
+Syncfusion.DocIO.Portable
Syncfusion.Compression.Portable
Syncfusion.OfficeChart.Portable
Syncfusion.Pdf.Portable
Syncfusion.DocIORenderer.Portable
Syncfusion.Pdf.Imaging.Portable
Syncfusion.MetafileRenderer.Portable
SkiaSharp.HarfBuzz
Syncfusion.SkiaSharpHelper.Portable
N> 1. Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, you also have to add "Syncfusion.Licensing" assembly reference and include a license key in your projects. Please refer to this [link](https://help.syncfusion.com/common/essential-studio/licensing/overview) to know about registering Syncfusion® license key in your application to use our components. diff --git a/Document-Processing/Word/Conversions/Word-To-PDF/NET/Nuget-packages-required-word-to-pdf.md b/Document-Processing/Word/Conversions/Word-To-PDF/NET/Nuget-packages-required-word-to-pdf.md index 1632d281a0..c806025f3d 100644 --- a/Document-Processing/Word/Conversions/Word-To-PDF/NET/Nuget-packages-required-word-to-pdf.md +++ b/Document-Processing/Word/Conversions/Word-To-PDF/NET/Nuget-packages-required-word-to-pdf.md @@ -97,17 +97,6 @@ Install-Package Syncfusion.DocIORenderer.Net.Core -{{'[Xamarin](https://help.syncfusion.com/document-processing/word/conversions/word-to-pdf/net/convert-word-document-to-pdf-in-xamarin)'|  markdownify }} - - -Syncfusion.Xamarin.DocIORenderer.nupkg - - -Install-Package Syncfusion.Xamarin.DocIORenderer - - - - {{'[Windows UI Library (WinUI)](https://help.syncfusion.com/document-processing/word/conversions/word-to-pdf/net/convert-word-document-to-pdf-in-winui)'|  markdownify }}
{{'[.NET Multi-platform App UI (.NET MAUI)](https://help.syncfusion.com/document-processing/word/conversions/word-to-pdf/net/convert-word-document-to-pdf-in-maui)'|  markdownify }} @@ -150,6 +139,17 @@ Syncfusion.DocToPdfConverter.AspNet.nupkg Install-Package Syncfusion.DocToPdfConverter.AspNet + + +{{'[Xamarin](https://help.syncfusion.com/document-processing/word/conversions/word-to-pdf/net/convert-word-document-to-pdf-in-xamarin)'|  markdownify }}
+ + +Syncfusion.DocIORenderer.NET + + +Install-Package Syncfusion.Xamarin.DocIORenderer + + N> 1. Starting with v16.2.0.x, if you reference Syncfusion® assemblies from trial setup or from the NuGet feed, you also have to add "Syncfusion.Licensing" assembly reference and include a license key in your projects. Please refer to this [link](https://help.syncfusion.com/common/essential-studio/licensing/overview) to know about registering Syncfusion® license key in your application to use our components. @@ -427,20 +427,6 @@ Install-Package Syncfusion.DocIORenderer.Net.Core Uninstall-Package Syncfusion.DocIORenderer.Net.Core -RemoveDependencies ~~~ -### Xamarin -**NuGet Package:** Syncfusion.Xamarin.DocIORenderer - -The package contains the DocIORenderer .NET portable library that allows you to convert the Word documents to PDF. - -~~~ -// Install package -Install-Package Syncfusion.Xamarin.DocIORenderer -~~~ -~~~ -// Uninstall package -Uninstall-Package Syncfusion.Xamarin.DocIORenderer -RemoveDependencies -~~~ - ### Windows UI Library (WinUI) and .NET Multi-platform App UI (.NET MAUI) **NuGet Package:** Syncfusion.DocIORenderer.NET diff --git a/Document-Processing/Word/Conversions/html-conversions.md b/Document-Processing/Word/Conversions/html-conversions.md index 669da01295..79c4f92df5 100644 --- a/Document-Processing/Word/Conversions/html-conversions.md +++ b/Document-Processing/Word/Conversions/html-conversions.md @@ -103,6 +103,32 @@ The Essential® DocIO provides settings while performing HTML to W The following code example shows how to customize the HTML to Word conversion. {% tabs %} + +{% highlight c# tabtitle="C# [Cross-platform]" %} +FileStream fileStreamPath = new FileStream("Template.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); +//Opens an existing document from file system through constructor of WordDocument class +using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx)) +{ + //Html string to be inserted + string htmlstring = "

This text is inserted as HTML string.

"; + //Validates the Html string + bool isValidHtml = document.LastSection.Body.IsValidXHTML(htmlstring, XHTMLValidationType.Transitional); + //When the Html string passes validation, it is inserted to the document + if (isValidHtml) + { + //Appends Html string as first item of the second paragraph in the document + document.Sections[0].Body.InsertXHTML(htmlstring, 2, 0); + //Appends the Html string to first paragraph in the document + document.Sections[0].Body.Paragraphs[0].AppendHTML(htmlstring); + } + //Saves the Word document to MemoryStream + MemoryStream stream = new MemoryStream(); + document.Save(stream, FormatType.Docx); + //Closes the Word document + document.Close(); +} +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} //Loads the template document WordDocument document = new WordDocument("Template.docx"); diff --git a/Document-Processing/Word/Conversions/word-to-markdown-conversion.md b/Document-Processing/Word/Conversions/word-to-markdown-conversion.md index ee71292ef9..230d6b973d 100644 --- a/Document-Processing/Word/Conversions/word-to-markdown-conversion.md +++ b/Document-Processing/Word/Conversions/word-to-markdown-conversion.md @@ -26,6 +26,8 @@ Convert an existing Word document or document that is created from scratch into The following code example shows how to convert a Word document to a Markdown. +N> Refer to the appropriate tabs in the code snippets section: ***C# [Cross-platform]*** for ASP.NET Core, Blazor, Xamarin, UWP, .NET MAUI, and WinUI; ***C# [Windows-specific]*** for WinForms and WPF; ***VB.NET [Windows-specific]*** for VB.NET applications. + {% tabs %} {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/DocIO-Examples/main/Word-to-Markdown-conversion/Convert-Word-to-Markdown/.NET/Convert-Word-to-Markdown/Program.cs" %} @@ -59,56 +61,6 @@ Using document As WordDocument = New WordDocument("Input.docx", FormatType.Docx) End Using {% endhighlight %} -{% highlight c# tabtitle="UWP" %} -//Open the file as Stream. -using (Stream docStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("Sample.Assets.Input.docx")) -{ - //Load the file stream into a Word document. - using (WordDocument document = new WordDocument(docStream, FormatType.Docx)) - { - //Save as a Markdown file into the MemoryStream. - MemoryStream stream = new MemoryStream(); - await document.SaveAsync(stream, FormatType.Markdown); - //Save the stream as a Markdown file in the local machine. - Save(stream, "WordtoMd.md"); - } -} -//Saves a Word document. -async void Save(MemoryStream streams, string filename) -{ - streams.Position = 0; - StorageFile stFile; - if (!(Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons"))) - { - FileSavePicker savePicker = new FileSavePicker(); - savePicker.DefaultFileExtension = ".md"; - savePicker.SuggestedFileName = filename; - savePicker.FileTypeChoices.Add("Word Documents", new List() { ".md" }); - stFile = await savePicker.PickSaveFileAsync(); - } - else - { - StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder; - stFile = await local.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting); - } - if (stFile != null) - { - using (IRandomAccessStream zipStream = await stFile.OpenAsync(FileAccessMode.ReadWrite)) - { - //Write the compressed data from the memory to a file. - using (Stream outstream = zipStream.AsStreamForWrite()) - { - byte[] buffer = streams.ToArray(); - outstream.Write(buffer, 0, buffer.Length); - outstream.Flush(); - } - } - } - //Launch the saved Word file. - await Windows.System.Launcher.LaunchFileAsync(stFile); -} -{% endhighlight %} - {% endtabs %} You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Word-to-Markdown-conversion/Convert-Word-to-Markdown). @@ -180,8 +132,6 @@ The Essential® DocIO supports two types of code blocks in Word to The following code example shows how to create code blocks in a Word document using DocIO. -N> Refer to the appropriate tabs in the code snippets section: ***C# [Cross-platform]*** for ASP.NET Core, Blazor, Xamarin, UWP, .NET MAUI, and WinUI; ***C# [Windows-specific]*** for WinForms and WPF; ***VB.NET [Windows-specific]*** for VB.NET applications. - {% tabs %} {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/DocIO-Examples/main/Word-to-Markdown-conversion/Code-block-in-Markdown/.NET/Code-block-in-Markdown/Program.cs" %} @@ -410,12 +360,8 @@ Using document As WordDocument = New WordDocument("Input.docx", FormatType.Docx) End Using {% endhighlight %} -{% highlight c# tabtitle="Xamarin" %} -//DocIO doesn’t support the MarkdownExportImagesFolder API in UWP and Xamarin platforms. -{% endhighlight %} - {% highlight c# tabtitle="UWP" %} -//DocIO doesn’t support the MarkdownExportImagesFolder API in UWP and Xamarin platforms. +//DocIO doesn’t support the MarkdownExportImagesFolder API in UWP platform. {% endhighlight %} {% endtabs %} @@ -473,30 +419,6 @@ Using document As WordDocument = New WordDocument("Input.docx") End Using {% endhighlight %} -{% highlight c# tabtitle="Xamarin" %} -//Open the file as a Stream. -using (Stream docStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("Sample.Assets.Input.docx")) -{ - //Load the file stream into a Word document. - using (WordDocument document = new WordDocument(docStream, FormatType.Docx)) - { - //Hook the event to customize the image. - document.SaveOptions.ImageNodeVisited += SaveImage; - //Save a Markdown file to the MemoryStream. - MemoryStream outputStream = new MemoryStream(); - document.Save(outputStream, FormatType.Markdown); - //Save the stream as a file in the device and invoke it for viewing. - Xamarin.Forms.DependencyService.Get().SaveAndView("WordtoMd.md", "application/msword", outputStream); - } - //Please download the helper files from the following link to save the stream as a file and open the file for viewing in the Xamarin platform. - //https://help.syncfusion.com/document-processing/word/word-library/net/create-word-document-in-xamarin#helper-files-for-xamarin -} -{% endhighlight %} - -{% highlight c# tabtitle="UWP" %} -//DocIO doesn’t support the ImageNodeVisitedEventArgs in UWP platform. -{% endhighlight %} - {% endtabs %} The following code examples show the event handler to customize the image path and save the image in an external folder. @@ -539,14 +461,12 @@ Private Shared Sub SaveImage(ByVal sender As Object, ByVal args As ImageNodeVisi End Sub {% endhighlight %} -{% highlight c# tabtitle="UWP" %} -//DocIO doesn’t support the ImageNodeVisitedEventArgs in UWP platform. -{% endhighlight %} - {% endtabs %} You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Word-to-Markdown-conversion/Customize-image-path). +N> The [MarkdownExportImagesFolder](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.SaveOptions.html#Syncfusion_DocIO_DLS_SaveOptions_MarkdownExportImagesFolder) property and [ImageNodeVisited](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.SaveOptions.html#Syncfusion_DocIO_DLS_SaveOptions_ImageNodeVisited) event are not supported on the UWP platform. + ## Supported Word document elements The following table shows the list of Word document elements supported in Word to Markdown conversion. diff --git a/Document-Processing/Word/Word-Library/NET/Assemblies-Required.md b/Document-Processing/Word/Word-Library/NET/Assemblies-Required.md index 5c07142dd0..f638c09c0a 100644 --- a/Document-Processing/Word/Word-Library/NET/Assemblies-Required.md +++ b/Document-Processing/Word/Word-Library/NET/Assemblies-Required.md @@ -26,7 +26,7 @@ Syncfusion.DocIO.Base
Syncfusion.Compression.Base
Syncfusion.OfficeChart Syncfusion.DocIO.ClientProfile
Syncfusion.Compression.Base
Syncfusion.OfficeChart.Base
-{{'[ASP.NET Core](https://help.syncfusion.com/document-processing/word/word-library/net/create-word-document-in-asp-net-core)' | markdownify}}, {{'[Xamarin](https://help.syncfusion.com/document-processing/word/word-library/net/create-word-document-in-xamarin)' | markdownify}} and {{'[Blazor](https://help.syncfusion.com/document-processing/word/word-library/net/create-word-document-in-blazor)' | markdownify}}
+{{'[ASP.NET Core](https://help.syncfusion.com/document-processing/word/word-library/net/create-word-document-in-asp-net-core)' | markdownify}} and {{'[Blazor](https://help.syncfusion.com/document-processing/word/word-library/net/create-word-document-in-blazor)' | markdownify}}
Syncfusion.DocIO.Portable
Syncfusion.Compression.Portable
Syncfusion.OfficeChart.Portable
@@ -93,6 +93,10 @@ Syncfusion.DocIO.Universal
{{'[ASP.NET](https://help.syncfusion.com/document-processing/word/word-library/net/create-word-document-in-asp-net)' | markdownify}}
Syncfusion.DocIO.Base
Syncfusion.Compression.Base
Syncfusion.OfficeChart.Base
+ + +{{'[Xamarin](https://help.syncfusion.com/document-processing/word/word-library/net/create-word-document-in-xamarin)' | markdownify}}
+Syncfusion.DocIO.Portable
Syncfusion.Compression.Portable
Syncfusion.OfficeChart.Portable
N> 1. Starting with v16.2.0.x, if you reference Syncfusion® assemblies from trial setup or from the NuGet feed, you also have to add "Syncfusion.Licensing" assembly reference and include a license key in your projects. Please refer to this [link](https://help.syncfusion.com/common/essential-studio/licensing/overview) to know about registering Syncfusion® license key in your application to use our components. @@ -119,7 +123,7 @@ Syncfusion.DocIO.Base
Syncfusion.Compression.Base
Syncfusion.OfficeChart Syncfusion.DocIO.ClientProfile
Syncfusion.Compression.Base
Syncfusion.OfficeChart.Base
Syncfusion.Pdf.ClientProfile
Syncfusion.DocToPdfConverter.ClientProfile
-{{'[ASP.NET Core](https://help.syncfusion.com/document-processing/word/conversions/word-to-pdf/net/convert-word-document-to-pdf-in-asp-net-core)' | markdownify}}, {{'[Xamarin](https://help.syncfusion.com/document-processing/word/conversions/word-to-pdf/net/convert-word-document-to-pdf-in-xamarin)' | markdownify}} and {{'[Blazor](https://help.syncfusion.com/document-processing/word/conversions/word-to-pdf/net/convert-word-document-to-pdf-in-blazor)' | markdownify}}
+{{'[ASP.NET Core](https://help.syncfusion.com/document-processing/word/conversions/word-to-pdf/net/convert-word-document-to-pdf-in-asp-net-core)' | markdownify}} and {{'[Blazor](https://help.syncfusion.com/document-processing/word/conversions/word-to-pdf/net/convert-word-document-to-pdf-in-blazor)' | markdownify}}
Syncfusion.DocIO.Portable
Syncfusion.Compression.Portable
Syncfusion.OfficeChart.Portable
Syncfusion.Pdf.Portable
Syncfusion.DocIORenderer.Portable
Syncfusion.Pdf.Imaging.Portable
Syncfusion.MetafileRenderer.Portable
SkiaSharp.HarfBuzz
Syncfusion.SkiaSharpHelper.Portable @@ -142,6 +146,10 @@ Assembly
{{'[ASP.NET](https://help.syncfusion.com/document-processing/word/conversions/word-to-pdf/net/convert-word-document-to-pdf-in-asp-net)' | markdownify}}
Syncfusion.DocIO.Base
Syncfusion.Compression.Base
Syncfusion.OfficeChart.Base
Syncfusion.Pdf.Base
Syncfusion.DocToPdfConverter.Base
+ + +{{'[Xamarin](https://help.syncfusion.com/document-processing/word/conversions/word-to-pdf/net/convert-word-document-to-pdf-in-xamarin)' | markdownify}}
+Syncfusion.DocIO.Portable
Syncfusion.Compression.Portable
Syncfusion.OfficeChart.Portable
Syncfusion.Pdf.Portable
Syncfusion.DocIORenderer.Portable
Syncfusion.Pdf.Imaging.Portable
Syncfusion.MetafileRenderer.Portable
SkiaSharp.HarfBuzz
Syncfusion.SkiaSharpHelper.Portable
N> 1. Word to PDF conversion is supported in ASP.NET Core and Xamarin from 2018 Volume 1 release (v16.1.0.24) using SkiaSharp graphics library. @@ -168,7 +176,7 @@ Syncfusion.DocIO.Base
Syncfusion.Compression.Base
Syncfusion.OfficeChart Syncfusion.DocIO.ClientProfile
Syncfusion.Compression.Base
Syncfusion.OfficeChart.Base
-{{'[ASP.NET Core](https://help.syncfusion.com/document-processing/word/conversions/word-to-image/net/convert-word-document-to-image-in-asp-net-core)' | markdownify}}, {{'[Xamarin](https://help.syncfusion.com/document-processing/word/conversions/word-to-image/net/convert-word-document-to-image-in-xamarin)' | markdownify}} and {{'[Blazor](https://help.syncfusion.com/document-processing/word/conversions/word-to-image/net/convert-word-document-to-image-in-blazor)' | markdownify}}
+{{'[ASP.NET Core](https://help.syncfusion.com/document-processing/word/conversions/word-to-image/net/convert-word-document-to-image-in-asp-net-core)' | markdownify}} and {{'[Blazor](https://help.syncfusion.com/document-processing/word/conversions/word-to-image/net/convert-word-document-to-image-in-blazor)' | markdownify}}
Syncfusion.DocIO.Portable
Syncfusion.Compression.Portable
Syncfusion.OfficeChart.Portable
Syncfusion.Pdf.Portable
Syncfusion.DocIORenderer.Portable
Syncfusion.Pdf.Imaging.Portable
Syncfusion.MetafileRenderer.NET
SkiaSharp.HarfBuzz
Syncfusion.SkiaSharpHelper.Portable @@ -191,6 +199,10 @@ Assembly
{{'[ASP.NET](https://help.syncfusion.com/document-processing/word/conversions/word-to-image/net/convert-word-document-to-image-in-asp-net)' | markdownify}}
Syncfusion.DocIO.Base
Syncfusion.Compression.Base
Syncfusion.OfficeChart.Base
+ + +{{'[Xamarin](https://help.syncfusion.com/document-processing/word/conversions/word-to-image/net/convert-word-document-to-image-in-xamarin)' | markdownify}}
+Syncfusion.DocIO.Portable
Syncfusion.Compression.Portable
Syncfusion.OfficeChart.Portable
Syncfusion.Pdf.Portable
Syncfusion.DocIORenderer.Portable
Syncfusion.Pdf.Imaging.Portable
Syncfusion.MetafileRenderer.NET
SkiaSharp.HarfBuzz
Syncfusion.SkiaSharpHelper.Portable
## Converting Charts diff --git a/Document-Processing/Word/Word-Library/NET/Getting-Started.md b/Document-Processing/Word/Word-Library/NET/Getting-Started.md index 43a5997950..96971fb07e 100644 --- a/Document-Processing/Word/Word-Library/NET/Getting-Started.md +++ b/Document-Processing/Word/Word-Library/NET/Getting-Started.md @@ -47,6 +47,13 @@ N> Refer to the appropriate tabs in the code snippets section: ***C# [Cross-plat {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} + +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; + +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} using Syncfusion.DocIO; @@ -61,13 +68,6 @@ Imports Syncfusion.DocIO.DLS {% endhighlight %} -{% highlight c# tabtitle="C# [Cross-platform]" %} - -using Syncfusion.DocIO; -using Syncfusion.DocIO.DLS; - -{% endhighlight %} - {% endtabs %} ## Creating a new Word document with few lines of code @@ -76,7 +76,22 @@ The following code example explains how to create a new Word document with few l {% tabs %} -{% highlight c# tabtitle="C# [Windows-specific]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/DocIO-Examples/main/Getting-Started/Create-Word-document/.NET/Create-Word-document/Program.cs" %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/DocIO-Examples/main/Getting-Started/Create-Word-document/.NET/Create-Word-document/Program.cs" %} +//Creates a new instance of WordDocument (Empty Word Document) +WordDocument document = new WordDocument(); +//Adds a section and a paragraph to the document +document.EnsureMinimal(); +//Appends text to the last paragraph of the document +document.LastParagraph.AppendText("Hello World"); +//Saves the Word document to MemoryStream. +MemoryStream stream = new MemoryStream(); +document.Save(stream, FormatType.Docx); +//Closes the Word document. +document.Close(); +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} //Creates an instance of WordDocument Instance (Empty Word Document) WordDocument document = new WordDocument(); //Add a section & a paragraph in the empty document @@ -100,20 +115,6 @@ document.Save("Result.docx") document.Close() {% endhighlight %} -{% highlight c# tabtitle="C# [Cross-platform]" %} -//Creates a new instance of WordDocument (Empty Word Document) -WordDocument document = new WordDocument(); -//Adds a section and a paragraph to the document -document.EnsureMinimal(); -//Appends text to the last paragraph of the document -document.LastParagraph.AppendText("Hello World"); -//Saves the Word document to MemoryStream. -MemoryStream stream = new MemoryStream(); -document.Save(stream, FormatType.Docx); -//Closes the Word document. -document.Close(); -{% endhighlight %} - {% endtabs %} You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Getting-Started/Create-Word-document). @@ -128,6 +129,15 @@ The following code example explains how to add a section into a [WordDocument](h {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/DocIO-Examples/main/Getting-Started/Create-Word-with-basic-elements/.NET/Create-Word-with-basic-elements/Program.cs" %} +//Creates an instance of WordDocument Instance (Empty Word Document) +WordDocument document = new WordDocument(); +//Adds a new section into the Word document +IWSection section = document.AddSection(); +//Specifies the page margins +section.PageSetup.Margins.All = 50f; +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} //Creates an instance of WordDocument Instance (Empty Word Document) WordDocument document = new WordDocument(); @@ -146,15 +156,6 @@ Dim section As IWSection = document.AddSection() section.PageSetup.Margins.All = 50.0F {% endhighlight %} -{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/DocIO-Examples/main/Getting-Started/Create-Word-with-basic-elements/.NET/Create-Word-with-basic-elements/Program.cs" %} -//Creates an instance of WordDocument Instance (Empty Word Document) -WordDocument document = new WordDocument(); -//Adds a new section into the Word document -IWSection section = document.AddSection(); -//Specifies the page margins -section.PageSetup.Margins.All = 50f; -{% endhighlight %} - {% endtabs %} All the textual contents in a Word document is represented by Paragraphs. Within the paragraph, textual contents are grouped into one or more child elements such as TextRange, field etc. Each TextRange represents a region of text with a common set of rich text formatting. @@ -163,6 +164,24 @@ The following code example explains how to add a Paragraph into a Word document {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/DocIO-Examples/main/Getting-Started/Create-Word-with-basic-elements/.NET/Create-Word-with-basic-elements/Program.cs" %} +//Adds a new simple paragraph into the section +IWParagraph firstParagraph = section.AddParagraph(); +//Sets the paragraph's horizontal alignment as justify +firstParagraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify; +//Adds a text range into the paragraph +IWTextRange firstTextRange = firstParagraph.AppendText("AdventureWorks Cycles,"); +//sets the font formatting of the text range +firstTextRange.CharacterFormat.Bold = true; +firstTextRange.CharacterFormat.FontName = "Calibri"; +firstTextRange.CharacterFormat.FontSize = 14; +//Adds another text range into the paragraph +IWTextRange secondTextRange = firstParagraph.AppendText(" the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company."); +//sets the font formatting of the text range +secondTextRange.CharacterFormat.FontName = "Calibri"; +secondTextRange.CharacterFormat.FontSize = 11; +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} //Adds a new simple paragraph into the section IWParagraph firstParagraph = section.AddParagraph(); @@ -199,30 +218,26 @@ secondTextRange.CharacterFormat.FontName = "Calibri" secondTextRange.CharacterFormat.FontSize = 11 {% endhighlight %} -{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/DocIO-Examples/main/Getting-Started/Create-Word-with-basic-elements/.NET/Create-Word-with-basic-elements/Program.cs" %} -//Adds a new simple paragraph into the section -IWParagraph firstParagraph = section.AddParagraph(); -//Sets the paragraph's horizontal alignment as justify -firstParagraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify; -//Adds a text range into the paragraph -IWTextRange firstTextRange = firstParagraph.AppendText("AdventureWorks Cycles,"); -//sets the font formatting of the text range -firstTextRange.CharacterFormat.Bold = true; -firstTextRange.CharacterFormat.FontName = "Calibri"; -firstTextRange.CharacterFormat.FontSize = 14; -//Adds another text range into the paragraph -IWTextRange secondTextRange = firstParagraph.AppendText(" the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company."); -//sets the font formatting of the text range -secondTextRange.CharacterFormat.FontName = "Calibri"; -secondTextRange.CharacterFormat.FontSize = 11; -{% endhighlight %} - {% endtabs %} The following code example shows how to add an image into the Word document. {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/DocIO-Examples/main/Getting-Started/Create-Word-with-basic-elements/.NET/Create-Word-with-basic-elements/Program.cs" %} +//Adds another paragraph and aligns it as center +IWParagraph paragraph = section.AddParagraph(); +paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; +//Sets after spacing for paragraph. +paragraph.ParagraphFormat.AfterSpacing = 8; +//Adds a picture into the paragraph +FileStream image1 = new FileStream("DummyProfilePicture.jpg", FileMode.Open, FileAccess.Read); +IWPicture picture = paragraph.AppendPicture(image1); +//Specify the size of the picture +picture.Height = 100; +picture.Width = 100; +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} //Adds another paragraph and aligns it as center IWParagraph paragraph = section.AddParagraph(); @@ -249,26 +264,46 @@ picture.Height = 100 picture.Width = 100 {% endhighlight %} -{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/DocIO-Examples/main/Getting-Started/Create-Word-with-basic-elements/.NET/Create-Word-with-basic-elements/Program.cs" %} -//Adds another paragraph and aligns it as center -IWParagraph paragraph = section.AddParagraph(); -paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; -//Sets after spacing for paragraph. -paragraph.ParagraphFormat.AfterSpacing = 8; -//Adds a picture into the paragraph -FileStream image1 = new FileStream("DummyProfilePicture.jpg", FileMode.Open, FileAccess.Read); -IWPicture picture = paragraph.AppendPicture(image1); -//Specify the size of the picture -picture.Height = 100; -picture.Width = 100; -{% endhighlight %} - {% endtabs %} Table is another important element in Word that contains a set of paragraphs arranged in rows and columns. You can create simple as well as complex table by using Essential DocIO’s API. The following code example creates a simple table and adds contents into it. Each table cell must contain at least one paragraph. {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/DocIO-Examples/main/Getting-Started/Create-Word-with-basic-elements/.NET/Create-Word-with-basic-elements/Program.cs" %} +//Adds a table into the Word document +IWTable table = section.AddTable(); +//Creates the specified number of rows and columns +table.ResetCells(2, 2); +//Accesses the instance of the cell (first row, first cell) +WTableCell firstCell = table.Rows[0].Cells[0]; +//Specifies the width of the cell +firstCell.Width = 150; +//Adds a paragraph into the cell; a cell must have atleast 1 paragraph +paragraph = firstCell.AddParagraph(); +IWTextRange textRange = paragraph.AppendText("Profile picture"); +textRange.CharacterFormat.Bold = true; +//Accesses the instance of cell (first row, second cell) +WTableCell secondCell = table.Rows[0].Cells[1]; +secondCell.Width = 330; +paragraph = secondCell.AddParagraph(); +textRange = paragraph.AppendText("Description"); +textRange.CharacterFormat.Bold = true; +firstCell = table.Rows[1].Cells[0]; +firstCell.Width = 150; +paragraph = firstCell.AddParagraph(); +//Sets after spacing for paragraph. +paragraph.ParagraphFormat.AfterSpacing = 6; +FileStream image2 = new FileStream("DummyProfile-Picture.jpg", FileMode.Open, FileAccess.Read); +IWPicture profilePicture = paragraph.AppendPicture(image2); +profilePicture.Height = 100; +profilePicture.Width = 100; +secondCell = table.Rows[1].Cells[1]; +secondCell.Width = 330; +paragraph = secondCell.AddParagraph(); +textRange = paragraph.AppendText("AdventureWorks Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company."); +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} //Adds a table into the Word document IWTable table = section.AddTable(); @@ -335,46 +370,76 @@ paragraph = secondCell.AddParagraph() textRange = paragraph.AppendText("AdventureWorks Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company.") {% endhighlight %} -{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/DocIO-Examples/main/Getting-Started/Create-Word-with-basic-elements/.NET/Create-Word-with-basic-elements/Program.cs" %} -//Adds a table into the Word document -IWTable table = section.AddTable(); -//Creates the specified number of rows and columns -table.ResetCells(2, 2); -//Accesses the instance of the cell (first row, first cell) -WTableCell firstCell = table.Rows[0].Cells[0]; -//Specifies the width of the cell -firstCell.Width = 150; -//Adds a paragraph into the cell; a cell must have atleast 1 paragraph -paragraph = firstCell.AddParagraph(); -IWTextRange textRange = paragraph.AppendText("Profile picture"); -textRange.CharacterFormat.Bold = true; -//Accesses the instance of cell (first row, second cell) -WTableCell secondCell = table.Rows[0].Cells[1]; -secondCell.Width = 330; -paragraph = secondCell.AddParagraph(); -textRange = paragraph.AppendText("Description"); -textRange.CharacterFormat.Bold = true; -firstCell = table.Rows[1].Cells[0]; -firstCell.Width = 150; -paragraph = firstCell.AddParagraph(); -//Sets after spacing for paragraph. -paragraph.ParagraphFormat.AfterSpacing = 6; -FileStream image2 = new FileStream("DummyProfile-Picture.jpg", FileMode.Open, FileAccess.Read); -IWPicture profilePicture = paragraph.AppendPicture(image2); -profilePicture.Height = 100; -profilePicture.Width = 100; -secondCell = table.Rows[1].Cells[1]; -secondCell.Width = 330; -paragraph = secondCell.AddParagraph(); -textRange = paragraph.AppendText("AdventureWorks Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company."); -{% endhighlight %} - {% endtabs %} Essential® DocIO allow you to create simple and multi-level lists. The following code snippet explains about how to create a numbered and bulleted list. {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/DocIO-Examples/main/Getting-Started/Create-Word-with-basic-elements/.NET/Create-Word-with-basic-elements/Program.cs" %} +//Writes default numbered list. +paragraph = section.AddParagraph(); +//Sets before spacing for paragraph. +paragraph.ParagraphFormat.BeforeSpacing = 6; +paragraph.AppendText("Level 0"); +//Applies the default numbered list formats +paragraph.ListFormat.ApplyDefNumberedStyle(); +//Applies list formatting. +paragraph.ListFormat.CurrentListLevel.ParagraphFormat.LeftIndent = 36; +paragraph.ListFormat.CurrentListLevel.ParagraphFormat.FirstLineIndent = -18; +paragraph.ListFormat.CurrentListLevel.NumberAlignment = ListNumberAlignment.Left; +paragraph = section.AddParagraph(); +paragraph.AppendText("Level 1"); +//Specifies the list format to continue from last list +paragraph.ListFormat.ContinueListNumbering(); +//Increments the list level +paragraph.ListFormat.IncreaseIndentLevel(); +//Applies list formatting. +paragraph.ListFormat.CurrentListLevel.ParagraphFormat.LeftIndent = 72; +paragraph.ListFormat.CurrentListLevel.ParagraphFormat.FirstLineIndent = -18; +paragraph.ListFormat.CurrentListLevel.NumberAlignment = ListNumberAlignment.Left; +paragraph = section.AddParagraph(); +paragraph.AppendText("Level 0"); +paragraph.ListFormat.ContinueListNumbering(); +//Decrements the list level +paragraph.ListFormat.DecreaseIndentLevel(); +//Applies list formatting. +paragraph.ListFormat.CurrentListLevel.ParagraphFormat.LeftIndent = 36; +paragraph.ListFormat.CurrentListLevel.ParagraphFormat.FirstLineIndent = -18; +paragraph.ListFormat.CurrentListLevel.NumberAlignment = ListNumberAlignment.Left; +section.AddParagraph(); +//Writes default bulleted list. +paragraph = section.AddParagraph(); +paragraph.AppendText("Level 0"); +//Applies the default bulleted list formats +paragraph.ListFormat.ApplyDefBulletStyle(); +//Applies list formatting. +paragraph.ListFormat.CurrentListLevel.ParagraphFormat.LeftIndent = 36; +paragraph.ListFormat.CurrentListLevel.ParagraphFormat.FirstLineIndent = -18; +paragraph.ListFormat.CurrentListLevel.NumberAlignment = ListNumberAlignment.Left; +paragraph = section.AddParagraph(); +paragraph.AppendText("Level 1"); +//Specifies the list format to continue from last list +paragraph.ListFormat.ContinueListNumbering(); +//Increments the list level +paragraph.ListFormat.IncreaseIndentLevel(); +//Applies list formatting. +paragraph.ListFormat.CurrentListLevel.ParagraphFormat.LeftIndent = 72; +paragraph.ListFormat.CurrentListLevel.ParagraphFormat.FirstLineIndent = -18; +paragraph.ListFormat.CurrentListLevel.NumberAlignment = ListNumberAlignment.Left; +paragraph = section.AddParagraph(); +paragraph.AppendText("Level 0"); +//Specifies the list format to continue from last list +paragraph.ListFormat.ContinueListNumbering(); +//Decrements the list level +paragraph.ListFormat.DecreaseIndentLevel(); +//Applies list formatting. +paragraph.ListFormat.CurrentListLevel.ParagraphFormat.LeftIndent = 36; +paragraph.ListFormat.CurrentListLevel.ParagraphFormat.FirstLineIndent = -18; +paragraph.ListFormat.CurrentListLevel.NumberAlignment = ListNumberAlignment.Left; +section.AddParagraph(); +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} //Writes default numbered list. paragraph = section.AddParagraph(); @@ -503,76 +568,22 @@ paragraph.ListFormat.CurrentListLevel.NumberAlignment = ListNumberAlignment.Left section.AddParagraph() {% endhighlight %} -{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/DocIO-Examples/main/Getting-Started/Create-Word-with-basic-elements/.NET/Create-Word-with-basic-elements/Program.cs" %} -//Writes default numbered list. -paragraph = section.AddParagraph(); -//Sets before spacing for paragraph. -paragraph.ParagraphFormat.BeforeSpacing = 6; -paragraph.AppendText("Level 0"); -//Applies the default numbered list formats -paragraph.ListFormat.ApplyDefNumberedStyle(); -//Applies list formatting. -paragraph.ListFormat.CurrentListLevel.ParagraphFormat.LeftIndent = 36; -paragraph.ListFormat.CurrentListLevel.ParagraphFormat.FirstLineIndent = -18; -paragraph.ListFormat.CurrentListLevel.NumberAlignment = ListNumberAlignment.Left; -paragraph = section.AddParagraph(); -paragraph.AppendText("Level 1"); -//Specifies the list format to continue from last list -paragraph.ListFormat.ContinueListNumbering(); -//Increments the list level -paragraph.ListFormat.IncreaseIndentLevel(); -//Applies list formatting. -paragraph.ListFormat.CurrentListLevel.ParagraphFormat.LeftIndent = 72; -paragraph.ListFormat.CurrentListLevel.ParagraphFormat.FirstLineIndent = -18; -paragraph.ListFormat.CurrentListLevel.NumberAlignment = ListNumberAlignment.Left; -paragraph = section.AddParagraph(); -paragraph.AppendText("Level 0"); -paragraph.ListFormat.ContinueListNumbering(); -//Decrements the list level -paragraph.ListFormat.DecreaseIndentLevel(); -//Applies list formatting. -paragraph.ListFormat.CurrentListLevel.ParagraphFormat.LeftIndent = 36; -paragraph.ListFormat.CurrentListLevel.ParagraphFormat.FirstLineIndent = -18; -paragraph.ListFormat.CurrentListLevel.NumberAlignment = ListNumberAlignment.Left; -section.AddParagraph(); -//Writes default bulleted list. -paragraph = section.AddParagraph(); -paragraph.AppendText("Level 0"); -//Applies the default bulleted list formats -paragraph.ListFormat.ApplyDefBulletStyle(); -//Applies list formatting. -paragraph.ListFormat.CurrentListLevel.ParagraphFormat.LeftIndent = 36; -paragraph.ListFormat.CurrentListLevel.ParagraphFormat.FirstLineIndent = -18; -paragraph.ListFormat.CurrentListLevel.NumberAlignment = ListNumberAlignment.Left; -paragraph = section.AddParagraph(); -paragraph.AppendText("Level 1"); -//Specifies the list format to continue from last list -paragraph.ListFormat.ContinueListNumbering(); -//Increments the list level -paragraph.ListFormat.IncreaseIndentLevel(); -//Applies list formatting. -paragraph.ListFormat.CurrentListLevel.ParagraphFormat.LeftIndent = 72; -paragraph.ListFormat.CurrentListLevel.ParagraphFormat.FirstLineIndent = -18; -paragraph.ListFormat.CurrentListLevel.NumberAlignment = ListNumberAlignment.Left; -paragraph = section.AddParagraph(); -paragraph.AppendText("Level 0"); -//Specifies the list format to continue from last list -paragraph.ListFormat.ContinueListNumbering(); -//Decrements the list level -paragraph.ListFormat.DecreaseIndentLevel(); -//Applies list formatting. -paragraph.ListFormat.CurrentListLevel.ParagraphFormat.LeftIndent = 36; -paragraph.ListFormat.CurrentListLevel.ParagraphFormat.FirstLineIndent = -18; -paragraph.ListFormat.CurrentListLevel.NumberAlignment = ListNumberAlignment.Left; -section.AddParagraph(); -{% endhighlight %} - {% endtabs %} Finally, save the document in file system and close its instance. {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/DocIO-Examples/main/Getting-Started/Create-Word-with-basic-elements/.NET/Create-Word-with-basic-elements/Program.cs" %} +MemoryStream stream = new MemoryStream(); +//Saves the Word document to MemoryStream +document.Save(stream, FormatType.Docx); +document.Close(); +stream.Position = 0; +//Download Word document in the browser +return File(stream, "application/msword", outputFileName); +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} //Saves the document in the given name and format document.Save(outputFileName, FormatType.Docx); @@ -587,16 +598,6 @@ document.Save(outputFileName, FormatType.Docx) document.Close() {% endhighlight %} -{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/DocIO-Examples/main/Getting-Started/Create-Word-with-basic-elements/.NET/Create-Word-with-basic-elements/Program.cs" %} -MemoryStream stream = new MemoryStream(); -//Saves the Word document to MemoryStream -document.Save(stream, FormatType.Docx); -document.Close(); -stream.Position = 0; -//Download Word document in the browser -return File(stream, "application/msword", outputFileName); -{% endhighlight %} - {% endtabs %} You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Getting-Started/Create-Word-with-basic-elements). @@ -615,6 +616,19 @@ You can open an existing Word document either by using constructor of [WordDocum {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/DocIO-Examples/main/Find-and-Replace/Find-and-replace-all/.NET/Find-and-replace-all/Program.cs" %} +FileStream fileStream = new FileStream(@"Giant Panda.docx",FileMode.Open,FileAccess.ReadWrite); +//Loads an existing Word document into DocIO instance +WordDocument document = new WordDocument(fileStream, FormatType.Automatic); +//Replaces the word "bear" as "panda" +document.Replace("bear", "panda", false, true); +//Saves the Word document to MemoryStream. +MemoryStream stream = new MemoryStream(); +document.Save(stream, FormatType.Docx); +//Closes the Word document. +document.Close(); +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} //Loads an existing Word document into DocIO instance WordDocument document = new WordDocument("Giant Panda.docx"); @@ -637,19 +651,6 @@ document.Save("Result.docx") document.Close() {% endhighlight %} -{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/DocIO-Examples/main/Find-and-Replace/Find-and-replace-all/.NET/Find-and-replace-all/Program.cs" %} -FileStream fileStream = new FileStream(@"Giant Panda.docx",FileMode.Open,FileAccess.ReadWrite); -//Loads an existing Word document into DocIO instance -WordDocument document = new WordDocument(fileStream, FormatType.Automatic); -//Replaces the word "bear" as "panda" -document.Replace("bear", "panda", false, true); -//Saves the Word document to MemoryStream. -MemoryStream stream = new MemoryStream(); -document.Save(stream, FormatType.Docx); -//Closes the Word document. -document.Close(); -{% endhighlight %} - {% endtabs %} You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Find-and-Replace/Find-and-replace-all). @@ -658,6 +659,25 @@ The following code example explains how to search a particular text and highligh {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/DocIO-Examples/main/Find-and-Replace/Find-and-highlight-all/.NET/Find-and-highlight-all/Program.cs" %} +FileStream fileStream = new FileStream(@"Test.docx",FileMode.Open,FileAccess.ReadWrite); +//Loads an existing Word document into DocIO instance +WordDocument document = new WordDocument(fileStream, FormatType.Automatic); +//Finds the occurrence of the Word "panda" in the document +TextSelection[] textSelection = document.FindAll("panda", false, true); +//Iterates through each occurrence and highlights it +foreach (TextSelection selection in textSelection) +{ + IWTextRange textRange = selection.GetAsOneRange(); + textRange.CharacterFormat.HighlightColor = Syncfusion.Drawing.Color.Yellow; +} +//Saves the Word document to MemoryStream. +MemoryStream stream = new MemoryStream(); +document.Save(stream, FormatType.Docx); +//Closes the Word document. +document.Close(); +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} //Loads an existing Word document into DocIO instance WordDocument document = new WordDocument(@"../../Data/Giant Panda.docx"); @@ -688,25 +708,6 @@ document.Save("Result.docx") document.Close() {% endhighlight %} -{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/DocIO-Examples/main/Find-and-Replace/Find-and-highlight-all/.NET/Find-and-highlight-all/Program.cs" %} -FileStream fileStream = new FileStream(@"Test.docx",FileMode.Open,FileAccess.ReadWrite); -//Loads an existing Word document into DocIO instance -WordDocument document = new WordDocument(fileStream, FormatType.Automatic); -//Finds the occurrence of the Word "panda" in the document -TextSelection[] textSelection = document.FindAll("panda", false, true); -//Iterates through each occurrence and highlights it -foreach (TextSelection selection in textSelection) -{ - IWTextRange textRange = selection.GetAsOneRange(); - textRange.CharacterFormat.HighlightColor = Syncfusion.Drawing.Color.Yellow; -} -//Saves the Word document to MemoryStream. -MemoryStream stream = new MemoryStream(); -document.Save(stream, FormatType.Docx); -//Closes the Word document. -document.Close(); -{% endhighlight %} - {% endtabs %} You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Find-and-Replace/Find-and-highlight-all). @@ -736,6 +737,23 @@ The following code example shows how to perform simple Mail merge by using strin {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/DocIO-Examples/main/Mail-Merge/Mail-merge-with-string-arrays/.NET/Mail-merge-with-string-arrays/Program.cs" %} +FileStream fileStream = new FileStream(@"SimpleMailMergeTemplate.docx", FileMode.Open,FileAccess.ReadWrite); +//Loads an existing Word document into DocIO instance +WordDocument document = new WordDocument(fileStream, FormatType.Automatic); +//Initializes the string array with field names +string[] fieldNames = new string[] { "FirstName", "LastName", "Email", "Country" }; +//Initializes the string array with field values +string[] fieldValues = new string[] { "John", "Smith", "john_smith@domain.com", "USA" }; +//Executes the mail merge operation that replaces the matching field names with field values respectively. +document.MailMerge.Execute(fieldNames, fieldValues); +//Saves the Word document to MemoryStream. +MemoryStream stream = new MemoryStream(); +document.Save(stream, FormatType.Docx); +//Closes the Word document. +document.Close(); +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} //Loads the template document with required merge fields WordDocument document = new WordDocument(@"../../data/SimpleMailMergeTemplate.docx"); @@ -764,23 +782,6 @@ document.Save("result.docx") document.Close() {% endhighlight %} -{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/DocIO-Examples/main/Mail-Merge/Mail-merge-with-string-arrays/.NET/Mail-merge-with-string-arrays/Program.cs" %} -FileStream fileStream = new FileStream(@"SimpleMailMergeTemplate.docx", FileMode.Open,FileAccess.ReadWrite); -//Loads an existing Word document into DocIO instance -WordDocument document = new WordDocument(fileStream, FormatType.Automatic); -//Initializes the string array with field names -string[] fieldNames = new string[] { "FirstName", "LastName", "Email", "Country" }; -//Initializes the string array with field values -string[] fieldValues = new string[] { "John", "Smith", "john_smith@domain.com", "USA" }; -//Executes the mail merge operation that replaces the matching field names with field values respectively. -document.MailMerge.Execute(fieldNames, fieldValues); -//Saves the Word document to MemoryStream. -MemoryStream stream = new MemoryStream(); -document.Save(stream, FormatType.Docx); -//Closes the Word document. -document.Close(); -{% endhighlight %} - {% endtabs %} You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Mail-Merge/Mail-merge-with-string-arrays). @@ -1117,7 +1118,7 @@ N> 2. [ChartToImageConverter](https://help.syncfusion.com/cr/document-processing ## Online Demo -* Explore how to create a simple Word document with text, an image, and a table using the .NET Word Library (DocIO) in a live demo [here](https://ej2.syncfusion.com/aspnetcore/word/helloworld#/bootstrap5). +* Explore how to create a simple Word document with text, an image, and a table using the .NET Word Library (DocIO) in a live demo [here](https://document.syncfusion.com/demos/word/helloworld#/tailwind). ## See Also diff --git a/Document-Processing/Word/Word-Library/NET/Loading-and-Saving-document.md b/Document-Processing/Word/Word-Library/NET/Loading-and-Saving-document.md index a016f96fae..b4fa80b4ab 100644 --- a/Document-Processing/Word/Word-Library/NET/Loading-and-Saving-document.md +++ b/Document-Processing/Word/Word-Library/NET/Loading-and-Saving-document.md @@ -1,6 +1,6 @@ --- title: Loading & Saving Word document in C# | DocIO | Syncfusion -description: Learn to open and save the Word document in C# and VB.NET using Syncfusion® .NET Word (DocIO) library without Microsoft Word or interop dependencies. +description: Learn to open and save Word document in C# and VB.NET using the Syncfusion® .NET Word (DocIO) library without Microsoft Word or interop. platform: document-processing control: DocIO documentation: UG @@ -11,31 +11,23 @@ documentation: UG The following namespaces of Essential® DocIO need to be included in your application to load and save the Word document. -{% tabs %} - -{% highlight c# tabtitle="C#" %} -using Syncfusion.DocIO; -using Syncfusion.DocIO.DLS; -{% endhighlight %} +N> Refer to the appropriate tabs in the code snippets section: ***C# [Cross-platform]*** for ASP.NET Core, Blazor, Xamarin, UWP, .NET MAUI, and WinUI; ***C# [Windows-specific]*** for WinForms and WPF; ***VB.NET [Windows-specific]*** for VB.NET applications. -{% highlight vb.net tabtitle="VB.NET" %} -Imports Syncfusion.DocIO -Imports Syncfusion.DocIO.DLS -{% endhighlight %} +{% tabs %} -{% highlight c# tabtitle="UWP" %} +{% highlight c# tabtitle="C# [Cross-platform]" %} using Syncfusion.DocIO; using Syncfusion.DocIO.DLS; {% endhighlight %} -{% highlight c# tabtitle="ASP.NET Core" %} +{% highlight c# tabtitle="C# [Windows-specific]" %} using Syncfusion.DocIO; using Syncfusion.DocIO.DLS; {% endhighlight %} -{% highlight c# tabtitle="Xamarin" %} -using Syncfusion.DocIO; -using Syncfusion.DocIO.DLS; +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.DocIO +Imports Syncfusion.DocIO.DLS {% endhighlight %} {% endtabs %} @@ -46,66 +38,27 @@ You can open an existing Word document by using either the [Open](https://help.s {% tabs %} -{% highlight c# tabtitle="C#" %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +//Opens an existing document from stream through constructor of `WordDocument` class +FileStream fileStreamPath = new FileStream(@"Data/Hello World.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); +WordDocument document = new WordDocument(fileStreamPath, FormatType.Automatic); +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} //Opens an existing document from file system through constructor of WordDocument class WordDocument document = new WordDocument(fileName); {% endhighlight %} -{% highlight vb.net tabtitle="VB.NET" %} +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} 'Opens an existing document from file system through constructor of WordDocument class Dim document As New WordDocument(fileName) {% endhighlight %} -{% highlight c# tabtitle="UWP" %} -//"App" is the class of Portable project -Assembly assembly = typeof(App).GetTypeInfo().Assembly; -//Opens an existing document through constructor of `WordDocument` class -WordDocument document = new WordDocument(assembly.GetManifestResourceStream("CreateWordSample.Assets.Test.docx"),FormatType.Docx); -{% endhighlight %} - -{% highlight c# tabtitle="ASP.NET Core" %} -//Opens an existing document from stream through constructor of `WordDocument` class -FileStream fileStreamPath = new FileStream(@"Data/Hello World.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); -WordDocument document = new WordDocument(fileStreamPath, FormatType.Automatic); -{% endhighlight %} - -{% highlight c# tabtitle="Xamarin" %} -//"App" is the class of Portable project -Assembly assembly = typeof(App).GetTypeInfo().Assembly; -//Opens an existing document through constructor of `WordDocument` class -WordDocument document = new WordDocument(assembly.GetManifestResourceStream("XamarinFormsApp1.Assets.Test.docx"),FormatType.Automatic); -{% endhighlight %} - {% endtabs %} {% tabs %} - -{% highlight c# tabtitle="C#" %} -//Creates an empty Word document instance -WordDocument document = new WordDocument(); -//Loads or opens an existing word document through Open method of WordDocument class -document.Open(fileName); -{% endhighlight %} - -{% highlight vb.net tabtitle="VB.NET" %} -'Creates an empty Word document instance -Dim document As New WordDocument() -'Loads or opens an existing word document through Open method of WordDocument class -document.Open(fileName) -{% endhighlight %} -{% highlight c# tabtitle="UWP" %} -//Instantiates the File Picker -FileOpenPicker openPicker = new FileOpenPicker(); -openPicker.SuggestedStartLocation = PickerLocationId.Desktop; -openPicker.FileTypeFilter.Add(".docx"); -//Creates a storage file from FileOpenPicker -StorageFile inputStorageFile = await openPicker.PickSingleFileAsync(); -WordDocument document = new WordDocument(); -await document.OpenAsync(inputStorageFile); -{% endhighlight %} - -{% highlight c# tabtitle="ASP.NET Core" %} +{% highlight c# tabtitle="C# [Cross-platform]" %} //Opens an existing document from stream through constructor of `WordDocument` class FileStream fileStreamPath = new FileStream(@"Data/Hello World.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); //Creates an empty Word document instance @@ -114,13 +67,18 @@ WordDocument document = new WordDocument(); document.Open(fileStreamPath, FormatType.Automatic); {% endhighlight %} -{% highlight c# tabtitle="Xamarin" %} -//"App" is the class of Portable project -Assembly assembly = typeof(App).GetTypeInfo().Assembly; +{% highlight c# tabtitle="C# [Windows-specific]" %} //Creates an empty Word document instance WordDocument document = new WordDocument(); //Loads or opens an existing word document through Open method of WordDocument class -document.Open(assembly.GetManifestResourceStream("XamarinFormsApp1.Assets.Test.docx"),FormatType.Automatic); +document.Open(fileName); +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +'Creates an empty Word document instance +Dim document As New WordDocument() +'Loads or opens an existing word document through Open method of WordDocument class +document.Open(fileName) {% endhighlight %} {% endtabs %} @@ -133,73 +91,28 @@ You can open an existing document from stream by using either the overloads of [ {% tabs %} -{% highlight c# tabtitle="C#" %} -//Opens an existing document from stream through constructor of WordDocument class -WordDocument document = new WordDocument(wordDocumentStream, FormatType.Automatic); -{% endhighlight %} - -{% highlight vb.net tabtitle="VB.NET" %} -'Opens an existing document from stream through constructor of WordDocument class -Dim document As New WordDocument(wordDocumentStream, FormatType.Automatic) -{% endhighlight %} - -{% highlight c# tabtitle="UWP" %} -//"App" is the class of Portable project -Assembly assembly = typeof(App).GetTypeInfo().Assembly; -//Loads or opens an existing Word document from stream -Stream inputStream = assembly.GetManifestResourceStream("CreateWordSample.Assets.Test.docx"); -//Opens an existing document through constructor of `WordDocument` class -WordDocument document = new WordDocument(inputStream, FormatType.Docx); -{% endhighlight %} - -{% highlight c# tabtitle="ASP.NET Core" %} +{% highlight c# tabtitle="C# [Cross-platform]" %} //Opens an existing document from stream through constructor of `WordDocument` class FileStream fileStreamPath = new FileStream(@"Data/Hello World.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); //Opens an existing document from stream through constructor of WordDocument class WordDocument document = new WordDocument(fileStreamPath, FormatType.Automatic); {% endhighlight %} -{% highlight c# tabtitle="Xamarin" %} -//"App" is the class of Portable project -Assembly assembly = typeof(App).GetTypeInfo().Assembly; -//Loads or opens an existing Word document from stream -Stream inputStream = assembly.GetManifestResourceStream("XamarinFormsApp1.Assets.Hello World.docx"); -//Opens an existing document through constructor of `WordDocument` class -WordDocument document = new WordDocument(inputStream, FormatType.Automatic); +{% highlight c# tabtitle="C# [Windows-specific]" %} +//Opens an existing document from stream through constructor of WordDocument class +WordDocument document = new WordDocument(wordDocumentStream, FormatType.Automatic); {% endhighlight %} -{% endtabs %} - -{% tabs %} - -{% highlight c# tabtitle="C#" %} -//Creates an empty WordDocument instance -WordDocument document = new WordDocument(); -//Loads or opens an existing Word document through Open method of WordDocument class -document.Open(wordDocumentStream, FormatType.Automatic); +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +'Opens an existing document from stream through constructor of WordDocument class +Dim document As New WordDocument(wordDocumentStream, FormatType.Automatic) {% endhighlight %} -{% highlight vb.net tabtitle="VB.NET" %} -'Creates an empty WordDocument instance -Dim document As New WordDocument() -'Loads or opens an existing word document through Open method of WordDocument class -document.Open(wordDocumentStream, FormatType.Automatic) -{% endhighlight %} +{% endtabs %} -{% highlight c# tabtitle="UWP" %} -//"App" is the class of Portable project -Assembly assembly = typeof(App).GetTypeInfo().Assembly; -//Creates an empty WordDocument instance -using (WordDocument document = new WordDocument()) -{ - //Loads or opens an existing Word document from stream - Stream inputStream = assembly.GetManifestResourceStream("CreateWordSample.Assets.Test.docx"); - //Loads or opens an existing Word document through Open method of WordDocument class - document.Open(inputStream, FormatType.Docx); -} -{% endhighlight %} +{% tabs %} -{% highlight c# tabtitle="ASP.NET Core" %} +{% highlight c# tabtitle="C# [Cross-platform]" %} //Creates an empty WordDocument instance using (WordDocument document = new WordDocument()) { @@ -210,17 +123,18 @@ using (WordDocument document = new WordDocument()) } {% endhighlight %} -{% highlight c# tabtitle="Xamarin" %} -//"App" is the class of Portable project -Assembly assembly = typeof(App).GetTypeInfo().Assembly; +{% highlight c# tabtitle="C# [Windows-specific]" %} //Creates an empty WordDocument instance -using (WordDocument document = new WordDocument()) -{ - //Loads or opens an existing Word document from stream - Stream inputStream = assembly.GetManifestResourceStream("XamarinFormsApp1.Assets.Hello World.docx"); - //Loads or opens an existing Word document through Open method of WordDocument class - document.Open(inputStream, FormatType.Automatic); -} +WordDocument document = new WordDocument(); +//Loads or opens an existing Word document through Open method of WordDocument class +document.Open(wordDocumentStream, FormatType.Automatic); +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +'Creates an empty WordDocument instance +Dim document As New WordDocument() +'Loads or opens an existing word document through Open method of WordDocument class +document.Open(wordDocumentStream, FormatType.Automatic) {% endhighlight %} {% endtabs %} @@ -233,80 +147,48 @@ You can open an existing encrypted Word document from either the file system or {% tabs %} -{% highlight c# tabtitle="C#" %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +//Open an existing document from stream through constructor of WordDocument class. +FileStream fileStreamPath = new FileStream(@"Template.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); +//Open an encrypted Word document. +WordDocument document = new WordDocument(fileStreamPath, "password"); +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} //Opens an existing encrypted document through constructor of WordDocument class WordDocument document = new WordDocument(fileName, FormatType.Automatic, "password"); {% endhighlight %} -{% highlight vb.net tabtitle="VB.NET" %} +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} 'Opens an existing encrypted document through constructor of WordDocument class Dim document As New WordDocument(fileName, FormatType.Automatic, "password") {% endhighlight %} -{% highlight c# tabtitle="UWP" %} -//Instantiates the File Picker -FileOpenPicker openPicker = new FileOpenPicker(); -openPicker.SuggestedStartLocation = PickerLocationId.Desktop; -openPicker.FileTypeFilter.Add(".docx"); -//Creates a storage file from FileOpenPicker -StorageFile inputStorageFile = await openPicker.PickSingleFileAsync(); -WordDocument document = new WordDocument(); -await document.OpenAsync(inputStorageFile, FormatType.Docx, "password"); -{% endhighlight %} +{% endtabs %} + +{% tabs %} -{% highlight c# tabtitle="ASP.NET Core" %} +{% highlight c# tabtitle="C# [Cross-platform]" %} //Open an existing document from stream through constructor of WordDocument class. FileStream fileStreamPath = new FileStream(@"Template.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); //Open an encrypted Word document. WordDocument document = new WordDocument(fileStreamPath, "password"); {% endhighlight %} -{% highlight c# tabtitle="Xamarin" %} -//DocIO supports Encryption in Windows Forms, WPF, ASP.NET, ASP.NET MVC and UWP platforms alone. -{% endhighlight %} - -{% endtabs %} - -{% tabs %} - -{% highlight c# tabtitle="C#" %} +{% highlight c# tabtitle="C# [Windows-specific]" %} //Creates an empty Word document instance WordDocument document = new WordDocument(); //Loads or opens an existing encrypted Word document through Open method of WordDocument class document.Open(wordDocumentStream, FormatType.Automatic, "password"); {% endhighlight %} -{% highlight vb.net tabtitle="VB.NET" %} +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} 'Creates an empty Word document instance Dim document As New WordDocument() 'Loads or opens an existing encrypted Word document through Open method of WordDocument class document.Open(wordDocumentStream, FormatType.Automatic, "password") {% endhighlight %} -{% highlight c# tabtitle="UWP" %} -//"App" is the class of Portable project -Assembly assembly = typeof(App).GetTypeInfo().Assembly; -//Creates an empty WordDocument instance -using (WordDocument document = new WordDocument()) -{ - //Loads or opens an existing Word document from stream - Stream inputStream = assembly.GetManifestResourceStream("CreateWordSample.Assets.Test.docx"); - //Loads or opens an existing encrypted Word document through Open method of WordDocument class - document.Open(inputStream, FormatType.Docx, "password"); -} -{% endhighlight %} - -{% highlight c# tabtitle="ASP.NET Core" %} -//Open an existing document from stream through constructor of WordDocument class. -FileStream fileStreamPath = new FileStream(@"Template.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); -//Open an encrypted Word document. -WordDocument document = new WordDocument(fileStreamPath, "password"); -{% endhighlight %} - -{% highlight c# tabtitle="Xamarin" %} -//DocIO supports Encryption in Windows Forms, WPF, ASP.NET, ASP.NET MVC and UWP platforms alone. -{% endhighlight %} - {% endtabs %} You can download a complete working sample from Stream from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Security/Open-encrypted-Word-document). @@ -316,65 +198,49 @@ You can download a complete working sample from Stream from [GitHub](https://git You can open the ready only documents or read only streams using the [OpenReadOnly](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.WordDocument.html#Syncfusion_DocIO_DLS_WordDocument_OpenReadOnly_System_String_Syncfusion_DocIO_FormatType_) method. If the Word document for reading is opened by any other application such as Microsoft Word, then the same document can be opened using DocIO in ReadOnly mode. The following code sample demonstrates the same. {% tabs %} - -{% highlight c# tabtitle="C#" %} + +{% highlight c# tabtitle="C# [Cross-platform]" %} +//DocIO supports OpenReadOnly Word documents in Windows Forms, WPF, ASP.NET, and ASP.NET MVC platforms alone. +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} //Creates an empty WordDocument instance WordDocument document = new WordDocument(); //Loads or opens an existing word document using read only stream document.OpenReadOnly("Template.docx", Syncfusion.DocIO.FormatType.Docx); {% endhighlight %} -{% highlight vb.net tabtitle="VB.NET" %} +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} 'Creates an empty WordDocument instance Dim document As WordDocument = New WordDocument 'Loads or opens an existing word document using read only stream document.OpenReadOnly("Template.docx", Syncfusion.DocIO.FormatType.Docx) {% endhighlight %} -{% highlight c# tabtitle="UWP" %} -//DocIO supports OpenReadOnly Word documents in Windows Forms, WPF, ASP.NET, and ASP.NET MVC platforms alone. -{% endhighlight %} - -{% highlight c# tabtitle="ASP.NET Core" %} -//DocIO supports OpenReadOnly Word documents in Windows Forms, WPF, ASP.NET, and ASP.NET MVC platforms alone. -{% endhighlight %} - -{% highlight c# tabtitle="Xamarin" %} -//DocIO supports OpenReadOnly Word documents in Windows Forms, WPF, ASP.NET, and ASP.NET MVC platforms alone. -{% endhighlight %} - {% endtabs %} You can also open an existing encrypted document in read only mode using the overloads as mentioned below. {% tabs %} - -{% highlight c# tabtitle="C#" %} + +{% highlight c# tabtitle="C# [Cross-platform]" %} +//DocIO supports OpenReadOnly Word documents in Windows Forms, WPF, ASP.NET, and ASP.NET MVC platforms alone. +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} //Creates an empty WordDocument instance WordDocument document = new WordDocument(); //Loads or opens an existing encrypted word document using read only stream document.OpenReadOnly("Template.docx", Syncfusion.DocIO.FormatType.Docx , "password"); {% endhighlight %} -{% highlight vb.net tabtitle="VB.NET" %} +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} 'Creates an empty WordDocument instance Dim document As WordDocument = New WordDocument 'Loads or opens an existing encrypted word document using read only stream document.OpenReadOnly("Template.docx", Syncfusion.DocIO.FormatType.Docx, "password") {% endhighlight %} -{% highlight c# tabtitle="UWP" %} -//DocIO supports OpenReadOnly Word documents in Windows Forms, WPF, ASP.NET, and ASP.NET MVC platforms alone. -{% endhighlight %} - -{% highlight c# tabtitle="ASP.NET Core" %} -//DocIO supports OpenReadOnly Word documents in Windows Forms, WPF, ASP.NET, and ASP.NET MVC platforms alone. -{% endhighlight %} - -{% highlight c# tabtitle="Xamarin" %} -//DocIO supports OpenReadOnly Word documents in Windows Forms, WPF, ASP.NET, and ASP.NET MVC platforms alone. -{% endhighlight %} - {% endtabs %} You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Read-and-Save-document/Open-read-only-Word-document). @@ -385,7 +251,21 @@ You can save the created or manipulated Word document to file system using [Save {% tabs %} -{% highlight c# tabtitle="C#" %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +//Open an existing WordDocument +FileStream inputStream = new FileStream(inputFileName, FileMode.Open); +WordDocument document = new WordDocument(inputStream, FormatType.Docx); +//To-Do some manipulation +//To-Do some manipulation +//Saving the Word document +FileStream outputStream = new FileStream("Sample.docx", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite); +document.Save(outputStream, FormatType.Docx); +document.Close(); +outputStream.Flush(); +outputStream.Dispose(); +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} //Creates an empty WordDocument instance WordDocument document = new WordDocument(); //opens an existing Word document through Open method of WordDocument class @@ -396,7 +276,7 @@ document.Open(fileName); document.Save(outputFileName, FormatType.Docx); {% endhighlight %} -{% highlight vb.net tabtitle="VB.NET" %} +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} 'Creates an empty WordDocument instance Dim document As New WordDocument() 'opens an existing Word document through Open method of WordDocument class @@ -407,61 +287,6 @@ document.Open(fileName) document.Save(outputFileName, FormatType.Docx) {% endhighlight %} -{% highlight c# tabtitle="UWP" %} -//Instantiates the File Picker -FileOpenPicker openPicker = new FileOpenPicker(); -openPicker.SuggestedStartLocation = PickerLocationId.Desktop; -openPicker.FileTypeFilter.Add(".docx"); -//Creates a storage file from FileOpenPicker -StorageFile inputStorageFile = await openPicker.PickSingleFileAsync(); -WordDocument document = new WordDocument(); -await document.OpenAsync(inputStorageFile); -//To-Do some manipulation -//To-Do some manipulation -//Initializes FileSavePicker -FileSavePicker savePicker = new FileSavePicker(); -savePicker.SuggestedStartLocation = PickerLocationId.Desktop; -savePicker.SuggestedFileName = OutputFileName; -savePicker.FileTypeChoices.Add("Word Documents", new List() { ".docx" }); -//Creates a storage file from FileSavePicker -StorageFile outputStorageFile = await savePicker.PickSaveFileAsync(); -//Saves changes to the specified storage file -await document.SaveAsAsync(outputStorageFile, FormatType.Docx); -{% endhighlight %} - -{% highlight c# tabtitle="ASP.NET Core" %} -//Open an existing WordDocument -FileStream inputStream = new FileStream(inputFileName, FileMode.Open); -WordDocument document = new WordDocument(inputStream, FormatType.Docx); -//To-Do some manipulation -//To-Do some manipulation -//Saving the Word document -FileStream outputStream = new FileStream("Sample.docx", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite); -document.Save(outputStream, FormatType.Docx); -document.Close(); -outputStream.Flush(); -outputStream.Dispose(); -{% endhighlight %} - -{% highlight c# tabtitle="Xamarin" %} -//"App" is the class of Portable project -Assembly assembly = typeof(App).GetTypeInfo().Assembly; -Stream inputStream = assembly.GetManifestResourceStream(inputFilePath); -WordDocument document = new WordDocument(inputStream, FormatType.Docx); -//To-Do some manipulation -//To-Do some manipulation -//Saving the Word document -MemoryStream stream = new MemoryStream(); -document.Save(stream, FormatType.Docx); -stream.Position = 0; -//Save the stream as a file in the device and invoke it for viewing -Xamarin.Forms.DependencyService.Get().SaveAndView("Result.docx", "application/msword", stream); -//Closes the document -document.Close(); -//Please download the helper files from the below link to save the stream as file and open the file for viewing in Xamarin platform -//https://help.syncfusion.com/document-processing/word/word-library/net/create-word-document-in-xamarin#helper-files-for-xamarin -{% endhighlight %} - {% endtabs %} You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Read-and-Save-document/Open-and-save-Word-document). @@ -472,54 +297,7 @@ You can also save the created or manipulated word document to stream by using ov {% tabs %} -{% highlight c# tabtitle="C#" %} -//Creates an empty WordDocument instance -WordDocument document = new WordDocument(); -//Opens an existing Word document through Open method of WordDocument class -document.Open(fileName); -//To-Do some manipulation -//To-Do some manipulation -//Creates an instance of memory stream -MemoryStream stream = new MemoryStream(); -//Saves the document to stream -document.Save(stream, FormatType.Docx); -{% endhighlight %} - -{% highlight vb.net tabtitle="VB.NET" %} -'Creates an empty WordDocument instance -Dim document As New WordDocument() -'Opens an existing Word document through Open method of WordDocument class -document.Open(fileName) -'To-Do some manipulation -'To-Do some manipulation -'Creates an instance of memory stream -Dim stream As New MemoryStream() -'Saves the document to stream -document.Save(stream, FormatType.Docx) -{% endhighlight %} - -{% highlight c# tabtitle="UWP" %} -//Instantiates the File Picker -FileOpenPicker openPicker = new FileOpenPicker(); -openPicker.SuggestedStartLocation = PickerLocationId.Desktop; -openPicker.FileTypeFilter.Add(".docx"); -//Creates a storage file from FileOpenPicker -StorageFile inputStorageFile = await openPicker.PickSingleFileAsync(); -WordDocument document = new WordDocument(); -await document.OpenAsync(inputStorageFile); -//To-Do some manipulation -//To-Do some manipulation -//Creates an instance of memory stream -MemoryStream stream = new MemoryStream(); -//Saves the Word file to MemoryStream -await document.SaveAsync(stream, FormatType.Docx); -//Saves the stream as Word file in local machine -Save(stream, "Result.docx"); -//Please refer the below link to save Word document in UWP platform -//https://help.syncfusion.com/document-processing/word/word-library/net/create-word-document-in-uwp#save-word-document-in-uwp -{% endhighlight %} - -{% highlight c# tabtitle="ASP.NET Core" %} +{% highlight c# tabtitle="C# [Cross-platform]" %} //Creates an empty WordDocument instance using (WordDocument document = new WordDocument()) { @@ -535,48 +313,10 @@ using (WordDocument document = new WordDocument()) document.Save(stream, FormatType.Docx); //Closes the document document.Close(); - stream.Position = 0; - //Download Word document in the browser - return File(stream, "application/msword", "Result.docx"); } {% endhighlight %} -{% highlight c# tabtitle="Xamarin" %} -//"App" is the class of Portable project -Assembly assembly = typeof(App).GetTypeInfo().Assembly; -//Creates an empty WordDocument instance -using (WordDocument document = new WordDocument()) -{ - //Loads or opens an existing Word document from stream - Stream inputStream = assembly.GetManifestResourceStream("XamarinFormsApp1.Assets.Hello World.docx"); - //Loads or opens an existing Word document through Open method of WordDocument class - document.Open(inputStream, FormatType.Automatic); - //To-Do some manipulation - //To-Do some manipulation - //Creates an instance of memory stream - MemoryStream stream = new MemoryStream(); - //Saves the document to stream - document.Save(stream, FormatType.Docx); - //Closes the document - document.Close(); - //Save the stream as a file in the device and invoke it for viewing - Xamarin.Forms.DependencyService.Get().SaveAndView("Result.docx", "application/msword", stream); -} -//Please download the helper files from the below link to save the stream as file and open the file for viewing in Xamarin platform -//https://help.syncfusion.com/document-processing/word/word-library/net/create-word-document-in-xamarin#helper-files-for-xamarin -{% endhighlight %} - -{% endtabs %} - -You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Read-and-Save-document/Open-and-save-Word-document). - -## Sending to a client browser - -You can save and send the document to a client browser from a web site or web application by invoking the following shown overload of [Save](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.WordDocument.html#Syncfusion_DocIO_DLS_WordDocument_Save_System_String_Syncfusion_DocIO_FormatType_System_Web_HttpResponse_Syncfusion_DocIO_HttpContentDisposition_) method. This method explicitly makes use of an instance of [HttpResponse](https://docs.microsoft.com/en-us/dotnet/api/system.web.httpresponse?view=netframework-4.8) as its parameter in order to stream the document to client browser. So this overload is suitable for web application that references System.Web assembly. - -{% tabs %} - -{% highlight c# tabtitle="C#" %} +{% highlight c# tabtitle="C# [Windows-specific]" %} //Creates an empty WordDocument instance WordDocument document = new WordDocument(); //Opens an existing Word document through Open method of WordDocument class @@ -586,12 +326,12 @@ document.Open(fileName); //Creates an instance of memory stream MemoryStream stream = new MemoryStream(); //Saves the document to stream -document.Save(outputFileName, FormatType.Docx, Response, HttpContentDisposition.Attachment); +document.Save(stream, FormatType.Docx); {% endhighlight %} -{% highlight vb.net tabtitle="VB.NET" %} +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} 'Creates an empty WordDocument instance -Dim document As New WordDocument() +Dim document As New WordDocument() 'Opens an existing Word document through Open method of WordDocument class document.Open(fileName) 'To-Do some manipulation @@ -599,14 +339,20 @@ document.Open(fileName) 'Creates an instance of memory stream Dim stream As New MemoryStream() 'Saves the document to stream -document.Save(outputFileName, FormatType.Docx, Response, HttpContentDisposition.Attachment) -{% endhighlight %} - -{% highlight c# tabtitle="UWP" %} -//Saving and sending the Word document to a client browser from a web site is suitable for web applications alone. +document.Save(stream, FormatType.Docx) {% endhighlight %} -{% highlight c# tabtitle="ASP.NET Core" %} +{% endtabs %} + +You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Read-and-Save-document/Open-and-save-Word-document). + +## Sending to a client browser + +You can save and send the document to a client browser from a web site or web application by invoking the following shown overload of [Save](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.WordDocument.html#Syncfusion_DocIO_DLS_WordDocument_Save_System_String_Syncfusion_DocIO_FormatType_System_Web_HttpResponse_Syncfusion_DocIO_HttpContentDisposition_) method. This method explicitly makes use of an instance of [HttpResponse](https://docs.microsoft.com/en-us/dotnet/api/system.web.httpresponse?view=netframework-4.8) as its parameter in order to stream the document to client browser. So this overload is suitable for web application that references System.Web assembly. + +{% tabs %} + +{% highlight c# tabtitle="C# [Cross-platform]" %} //Creates a new instance of WordDocument (Empty Word Document) WordDocument document = new WordDocument(); //Adds new section to the document @@ -624,10 +370,32 @@ stream.Position = 0; return File(stream, "application/msword", "Result.docx"); {% endhighlight %} -{% highlight c# tabtitle="Xamarin" %} -//Saving and sending the Word document to a client browser from a web site is suitable for web applications alone. +{% highlight c# tabtitle="C# [Windows-specific]" %} +//Creates an empty WordDocument instance +WordDocument document = new WordDocument(); +//Opens an existing Word document through Open method of WordDocument class +document.Open(fileName); +//To-Do some manipulation +//To-Do some manipulation +//Creates an instance of memory stream +MemoryStream stream = new MemoryStream(); +//Saves the document to stream +document.Save(outputFileName, FormatType.Docx, Response, HttpContentDisposition.Attachment); {% endhighlight %} +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +'Creates an empty WordDocument instance +Dim document As New WordDocument() +'Opens an existing Word document through Open method of WordDocument class +document.Open(fileName) +'To-Do some manipulation +'To-Do some manipulation +'Creates an instance of memory stream +Dim stream As New MemoryStream() +'Saves the document to stream +document.Save(outputFileName, FormatType.Docx, Response, HttpContentDisposition.Attachment) +{% endhighlight %} + {% endtabs %} You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Read-and-Save-document/Send-Word-to-client-browser). @@ -640,7 +408,26 @@ Once the document manipulation and save operation are completed, you should clos {% tabs %} -{% highlight c# tabtitle="C#" %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +//Creates an empty WordDocument instance +using (WordDocument document = new WordDocument()) +{ + //Loads or opens an existing Word document from stream + FileStream fileStreamPath = new FileStream(@"Data/Hello World.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); + //Loads or opens an existing Word document through Open method of WordDocument class + document.Open(fileStreamPath, FormatType.Automatic); + //To-Do some manipulation + //To-Do some manipulation + //Creates an instance of memory stream + MemoryStream stream = new MemoryStream(); + //Saves the document to stream + document.Save(stream, FormatType.Docx); + //Closes the document + document.Close(); +} +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} //Creates an empty WordDocument instance WordDocument document = new WordDocument(); //opens an existing word document through Open method of WordDocument class @@ -655,7 +442,7 @@ document.Save(stream, FormatType.Docx); document.Close(); {% endhighlight %} -{% highlight vb.net tabtitle="VB.NET" %} +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} 'creates an empty WordDocument instance Dim document As New WordDocument() 'opens an existing word document through Open method of WordDocument class @@ -670,76 +457,6 @@ document.Save(stream, FormatType.Docx) document.Close() {% endhighlight %} -{% highlight c# tabtitle="UWP" %} -//Instantiates the File Picker -FileOpenPicker openPicker = new FileOpenPicker(); -openPicker.SuggestedStartLocation = PickerLocationId.Desktop; -openPicker.FileTypeFilter.Add(".docx"); -//Creates a storage file from FileOpenPicker -StorageFile inputStorageFile = await openPicker.PickSingleFileAsync(); -WordDocument document = new WordDocument(); -await document.OpenAsync(inputStorageFile); -//To-Do some manipulation -//To-Do some manipulation -//Creates an instance of memory stream -MemoryStream stream = new MemoryStream(); -//Saves the Word file to MemoryStream -await document.SaveAsync(stream, FormatType.Docx); -//Saves the stream as Word file in local machine -Save(stream, "Result.docx"); -//Closes the document -document.Close(); -//Please refer the below link to save Word document in UWP platform -//https://help.syncfusion.com/document-processing/word/word-library/net/create-word-document-in-uwp#save-word-document-in-uwp -{% endhighlight %} - -{% highlight c# tabtitle="ASP.NET Core" %} -//Creates an empty WordDocument instance -using (WordDocument document = new WordDocument()) -{ - //Loads or opens an existing Word document from stream - FileStream fileStreamPath = new FileStream(@"Data/Hello World.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); - //Loads or opens an existing Word document through Open method of WordDocument class - document.Open(fileStreamPath, FormatType.Automatic); - //To-Do some manipulation - //To-Do some manipulation - //Creates an instance of memory stream - MemoryStream stream = new MemoryStream(); - //Saves the document to stream - document.Save(stream, FormatType.Docx); - //Closes the document - document.Close() - stream.Position = 0; - //Download Word document in the browser - return File(stream, "application/msword", "Result.docx"); -} -{% endhighlight %} - -{% highlight c# tabtitle="Xamarin" %} -//"App" is the class of Portable project -Assembly assembly = typeof(App).GetTypeInfo().Assembly; -//Creates an empty WordDocument instance -using (WordDocument document = new WordDocument()) -{ - //Loads or opens an existing Word document from stream - Stream inputStream = assembly.GetManifestResourceStream("XamarinFormsApp1.Assets.Hello World.docx"); - //Loads or opens an existing Word document through Open method of WordDocument class - document.Open(inputStream, FormatType.Automatic); - //To-Do some manipulation - //To-Do some manipulation - //Creates an instance of memory stream - MemoryStream stream = new MemoryStream(); - //Saves the document to stream - document.Save(stream, FormatType.Docx); - //Save the stream as a file in the device and invoke it for viewing - Xamarin.Forms.DependencyService.Get().SaveAndView("Result.docx", "application/msword", stream); - //Closes the document - document.Close(); -} -//Please download the helper files from the below link to save the stream as file and open the file for viewing in Xamarin platform -//https://help.syncfusion.com/document-processing/word/word-library/net/create-word-document-in-xamarin#helper-files-for-xamarin -{% endhighlight %} - {% endtabs %} You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Read-and-Save-document/Open-and-save-Word-document). diff --git a/Document-Processing/Word/Word-Library/NET/NuGet-Packages-Required.md b/Document-Processing/Word/Word-Library/NET/NuGet-Packages-Required.md index 499c7e5dba..b533ae115e 100644 --- a/Document-Processing/Word/Word-Library/NET/NuGet-Packages-Required.md +++ b/Document-Processing/Word/Word-Library/NET/NuGet-Packages-Required.md @@ -93,17 +93,6 @@ Install-Package Syncfusion.DocIO.Net.Core -{{'[Xamarin](https://help.syncfusion.com/document-processing/word/word-library/net/create-word-document-in-xamarin)'|  markdownify }} - - -Syncfusion.Xamarin.DocIO.nupkg - - -Install-Package Syncfusion.Xamarin.DocIO - - - - {{'[UWP](https://help.syncfusion.com/document-processing/word/word-library/net/create-word-document-in-uwp)'|  markdownify }} @@ -155,6 +144,17 @@ Syncfusion.DocIO.AspNet.nupkg Install-Package Syncfusion.DocIO.AspNet + + +{{'[Xamarin](https://help.syncfusion.com/document-processing/word/word-library/net/create-word-document-in-xamarin)'|  markdownify }}
+ + +Syncfusion.Xamarin.DocIO.nupkg + + +Install-Package Syncfusion.Xamarin.DocIO + + N> 1. Starting with v16.2.0.x, if you reference Syncfusion® assemblies from trial setup or from the NuGet feed, you also have to add "Syncfusion.Licensing" assembly reference and include a license key in your projects. Please refer to this [link](https://help.syncfusion.com/common/essential-studio/licensing/overview) to know about registering Syncfusion® license key in your application to use our components. @@ -251,17 +251,6 @@ Install-Package Syncfusion.DocIORenderer.Net.Core -{{'[Xamarin](https://help.syncfusion.com/document-processing/word/conversions/word-to-pdf/net/convert-word-document-to-pdf-in-xamarin)'|  markdownify }} - - -Syncfusion.Xamarin.DocIORenderer.nupkg - - -Install-Package Syncfusion.Xamarin.DocIORenderer - - - - {{'[Windows UI Library (WinUI)](https://help.syncfusion.com/document-processing/word/conversions/word-to-pdf/net/convert-word-document-to-pdf-in-winui)'|  markdownify }}
{{'[.NET Multi-platform App UI (.NET MAUI)](https://help.syncfusion.com/document-processing/word/conversions/word-to-pdf/net/convert-word-document-to-pdf-in-maui)'|  markdownify }} @@ -304,6 +293,17 @@ Syncfusion.DocToPdfConverter.AspNet.nupkg Install-Package Syncfusion.DocToPdfConverter.AspNet + + +{{'[Xamarin](https://help.syncfusion.com/document-processing/word/conversions/word-to-pdf/net/convert-word-document-to-pdf-in-xamarin)'|  markdownify }}
+ + +Syncfusion.Xamarin.DocIORenderer.nupkg + + +Install-Package Syncfusion.Xamarin.DocIORenderer + + N> 1. Please refer the procedure to deploy your .NET Core application in Linux OS from [here](https://support.syncfusion.com/kb/article/7626/how-to-deploy-net-core-application-with-word-to-pdf-conversion-capabilities-in-linux-os). @@ -440,17 +440,6 @@ Install-Package Syncfusion.DocIORenderer.Net.Core -Xamarin - - -Syncfusion.Xamarin.DocIORenderer.nupkg - - -Install-Package Syncfusion.Xamarin.DocIORenderer - - - - Windows UI Library (WinUI)
.NET Multi-platform App UI (.NET MAUI) @@ -491,6 +480,17 @@ Syncfusion.DocIO.AspNet.nupkg Install-Package Syncfusion.DocIO.AspNet + + +{{'[Xamarin](https://help.syncfusion.com/document-processing/word/conversions/word-to-image/net/convert-word-document-to-image-in-xamarin)' | markdownify}}
+ + +Syncfusion.Xamarin.DocIORenderer.nupkg + + +Install-Package Syncfusion.Xamarin.DocIORenderer + + ### Additional NuGet packages required for Linux @@ -827,34 +827,6 @@ Install-Package Syncfusion.DocIORenderer.Net.Core Uninstall-Package Syncfusion.DocIORenderer.Net.Core -RemoveDependencies ~~~ -### Xamarin - -**NuGet Package:** Syncfusion.Xamarin.DocIO - -The package contains DocIO portable library that allows you to create, read and edit Word documents. - -~~~ -// Install package -Install-Package Syncfusion.Xamarin.DocIO -~~~ -~~~ -// Uninstall package -Uninstall-Package Syncfusion.Xamarin.DocIO -RemoveDependencies -~~~ - -**NuGet Package:** Syncfusion.Xamarin.DocIORenderer - -The package contains the DocIORenderer .NET portable library that allows you to convert the Word documents to PDF. - -~~~ -// Install package -Install-Package Syncfusion.Xamarin.DocIORenderer -~~~ -~~~ -// Uninstall package -Uninstall-Package Syncfusion.Xamarin.DocIORenderer -RemoveDependencies -~~~ - ### UWP **NuGet Package:** Syncfusion.DocIO.UWP diff --git a/Document-Processing/Word/Word-Library/NET/Word-document/Print-Word-documents.md b/Document-Processing/Word/Word-Library/NET/Word-document/Print-Word-documents.md index 3882cd0b0b..c485556971 100644 --- a/Document-Processing/Word/Word-Library/NET/Word-document/Print-Word-documents.md +++ b/Document-Processing/Word/Word-Library/NET/Word-document/Print-Word-documents.md @@ -11,7 +11,7 @@ You can print a Word document by utilizing DocIO’s capability to convert the d Initially you have to render the pages as images as shown below -N> Refer to the appropriate tabs in the code snippets section: ***C# [Cross-platform]*** for ASP.NET Core, Blazor, Xamarin, UWP, .NET MAUI, and WinUI; ***C# [Windows-specific]*** for WinForms and WPF; ***VB.NET [Windows-specific]*** for VB.NET applications. +N> Refer to the appropriate tabs in the code snippets section: ***C# [Windows-specific]*** for WinForms and WPF; ***VB.NET [Windows-specific]*** for VB.NET applications. {% tabs %} diff --git a/Document-Processing/Word/Word-Library/NET/Working-with-Charts.md b/Document-Processing/Word/Word-Library/NET/Working-with-Charts.md index 759ad1d46a..75249b63d7 100644 --- a/Document-Processing/Word/Word-Library/NET/Working-with-Charts.md +++ b/Document-Processing/Word/Word-Library/NET/Working-with-Charts.md @@ -476,6 +476,83 @@ Create a chart in a Word document using the .NET Word Library by utilizing the v The following code example illustrates how to create a chart in a Word document from a database. {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +//Create a new instance of WordDocument. +using (WordDocument document = new WordDocument()) +{ + document.EnsureMinimal(); + //Get the data table. + DataTable dataTable = GetDataTable(); + //Create and append the chart to the paragraph. + WChart chart = document.LastParagraph.AppendChart(446, 270); + chart.ChartType = OfficeChartType.Pie; + //Assign the data. + AddChartData(chart, dataTable); + //Set a chart title. + chart.ChartTitle = "Best Selling Products"; + IOfficeChartSerie pieSeries = chart.Series.Add("Sales"); + pieSeries.Values = chart.ChartData[2, 2, 11, 2]; + //Set the data label. + pieSeries.DataPoints.DefaultDataPoint.DataLabels.IsValue = true; + pieSeries.DataPoints.DefaultDataPoint.DataLabels.Position = OfficeDataLabelPosition.Outside; + //Set the category labels. + chart.PrimaryCategoryAxis.CategoryLabels = chart.ChartData[2, 1, 11, 1]; + //Set the legend. + chart.HasLegend = true; + //Save a Word document. + MemoryStream stream = new MemoryStream(); + document.Save(stream, FormatType.Docx); +} + +// Get the data to create a pie chart. +private static DataTable GetDataTable() +{ + string path = Path.GetFullPath(@"../../Data/DataBase.mdb"); + //Create a new instance of OleDbConnection. + OleDbConnection connection = new OleDbConnection(); + //Set the string to open a Database. + connection.ConnectionString = "Provider=Microsoft.JET.OLEDB.4.0;Password=\"\";User ID=Admin;Data Source=" + path; + //Open the Database connection. + connection.Open(); + //Get all the data from the Database. + OleDbCommand query = new OleDbCommand("select * from Products", connection); + //Create a new instance of OleDbDataAdapter. + OleDbDataAdapter adapter = new OleDbDataAdapter(query); + //Create a new instance of DataSet. + DataSet dataSet = new DataSet(); + //Add rows in the Dataset. + adapter.Fill(dataSet); + //Create a DataTable from the Dataset. + DataTable table = dataSet.Tables[0]; + table.TableName = "Products"; + return table; +} + +// Set the value for the chart. +private static void AddChartData(WChart chart, DataTable dataTable) +{ + //Set the value for the chart data. + chart.ChartData.SetValue(1, 1, "Names"); + chart.ChartData.SetValue(1, 2, "Product"); + + int rowIndex = 2; + int colIndex = 1; + //Get the value from the DataTable and set the value for the chart data + foreach (DataRow row in dataTable.Rows) + { + foreach (object val in row.ItemArray) + { + string value = val.ToString(); + chart.ChartData.SetValue(rowIndex, colIndex, value); + colIndex++; + if (colIndex == 3) + break; + } + colIndex = 1; + rowIndex++; + } +} +{% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} //Create a new instance of WordDocument. @@ -654,7 +731,7 @@ using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx) // or false to refresh only the data without evaluating formulas. chart.Refresh(false); MemoryStream stream = new MemoryStream(); - document.Save(stream, FormatType.docx); + document.Save(stream, FormatType.Docx); //Closes the Word document document.Close(); } @@ -716,7 +793,7 @@ using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx) //Refreshes chart data to set the modified values chart.Refresh(); MemoryStream stream = new MemoryStream(); - document.Save(stream, FormatType.docx); + document.Save(stream, FormatType.Docx); //Closes the Word document document.Close(); } @@ -922,6 +999,66 @@ Essential® DocIO allows to modify the side wall, back wall, floor {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +//Creates a new Word document +WordDocument document = new WordDocument(); +//Adds section to the document +IWSection sec = document.AddSection(); +//Adds paragraph to the section +IWParagraph paragraph = sec.AddParagraph(); +//Loads the excel file as stream +Stream excelStream = File.OpenRead("Excel_Template.xlsx"); +//Creates and Appends chart to the paragraph with excel stream as parameter +WChart chart = paragraph.AppendChart(excelStream, 1, "B2:C6", 470, 300); +//Sets chart type and title +chart.ChartType = OfficeChartType.Column_Clustered_3D; +chart.ChartTitle = "Purchase Details"; +chart.ChartTitleArea.FontName = "Calibri"; +chart.ChartTitleArea.Size = 14; +chart.ChartArea.Border.LinePattern = OfficeChartLinePattern.None; +//Sets name to chart series +chart.Series[0].Name = "Sum of Purchases"; +chart.Series[1].Name = "Sum of Future Expenses"; +chart.PrimaryCategoryAxis.Title = "Products"; +chart.PrimaryValueAxis.Title = "In Dollars"; +//Sets position of legend +chart.Legend.Position = OfficeLegendPosition.Bottom; +//Sets rotation and elevation values +chart.Rotation = 20; +chart.Elevation = 15; +//Sets side wall properties +chart.SideWall.Fill.FillType = OfficeFillType.SolidColor; +chart.SideWall.Fill.ForeColor = Color.White; +chart.SideWall.Fill.BackColor = Color.White; +chart.SideWall.Border.LineColor = Syncfusion.Drawing.Color.Beige; +//Sets floor fill option. +chart.Floor.Fill.FillType = OfficeFillType.Pattern; +//Sets the floor pattern Type. +chart.Floor.Fill.Pattern = OfficeGradientPattern.Pat_Divot; +//Sets the floor fore and Back ground color. +chart.Floor.Fill.ForeColor = Syncfusion.Drawing.Color.Blue; +chart.Floor.Fill.BackColor = Syncfusion.Drawing.Color.White; +//Sets the floor thickness. +chart.Floor.Thickness = 3; +//Sets the back wall fill option. +chart.BackWall.Fill.FillType = OfficeFillType.Gradient; +//Sets the Texture Type. +chart.BackWall.Fill.GradientColorType = OfficeGradientColor.TwoColor; +chart.BackWall.Fill.GradientStyle = OfficeGradientStyle.Diagonl_Down; +chart.BackWall.Fill.ForeColor = Color.WhiteSmoke; +chart.BackWall.Fill.BackColor = Color.LightBlue; +//Sets the Border Line color. +chart.BackWall.Border.LineColor = Syncfusion.Drawing.Color.Wheat; +//Sets the Picture Type. +chart.BackWall.PictureUnit = OfficeChartPictureType.stretch; +//Sets the back wall thickness. +chart.BackWall.Thickness = 10; +//Saves and closes the document +MemoryStream stream = new MemoryStream(); +document.Save(stream, FormatType.Docx); +document.Close(); +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} //Creates a new Word document WordDocument document = new WordDocument(); @@ -1248,92 +1385,6 @@ image.Save("ChartToImage.jpeg", ImageFormat.Jpeg) wordDocument.Close() {% endhighlight %} -{% highlight c# tabtitle="Xamarin" %} -//Open the file as Stream. -using (Stream docStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("Sample.Assets.TemplateWithChart.docx")) -{ - //Load file stream into Word document. - using (WordDocument wordDocument = new WordDocument(docStream, FormatType.Docx)) - { - //Get the first paragraph from the section.. - WParagraph paragraph = wordDocument.LastSection.Paragraphs[0]; - //Get the chart element from the paragraph. - WChart chart = paragraph.ChildEntities[0] as WChart; - //Create a new instance of DocIORenderer class. - using (DocIORenderer render = new DocIORenderer()) - { - //Convert chart to an image. - using (Stream stream = chart.SaveAsImage()) - { - //Save the stream as file in the device and invoke it for viewing. - Xamarin.Forms.DependencyService.Get().SaveAndView("ChartToImage.jpeg", "image/jpeg", stream as MemoryStream); - } - } - } -} -{% endhighlight %} - -{% highlight c# tabtitle="UWP" %} -// You can convert a chart to images in UWP using DocIORenderer, by using cross-platform NuGets or assemblies in a UWP application. -//Open the file as Stream. -using (Stream docStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("Sample.Assets.TemplateWithChart.docx")) -{ - //Load file stream into Word document. - using (WordDocument wordDocument = new WordDocument(docStream, FormatType.Docx)) - { - //Get the first paragraph from the section. - WParagraph paragraph = wordDocument.LastSection.Paragraphs[0]; - //Get the chart element from the paragraph. - WChart chart = paragraph.ChildEntities[0] as WChart; - //Create a new instance of DocIORenderer class. - using (DocIORenderer render = new DocIORenderer()) - { - //Convert chart to an image. - using (Stream stream = chart.SaveAsImage()) - { - //Save the memory stream as file. - Save(stream as MemoryStream, "ChartToImage.jpeg"); - } - } - } -} - -//Save the image. -async void Save(MemoryStream streams, string filename) -{ - streams.Position = 0; - StorageFile stFile; - if (!(Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons"))) - { - FileSavePicker savePicker = new FileSavePicker(); - savePicker.DefaultFileExtension = ".jpeg"; - savePicker.SuggestedFileName = filename; - savePicker.FileTypeChoices.Add("Image", new List() { ".jpeg" }); - stFile = await savePicker.PickSaveFileAsync(); - } - else - { - StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder; - stFile = await local.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting); - } - if (stFile != null) - { - using (IRandomAccessStream zipStream = await stFile.OpenAsync(FileAccessMode.ReadWrite)) - { - //Write compressed data from memory to file. - using (Stream outstream = zipStream.AsStreamForWrite()) - { - byte[] buffer = streams.ToArray(); - outstream.Write(buffer, 0, buffer.Length); - outstream.Flush(); - } - } - } - //Launch the saved image file. - await Windows.System.Launcher.LaunchFileAsync(stFile); -} -{% endhighlight %} - {% endtabs %} You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Charts/Convert-chart-to-image). diff --git a/Document-Processing/Word/Word-Library/NET/Working-with-Find-and-Replace.md b/Document-Processing/Word/Word-Library/NET/Working-with-Find-and-Replace.md index f40aa00128..532e488168 100644 --- a/Document-Processing/Word/Word-Library/NET/Working-with-Find-and-Replace.md +++ b/Document-Processing/Word/Word-Library/NET/Working-with-Find-and-Replace.md @@ -5,7 +5,7 @@ platform: document-processing control: DocIO documentation: UG --- -# Working with Find and Replace +# Working with Find and Replace in Word Library You can search a particular text you like to change and replace it with another text or part of the document. @@ -869,64 +869,6 @@ document.Save("Sample.docx", FormatType.Docx) document.Close() {% endhighlight %} -{% highlight c# tabtitle="Xamarin" %} -//"App" is the class of Portable project -Assembly assembly = typeof(App).GetTypeInfo().Assembly; -//Opens an existing wod document -WordDocument document = new WordDocument(assembly.GetManifestResourceStream("Sample.Assets.Template.docx"), FormatType.Automatic); -//Finds all the image placeholder text in the Word document -TextSelection[] textSelections = document.FindAll(new Regex("^//(.*)")); -for (int i = 0; i < textSelections.Length; i++) -{ - //Replaces the image placeholder text with desired image - WParagraph paragraph = new WParagraph(document); - Stream imageStream = assembly.GetManifestResourceStream("Sample.Assets."+ textSelections[i].SelectedText.Trim('/') + ".png"); - WPicture picture = paragraph.AppendPicture(imageStream) as WPicture; - TextSelection newSelection = new TextSelection(paragraph, 0, 1); - TextBodyPart bodyPart = new TextBodyPart(document); - bodyPart.BodyItems.Add(paragraph); - document.Replace(textSelections[i].SelectedText, bodyPart, true, true); -} -//Saves the Word document to MemoryStream -MemoryStream stream = new MemoryStream(); -document.Save(stream, FormatType.Docx); -//Save the stream as a file in the device and invoke it for viewing -Xamarin.Forms.DependencyService.Get().SaveAndView("Sample.docx", "application/msword", stream); -//Closes the document instance -document.Close(); -//Please download the helper files from the below link to save the stream as file and open the file for viewing in Xamarin platform -//https://help.syncfusion.com/document-processing/word/word-library/net/create-word-document-in-xamarin#helper-files-for-xamarin -{% endhighlight %} - -{% highlight c# tabtitle="UWP" %} -//"App" is the class of Portable project -Assembly assembly = typeof(App).GetTypeInfo().Assembly; -//Opens an existing word document -WordDocument document = new WordDocument(assembly.GetManifestResourceStream("Sample.Assets.Template.docx"), FormatType.Docx); -//Finds all the image placeholder text in the Word document -TextSelection[] textSelections = document.FindAll(new Regex("^//(.*)")); -for (int i = 0; i < textSelections.Length; i++) -{ - //Replaces the image placeholder text with desired image - WParagraph paragraph = new WParagraph(document); - Stream imageStream = assembly.GetManifestResourceStream("Sample.Assets." + textSelections[i].SelectedText.Trim('/') + ".png"); - WPicture picture = paragraph.AppendPicture(imageStream) as WPicture; - TextSelection newSelection = new TextSelection(paragraph, 0, 1); - TextBodyPart bodyPart = new TextBodyPart(document); - bodyPart.BodyItems.Add(paragraph); - document.Replace(textSelections[i].SelectedText, bodyPart, true, true); -} -//Saves the Word file to MemoryStream -MemoryStream stream = new MemoryStream(); -await document.SaveAsync(stream, FormatType.Docx); -//Saves the stream as Word document file in local machine -Save(stream, "Sample.docx"); -//Closes the document instance -document.Close(); -//Please refer the below link to save Word document in UWP platform -//https://help.syncfusion.com/document-processing/word/word-library/net/create-word-document-in-uwp#save-word-document-in-uwp -{% endhighlight %} - {% endtabs %} You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Find-and-Replace/Find-and-replace-text-with-image). diff --git a/Document-Processing/Word/Word-Library/NET/Working-with-Ink.md b/Document-Processing/Word/Word-Library/NET/Working-with-Ink.md index d10db85883..fdda426673 100644 --- a/Document-Processing/Word/Word-Library/NET/Working-with-Ink.md +++ b/Document-Processing/Word/Word-Library/NET/Working-with-Ink.md @@ -15,6 +15,8 @@ N> DocIO supports Ink only in DOCX format documents. The following code example illustrating how to create an Ink in a Word document. +N> Refer to the appropriate tabs in the code snippets section: ***C# [Cross-platform]*** for ASP.NET Core, Blazor, Xamarin, UWP, .NET MAUI, and WinUI; ***C# [Windows-specific]*** for WinForms and WPF; ***VB.NET [Windows-specific]*** for VB.NET applications. + {% tabs %} {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/DocIO-Examples/refs/heads/main/Ink/Create-ink/.NET/Create-ink/Program.cs" %} diff --git a/Document-Processing/Word/Word-Library/NET/Working-with-Paragraph.md b/Document-Processing/Word/Word-Library/NET/Working-with-Paragraph.md index 5e81b7b62c..29500617f1 100644 --- a/Document-Processing/Word/Word-Library/NET/Working-with-Paragraph.md +++ b/Document-Processing/Word/Word-Library/NET/Working-with-Paragraph.md @@ -1103,58 +1103,6 @@ document.Save("Sample.docx", FormatType.Docx) document.Close() {% endhighlight %} -{% highlight c# tabtitle="Xamarin" %} -//Create a new Word document -WordDocument document = new WordDocument(); -//Add new section to the document -IWSection section = document.AddSection(); -//Add new paragraph to the section -IWParagraph firstParagraph = section.AddParagraph(); -//Add new text to the paragraph -IWTextRange firstText = firstParagraph.AppendText("This is the first text range. "); -//Apply formatting for first text range -firstText.CharacterFormat.Bold = true; -firstText.CharacterFormat.FontSize = 14; -firstText.CharacterFormat.Shadow = true; -firstText.CharacterFormat.SmallCaps = true; -IWTextRange secondText = firstParagraph.AppendText("This the second text range"); -//Apply formatting for second text range -secondText.CharacterFormat.HighlightColor = Syncfusion.Drawing.Color.GreenYellow; -secondText.CharacterFormat.UnderlineStyle = Syncfusion.Drawing.UnderlineStyle.DotDash; -secondText.CharacterFormat.Italic = true; -secondText.CharacterFormat.FontName = "Times New Roman"; -secondText.CharacterFormat.TextColor = Syncfusion.Drawing.Color.Green; -//Add new paragraph to the section -IWParagraph secondParagraph = section.AddParagraph(); -//Add new text to the paragraph -IWTextRange thirdText = secondParagraph.AppendText("שלום עולם"); -thirdText.CharacterFormat.Bidi = true; -//Set language Identifier for right to left characters. -thirdText.CharacterFormat.LocaleIdBidi = (short)LocaleIDs.he_IL; -//Add third paragraph to the section. -IWParagraph thirdParagraph = section.AddParagraph(); -//Add text to the third paragraph -IWTextRange fourthText = thirdParagraph.AppendText("X"); -IWTextRange fifthText = thirdParagraph.AppendText("2"); -//Apply super script formatting for fifth text range. -fifthText.CharacterFormat.SubSuperScript = SubSuperScript.SuperScript; -IWParagraph fourthParagraph = section.AddParagraph(); -//Add text to the fourth paragraph -IWTextRange sixthText = fourthParagraph.AppendText("m"); -IWTextRange seventhText = fourthParagraph.AppendText("3"); -//Apply sub script formatting for seventh text range -seventhText.CharacterFormat.SubSuperScript = SubSuperScript.SubScript; -//Save and close the Word document instance -MemoryStream stream = new MemoryStream(); -//Save the Word file to MemoryStream -document.Save(stream, FormatType.Docx); -document.Close(); -//Save the stream as a file in the device and invoke it for viewing -Xamarin.Forms.DependencyService.Get().SaveAndView("Result.docx", "application/msword", stream); -//Download the helper files from the following link to save the stream as file and open the file for viewing in Xamarin platform -//https://help.syncfusion.com/document-processing/word/word-library/net/create-word-document-in-xamarin#helper-files-for-xamarin -{% endhighlight %} - {% endtabs %} You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Paragraphs/Apply-formatting-to-text). diff --git a/Document-Processing/Word/Word-Library/NET/Working-with-Security.md b/Document-Processing/Word/Word-Library/NET/Working-with-Security.md index 4204f1cce1..c6236641e7 100644 --- a/Document-Processing/Word/Word-Library/NET/Working-with-Security.md +++ b/Document-Processing/Word/Word-Library/NET/Working-with-Security.md @@ -91,58 +91,6 @@ document.Save("Sample.docx", FormatType.Docx) document.Close() {% endhighlight %} -{% highlight c# tabtitle="UWP" %} -//"App" is the class of Portable project. -Assembly assembly = typeof(App).GetTypeInfo().Assembly; -using (WordDocument document = new WordDocument()) -{ - //Loads or opens an existing Word document from stream - Stream inputStream = assembly.GetManifestResourceStream("CreateWordSample.Assets.Test.doc"); - //Loads or opens an existing Word document through Open method of WordDocument class - document.Open(inputStream, FormatType.Automatic, "password"); - MemoryStream stream = new MemoryStream(); - //Saves the Word file to MemoryStream - await document.SaveAsync(stream, FormatType.Doc); - //Saves the stream as Word file in local machine - Save(stream, "Result.doc"); - document.Close(); -} -//Saves the Word document -async void Save(MemoryStream streams, string filename) -{ - streams.Position = 0; - StorageFile stFile; - if (!(Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons"))) - { - FileSavePicker savePicker = new FileSavePicker(); - savePicker.DefaultFileExtension = ".doc"; - savePicker.SuggestedFileName = filename; - savePicker.FileTypeChoices.Add("Word Documents", new List() {".doc"}); - stFile = await savePicker.PickSaveFileAsync(); - } - else - { - StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder; - stFile = await local.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting); - } - if (stFile != null) - { - using (IRandomAccessStream zipStream = await stFile.OpenAsync(FileAccessMode.ReadWrite)) - { - //Write compressed data from memory to file - using (Stream outstream = zipStream.AsStreamForWrite()) - { - byte[] buffer = streams.ToArray(); - outstream.Write(buffer, 0, buffer.Length); - outstream.Flush(); - } - } -} -//Launch the saved Word file -await Windows.System.Launcher.LaunchFileAsync(stFile); -} -{% endhighlight %} - {% endtabs %} You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Security/Open-encrypted-Word-document). @@ -187,30 +135,6 @@ document.Save("Sample.docx", FormatType.Docx) document.Close() {% endhighlight %} -{% highlight c# tabtitle="UWP" %} -//"App" is the class of Portable project -Assembly assembly = typeof(App).GetTypeInfo().Assembly; -//Create new Word document instance -using (WordDocument document = new WordDocument()) -{ - //Loads or opens an existing Word document from stream - Stream inputStream = assembly.GetManifestResourceStream("Sample.Assets.Template.docx"); - //Loads or opens an existing Word document using the Open method of WordDocument class - document.Open(inputStream, FormatType.Docx, "password"); - //Removes encryption in Word document - document.RemoveEncryption(); - MemoryStream stream = new MemoryStream(); - //Saves the Word file to MemoryStream - document.Save(stream, FormatType.Docx); - //Closes the Word document instance - document.Close(); - //Saves the stream as Word file in local machine - Save(stream, "Sample.Docx"); -} -//Refer to the following link to save Word document in UWP platform -//https://help.syncfusion.com/document-processing/word/word-library/net/create-word-document-in-uwp#save-word-document-in-uwp -{% endhighlight %} - {% endtabs %} You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Security/Remove-encryption-from-Word-document). diff --git a/Document-Processing/Word/Word-Library/NET/Working-with-SmartArts.md b/Document-Processing/Word/Word-Library/NET/Working-with-SmartArts.md index 86532c16f1..8010d3fd46 100644 --- a/Document-Processing/Word/Word-Library/NET/Working-with-SmartArts.md +++ b/Document-Processing/Word/Word-Library/NET/Working-with-SmartArts.md @@ -28,6 +28,8 @@ N> DocIO supports SmartArt only in DOCX format document. The following code example illustrating how to create a **List SmartArt** in a Word document. +N> Refer to the appropriate tabs in the code snippets section: ***C# [Cross-platform]*** for ASP.NET Core, Blazor, Xamarin, UWP, .NET MAUI, and WinUI; ***C# [Windows-specific]*** for WinForms and WPF; ***VB.NET [Windows-specific]*** for VB.NET applications. + {% tabs %} {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/DocIO-Examples/main/SmartArts/Create-SmartArt-List/.NET/Create-SmartArt-List/Program.cs" %} diff --git a/Document-Processing/Word/Word-Library/NET/Working-with-Table-Of-Contents.md b/Document-Processing/Word/Word-Library/NET/Working-with-Table-Of-Contents.md index 650c5f4b7f..0821b3725b 100644 --- a/Document-Processing/Word/Word-Library/NET/Working-with-Table-Of-Contents.md +++ b/Document-Processing/Word/Word-Library/NET/Working-with-Table-Of-Contents.md @@ -69,6 +69,8 @@ To quickly start create and update a table of contents in Word document, please The following code example shows how to add a table of contents (TOC) in Word document. +N> Refer to the appropriate tabs in the code snippets section: ***C# [Cross-platform]*** for ASP.NET Core, Blazor, Xamarin, UWP, .NET MAUI, and WinUI; ***C# [Windows-specific]*** for WinForms and WPF; ***VB.NET [Windows-specific]*** for VB.NET applications. + {% tabs %} {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/DocIO-Examples/main/Table-Of-Contents/Add-table-of-contents/.NET/Add-table-of-contents/Program.cs" %} @@ -214,10 +216,6 @@ document.Save("Sample.docx", FormatType.Docx) document.Close() {% endhighlight %} -{% highlight c# tabtitle="UWP" %} -//DocIO supports Table of contents in WPF, Windows Forms platforms alone -{% endhighlight %} - {% endtabs %} You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Table-Of-Contents/Add-table-of-contents). @@ -228,7 +226,7 @@ You can also update or re-build the TOC in an existing document or document crea N> 1. Updating of TOC is not supported in Silverlight, WinRT, Universal and Windows Phone applications. N> 2. Updating TOC makes use of the Word to PDF layout engine that may lead to update incorrect page number due to its limitations. -N> 3. In ASP.NET Core, Blazor, and Xamarin platforms, to update TOC in a Word document we recommend you to use Word to PDF [assemblies](https://help.syncfusion.com/document-processing/word/word-library/net/assemblies-required#converting-word-document-to-pdf) or [NuGet](https://help.syncfusion.com/document-processing/word/word-library/net/nuget-packages-required#converting-word-document-to-pdf) as a reference in your application. +N> 3. In ASP.NET Core, Blazor, and UWP platforms, to update TOC in a Word document we recommend you to use Word to PDF [assemblies](https://help.syncfusion.com/document-processing/word/word-library/net/assemblies-required#converting-word-document-to-pdf) or [NuGet](https://help.syncfusion.com/document-processing/word/word-library/net/nuget-packages-required#converting-word-document-to-pdf) as a reference in your application. The following code example shows how to update a TOC in an existing word document. @@ -267,13 +265,6 @@ document.Save("Sample.docx", FormatType.Docx) document.Close() {% endhighlight %} -{% highlight c# tabtitle="UWP" %} -//DocIO supports Table of contents in WPF, Windows Forms platforms alone - -//Please download the helper files from the below link to save the stream as file and open the file for viewing in Xamarin platform -//https://help.syncfusion.com/document-processing/word/word-library/net/create-word-document-in-xamarin#helper-files-for-xamarin -{% endhighlight %} - {% endtabs %} You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Table-Of-Contents/Update-table-of-contents). @@ -451,10 +442,6 @@ document.Save("Sample.docx", FormatType.Docx) document.Close() {% endhighlight %} -{% highlight c# tabtitle="UWP" %} -//DocIO supports Table of contents in WPF, Windows Forms platforms alone -{% endhighlight %} - {% endtabs %} You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Table-Of-Contents/TOC-with-user-defined-styles). @@ -709,10 +696,6 @@ Using document As WordDocument = New WordDocument() End Using {% endhighlight %} -{% highlight c# tabtitle="UWP" %} -//DocIO doesn't support updating table of contents in UWP platform. -{% endhighlight %} - {% endtabs %} ## Removing table of contents @@ -763,10 +746,6 @@ Using document As WordDocument = New WordDocument End Using {% endhighlight %} -{% highlight c# tabtitle="UWP" %} -//DocIO does not support a table of contents directly in the UWP platform. You can achieve this by using the Syncfusion.DocIORenderer.Net.Core NuGet package in UWP. -{% endhighlight %} - {% endtabs %} The helper methods helps for removing table of contents (TOC) in Word document. @@ -1086,8 +1065,6 @@ N> Update the SEQ fields in the Word document by calling the [UpdateDocumentFiel The following code example illustrates how to add a Table of Figures in a Word document using the .NET Word Library (DocIO). -N> Refer to the appropriate tabs in the code snippets section: ***C# [Cross-platform]*** for ASP.NET Core, Blazor, Xamarin, UWP, .NET MAUI, and WinUI; ***C# [Windows-specific]*** for WinForms and WPF; ***VB.NET [Windows-specific]*** for VB.NET applications. - {% tabs %} {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/DocIO-Examples/main/Table-Of-Contents/Table_of_figures/.NET/Table_of_figures/Program.cs" %} @@ -1350,10 +1327,6 @@ End Using {% endhighlight %} -{% highlight c# tabtitle="UWP" %} -//DocIO does not support a table of figures directly in the UWP platform. You can achieve this by using the Syncfusion.DocIORenderer.Net.Core NuGet package in UWP. -{% endhighlight %} - {% endtabs %} You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Table-Of-Contents/Table_of_figures). @@ -1641,6 +1614,7 @@ Using document As New WordDocument("Input.docx", FormatType.Docx) End Using {% endhighlight %} + {% endtabs %} You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Table-Of-Contents/Exclude_caption_label_numbers). diff --git a/Document-Processing/Word/Word-Library/NET/Working-with-Tables.md b/Document-Processing/Word/Word-Library/NET/Working-with-Tables.md index a3f63c4688..99527a17da 100644 --- a/Document-Processing/Word/Word-Library/NET/Working-with-Tables.md +++ b/Document-Processing/Word/Word-Library/NET/Working-with-Tables.md @@ -470,56 +470,134 @@ The following code example illustrates how to align text within a table. {% tabs %} -{% highlight c# tabtitle="C# [Windows-specific]" %} -private void AlignCellContent(WTableCell tableCell, VerticalAlignment verticalAlignment, HorizontalAlignment horizontalAlignment) +{% highlight c# tabtitle="C# [Cross-platform]" %} +private void AlignCellContentForTable(WTable table, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment) { - //Sets vertical alignment to the cell. - tableCell.CellFormat.VerticalAlignment = verticalAlignment; - //Iterates body items in table cell and set horizontal alignment. - AlignCellContentForTextBody(tableCell, horizontalAlignment); + //Iterates the row collection in a table. + foreach (WTableRow row in table.Rows) + { + //Iterates the cell collection in a table row. + foreach (WTableCell cell in row.Cells) + { + //Sets vertical alignment to the cell. + cell.CellFormat.VerticalAlignment = verticalAlignment; + //Iterate items in cell and set horizontal alignment. + AlignCellContentForTextBody(cell, horizontalAlignment, verticalAlignment); + } + } } -private void AlignCellContentForTextBody(WTextBody textBody, HorizontalAlignment horizontalAlignment) +private void AlignCellContentForTextBody(WTextBody textBody, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment) { - for (int i = 0; i < textBody.ChildEntities.Count; i++) - { - //IEntity is the basic unit in DocIO DOM. - //Accesses the body items as IEntity - IEntity bodyItemEntity = textBody.ChildEntities[i]; - //A Text body has 3 types of elements - Paragraph, Table and Block Content Control - //Decides the element type by using EntityType - switch (bodyItemEntity.EntityType) - { - case EntityType.Paragraph: - WParagraph paragraph = bodyItemEntity as WParagraph; - //Sets horizontal alignment for paragraph. - paragraph.ParagraphFormat.HorizontalAlignment = horizontalAlignment; - break; - case EntityType.Table: - //Table is a collection of rows and cells - //Iterates through table's DOM and set horizontal alignment. - AlignCellContentForTable(bodyItemEntity as WTable, horizontalAlignment); - break; - case EntityType.BlockContentControl: - BlockContentControl blockContentControl = bodyItemEntity as BlockContentControl; - //Iterates to the body items of Block Content Control and set horizontal alignment. - AlignCellContentForTextBody(blockContentControl.TextBody, horizontalAlignment); - break; - } - } + for (int i = 0; i < textBody.ChildEntities.Count; i++) + { + //IEntity is the basic unit in DocIO DOM. + //Accesses the body items as IEntity + IEntity bodyItemEntity = textBody.ChildEntities[i]; + //A Text body has 3 types of elements - Paragraph, Table and Block Content Control. + //Decides the element type by using EntityType. + switch (bodyItemEntity.EntityType) + { + case EntityType.Paragraph: + WParagraph paragraph = bodyItemEntity as WParagraph; + //Sets horizontal alignment for paragraph. + paragraph.ParagraphFormat.HorizontalAlignment = horizontalAlignment; + break; + case EntityType.Table: + //Table is a collection of rows and cells. + //Iterates through table's DOM and set horizontal alignment. + AlignCellContentForTable(bodyItemEntity as WTable, horizontalAlignment, verticalAlignment); + break; + case EntityType.BlockContentControl: + BlockContentControl blockContentControl = bodyItemEntity as BlockContentControl; + //Iterates to the body items of Block Content Control and set horizontal alignment. + AlignCellContentForTextBody(blockContentControl.TextBody, horizontalAlignment, verticalAlignment); + break; + } + } } -private void AlignCellContentForTable(WTable table, Syncfusion.DocIO.DLS.HorizontalAlignment horizontalAlignment) +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} +private void AlignCellContentForTable(WTable table, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment) { - //Iterates the row collection in a table - foreach (WTableRow row in table.Rows) - { - //Iterates the cell collection in a table row - foreach (WTableCell cell in row.Cells) - { - //Iterate items in cell and set horizontal alignment - AlignCellContentForTextBody(cell, horizontalAlignment); - } - } + //Iterates the row collection in a table. + foreach (WTableRow row in table.Rows) + { + //Iterates the cell collection in a table row. + foreach (WTableCell cell in row.Cells) + { + //Sets vertical alignment to the cell. + cell.CellFormat.VerticalAlignment = verticalAlignment; + //Iterate items in cell and set horizontal alignment. + AlignCellContentForTextBody(cell, horizontalAlignment, verticalAlignment); + } + } } +private void AlignCellContentForTextBody(WTextBody textBody, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment) +{ + for (int i = 0; i < textBody.ChildEntities.Count; i++) + { + //IEntity is the basic unit in DocIO DOM. + //Accesses the body items as IEntity + IEntity bodyItemEntity = textBody.ChildEntities[i]; + //A Text body has 3 types of elements - Paragraph, Table and Block Content Control. + //Decides the element type by using EntityType. + switch (bodyItemEntity.EntityType) + { + case EntityType.Paragraph: + WParagraph paragraph = bodyItemEntity as WParagraph; + //Sets horizontal alignment for paragraph. + paragraph.ParagraphFormat.HorizontalAlignment = horizontalAlignment; + break; + case EntityType.Table: + //Table is a collection of rows and cells. + //Iterates through table's DOM and set horizontal alignment. + AlignCellContentForTable(bodyItemEntity as WTable, horizontalAlignment, verticalAlignment); + break; + case EntityType.BlockContentControl: + BlockContentControl blockContentControl = bodyItemEntity as BlockContentControl; + //Iterates to the body items of Block Content Control and set horizontal alignment. + AlignCellContentForTextBody(blockContentControl.TextBody, horizontalAlignment, verticalAlignment); + break; + } + } +} +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Private Sub AlignCellContentForTable(table As WTable, horizontalAlignment As HorizontalAlignment, verticalAlignment As VerticalAlignment) + ' Iterates the row collection in a table. + For Each row As WTableRow In table.Rows + ' Iterates the cell collection in a table row. + For Each cell As WTableCell In row.Cells + ' Sets vertical alignment to the cell. + cell.CellFormat.VerticalAlignment = verticalAlignment + ' Iterate items in cell and set horizontal alignment. + AlignCellContentForTextBody(cell, horizontalAlignment, verticalAlignment) + Next + Next +End Sub + +Private Sub AlignCellContentForTextBody(textBody As WTextBody, horizontalAlignment As HorizontalAlignment, verticalAlignment As VerticalAlignment) + For i As Integer = 0 To textBody.ChildEntities.Count - 1 + ' IEntity is the basic unit in DocIO DOM. + Dim bodyItemEntity As IEntity = textBody.ChildEntities(i) + ' A Text body has 3 types of elements - Paragraph, Table and Block Content Control. + Select Case bodyItemEntity.EntityType + Case EntityType.Paragraph + Dim paragraph As WParagraph = TryCast(bodyItemEntity, WParagraph) + ' Sets horizontal alignment for paragraph. + paragraph.ParagraphFormat.HorizontalAlignment = horizontalAlignment + Case EntityType.Table + ' Iterates through table's DOM and set alignment. + AlignCellContentForTable(TryCast(bodyItemEntity, WTable), horizontalAlignment, verticalAlignment) + Case EntityType.BlockContentControl + Dim blockContentControl As BlockContentControl = TryCast(bodyItemEntity, BlockContentControl) + ' Iterates to the body items of Block Content Control. + AlignCellContentForTextBody(blockContentControl.TextBody, horizontalAlignment, verticalAlignment) + End Select + Next +End Sub {% endhighlight %} {% endtabs %} diff --git a/Document-Processing/Word/Word-Library/NET/Working-with-Word-document.md b/Document-Processing/Word/Word-Library/NET/Working-with-Word-document.md index 665ebd1f66..0571ab7ebc 100644 --- a/Document-Processing/Word/Word-Library/NET/Working-with-Word-document.md +++ b/Document-Processing/Word/Word-Library/NET/Working-with-Word-document.md @@ -377,10 +377,6 @@ Using document As WordDocument = New WordDocument("Template.docx", FormatType.Do End Using {% endhighlight %} -{% highlight c# tabtitle="UWP" %} -//DocIO supports updating word count in WPF, Windows Forms, ASP.NET and ASP.NET MVC, platforms alone. -{% endhighlight %} - {% endtabs %} You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Word-document/Update-words-count). @@ -432,10 +428,6 @@ Using document As WordDocument = New WordDocument("Template.docx", FormatType.Do End Using {% endhighlight %} -{% highlight c# tabtitle="UWP" %} -//DocIO supports updating word count in WPF, Windows Forms, ASP.NET and ASP.NET MVC, platforms alone. -{% endhighlight %} - {% endtabs %} You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Word-document/Update-pages-count). @@ -443,6 +435,7 @@ You can download a complete working sample from [GitHub](https://github.com/Sync N> 1. The word to PDF layout engine is used for updating the page count in word document. Due to its limitations, it may result in an incorrect page count and the execution of this process may take some time. N> 2. In ASP.NET Core and Xamarin platforms, to update page count in a Word document we recommend you to use Word to PDF [assemblies](https://help.syncfusion.com/document-processing/word/word-library/net/assemblies-required#converting-word-document-to-pdf) or [NuGet](https://help.syncfusion.com/document-processing/word/word-library/net/nuget-packages-required#converting-word-document-to-pdf) as a reference in your application to update page count in a Word document. N> 3. DocIO uses the Word-to-PDF layout engine to update page count. If the required fonts are missing in the environment, alternate fonts are used, which may affect accuracy. [Ensure](https://support.syncfusion.com/kb/article/6821/check-whether-fonts-in-word-document-are-available-in-machine-for-pdf-or-image-conversion) all fonts used in the input document are available for a correct page count. +N> 4. In UWP platform, to updates paragraph, word, and character counts in the document using the [UpdateWordCount()](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.WordDocument.html#Syncfusion_DocIO_DLS_WordDocument_UpdateWordCount) API. ### Adding Custom Document properties @@ -876,50 +869,6 @@ document.Save("Sample.docx", FormatType.Docx) document.Close() {% endhighlight %} -{% highlight c# tabtitle="Xamarin" %} -//"App" is the class of Portable project -Assembly assembly = typeof(App).GetTypeInfo().Assembly; -using (WordDocument document = new WordDocument(assembly.GetManifestResourceStream("XamarinFormsApp1.Assets.Hello World.docx"), FormatType.Docx)) -{ - document.Background.Type = BackgroundType.Picture; - //Opens the existing image - Stream imageStream = assembly.GetManifestResourceStream("CreateWordSample.Assets.Picture.png"); - MemoryStream memoryStream = new MemoryStream(); - imageStream.CopyTo(memoryStream); - document.Background.Picture = memoryStream.ToArray(); - MemoryStream stream = new MemoryStream(); - document.Save(stream, FormatType.Docx); - //Save the stream as a file in the device and invoke it for viewing - Xamarin.Forms.DependencyService.Get().SaveAndView("WorkingWordDoc.docx", "application/msword", stream); - //Closes the document - document.Close(); - //Please download the helper files from the below link to save the stream as file and open the file for viewing in Xamarin platform - //https://help.syncfusion.com/document-processing/word/word-library/net/create-word-document-in-xamarin#helper-files-for-xamarin -} -{% endhighlight %} - -{% highlight c# tabtitle="UWP" %} -//"App" is the class of Portable project. -Assembly assembly = typeof(App).GetTypeInfo().Assembly; -using (WordDocument document = new WordDocument(assembly.GetManifestResourceStream("CreateWordSample.Assets.Test.docx"), FormatType.Docx)) -{ - document.Background.Type = BackgroundType.Picture; - //Opens the existing image - Stream imageStream = assembly.GetManifestResourceStream("CreateWordSample.Assets.Picture.png"); - MemoryStream memoryStream = new MemoryStream(); - imageStream.CopyTo(memoryStream); - document.Background.Picture = memoryStream.ToArray(); - MemoryStream stream = new MemoryStream(); - //Saves the Word file to MemoryStream - await document.SaveAsync(stream, FormatType.Docx); - //Saves the stream as Word file in local machine - Save(stream, "Result.docx"); - //Please refer the below link to save Word document in UWP platform - //https://help.syncfusion.com/document-processing/word/word-library/net/create-word-document-in-uwp#save-word-document-in-uwp - document.Close(); -} -{% endhighlight %} - {% endtabs %} You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Word-document/Apply-picture-background-to-document). diff --git a/Document-Processing/Word/Word-Library/NET/faqs/migration-from-microsoft-office-automation-to-docio.md b/Document-Processing/Word/Word-Library/NET/faqs/migration-from-microsoft-office-automation-to-docio.md index 6eaab6a03f..3ab3f31188 100644 --- a/Document-Processing/Word/Word-Library/NET/faqs/migration-from-microsoft-office-automation-to-docio.md +++ b/Document-Processing/Word/Word-Library/NET/faqs/migration-from-microsoft-office-automation-to-docio.md @@ -81,8 +81,32 @@ DocIO performs Mail merge by using the following methods: The following code example performs Mail merge by using the [Execute](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MailMerge.html#Syncfusion_DocIO_DLS_MailMerge_Execute_System_Data_DataTable_) method. +N> Refer to the appropriate tabs in the code snippets section: ***C# [Cross-platform]*** for ASP.NET Core, Blazor, Xamarin, UWP, .NET MAUI, and WinUI; ***C# [Windows-specific]*** for WinForms and WPF; ***VB.NET [Windows-specific]*** for VB.NET applications. + {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +string dataBase = "Northwind.mdb"; +//Opens existing template. +FileStream docStream = new FileStream("Template.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); +WordDocument doc = new WordDocument(docStream, FormatType.Docx); +//Gets Data from the Database. +OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + dataBase); +conn.Open(); +//Populates the data table. +DataTable table = new DataTable(); +OleDbDataAdapter adapter = new OleDbDataAdapter("select * from employees", conn); +adapter.Fill(table); +adapter.Dispose(); +//Performs Mail Merge. +doc.MailMerge.Execute(table); +//Saves the document. +MemoryStream stream = new MemoryStream(); +doc.Save(stream, FormatType.Docx); +//Closes the document. +doc.Close(); +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} string dataBase = "Northwind.mdb"; //Opens existing template. @@ -221,6 +245,21 @@ The following code example illustrates how to perform a simple find and replace {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +//Opens the Word document. +FileStream docStream = new FileStream("Template.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); +WordDocument document = new WordDocument(docStream, FormatType.Docx); +//Defines replacement text. +string replaceText = "World"; +//Performs replace. +document.Replace(new Regex("Hello"), replaceText); +//Saves the document. +MemoryStream stream = new MemoryStream(); +document.Save(stream, FormatType.Docx); +//Closes the document. +document.Close(); +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} //Opens the Word document. WordDocument document = new WordDocument("Template.docx",FormatType.Docx); @@ -333,6 +372,28 @@ The following code example illustrates how to insert the bookmark by using DocIO {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +//Creates a new Word document. +WordDocument doc = new WordDocument(); +//Adds new section +IWSection section = doc.AddSection(); +//Adds new paragraph +IWParagraph paragraph = section.AddParagraph(); +paragraph.AppendText("Simple Bookmark"); +paragraph = section.AddParagraph(); +paragraph.AppendText("Bookmark with one "); +//Inserts bookmark. +paragraph.AppendBookmarkStart("one_word"); +paragraph.AppendText("word"); +paragraph.AppendBookmarkEnd("one_word"); +paragraph.AppendText(" selected"); +//Saves the document. +MemoryStream stream = new MemoryStream(); +doc.Save(stream, FormatType.Docx); +//Closes the document. +doc.Close(); +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} //Creates a new Word document. WordDocument doc = new WordDocument(); @@ -460,6 +521,28 @@ The following code example illustrates how page numbers are inserted to the foot {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +//Opens the Word document. +FileStream docStream = new FileStream("Template.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); +WordDocument doc = new WordDocument(docStream, FormatType.Docx); +//Iterates through sections +foreach (WSection sec in doc.Sections) +{ + IWParagraph para = sec.AddParagraph(); + //Appends page field to the paragraph + para.AppendField("footer", FieldType.FieldPage); + para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center; + sec.PageSetup.PageNumberStyle = PageNumberStyle.Arabic; + //Adds paragraph to footer + sec.HeadersFooters.Footer.Paragraphs.Add(para); +} +//Saves the document. +MemoryStream stream = new MemoryStream(); +doc.Save(stream, FormatType.Docx); +//Closes the document. +doc.Close(); +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} //Opens the Word document. WordDocument doc = new WordDocument("Template.docx", FormatType.Docx); @@ -583,6 +666,23 @@ DocIO enables you to add a text watermark and a picture watermark to a Word docu {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +//Creates a new Word document. +WordDocument doc = new WordDocument(); +doc.EnsureMinimal(); +//Adds picture watermark to the document. +PictureWatermark picWatermark = new PictureWatermark(); +picWatermark.Scaling = 120f; +picWatermark.Washout = true; +doc.Watermark = picWatermark; +picWatermark.Picture = Image.FromFile(ImagesPath + "Water lilies.jpg"); +//Saves the document. +MemoryStream stream = new MemoryStream(); +doc.Save(stream, FormatType.Docx); +//Closes the document. +doc.Close(); +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} //Creates a new Word document. WordDocument doc = new WordDocument(); @@ -713,6 +813,31 @@ You can set the header and footer by using the [HeadersFooters](https://help.syn {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +//Opens a Word document. +FileStream docStream = new FileStream("Template.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); +WordDocument doc = new WordDocument(docStream, FormatType.Docx); +//Adds header and footer to each section in the document. +foreach (WSection sec in doc.Sections) +{ + //Header. + WParagraph para = new WParagraph(doc); + para.AppendField("page", FieldType.FieldPage); + para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Right; + sec.HeadersFooters.Header.Paragraphs.Add(para); + /Footer. + WParagraph para1 = new WParagraph(doc); + para1.AppendText("Internal"); + para1.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left; + sec.HeadersFooters.Footer.Paragraphs.Add(para1); +} +//Saves the document. +MemoryStream stream = new MemoryStream(); +doc.Save(stream, FormatType.Docx); +//Closes the document. +doc.Close(); +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} //Opens a Word document. WordDocument doc = new WordDocument("Template.docx"); @@ -902,6 +1027,20 @@ The following code example shows how to insert an empty table to a Word document {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +//Creates a new Word document. +WordDocument document = new WordDocument(); +IWSection section = document.AddSection(); +//Adds a table to the document. +IWTable table = section.AddTable(); +table.ResetCells(3, 2); +//Saves the document. +MemoryStream stream = new MemoryStream(); +document.Save(stream, FormatType.Docx); +//Closes the document. +document.Close(); +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} //Creates a new Word document. WordDocument document = new WordDocument(); @@ -1010,6 +1149,20 @@ You can insert comments to a paragraph or text in a Word document by using DocIO {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +//Creates a new Word document. +WordDocument doc = new WordDocument(); +IWSection section = doc.AddSection(); +//Adds a paragraph to the document. +IWParagraph para = section.AddParagraph(); +para.AppendText("New Text"); +//Adds comment to the paragraph. +para.AppendComment("Comment goes here"); +//Saves the document. +MemoryStream stream = new MemoryStream(); +doc.Save(stream, FormatType.Doc); +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} //Creates a new Word document. WordDocument doc = new WordDocument(); @@ -1113,6 +1266,18 @@ DocIO uses [ProtectionType](https://help.syncfusion.com/cr/document-processing/S {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +FileStream docStream = new FileStream("Template.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); +//Loads the existing Word document by using DocIO instance +WordDocument document = new WordDocument(docStream, FormatType.Docx); +//Sets "Allow only Comments" protection to Word document. +document.ProtectionType = Syncfusion.DocIO.ProtectionType.AllowOnlyComments; +//Saves and closes the document. +MemoryStream stream = new MemoryStream(); +document.Save(stream, FormatType.Docx); +document.Close(); +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} //Loads the existing Word document by using DocIO instance WordDocument document = new WordDocument("Template.docx", FormatType.Docx); @@ -1212,6 +1377,23 @@ The following code example illustrates how to insert and update the table of con {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +//Loads the existing Word document by using DocIO instance +FileStream docStream = new FileStream("Template.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); +WordDocument document = new WordDocument(docStream, FormatType.Docx); +IWSection section = document.Sections[0]; +//Appends TOC to the first paragraph of the document. +WParagraph paragraph = new WParagraph(document); +TableOfContent tableOfContents = paragraph.AppendTOC(1, 3); +section.Paragraphs.Insert(0, paragraph); +//Updates table of contents. +document.UpdateTableOfContents(); +//Saves and closes the document. +MemoryStream stream = new MemoryStream(); +document.Save(stream, FormatType.Docx); +document.Close(); +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} //Loads the existing Word document by using DocIO instance WordDocument document = new WordDocument("Template.docx", FormatType.Docx); diff --git a/Document-Processing/Word/Word-Library/NET/faqs/paragraph-and-paragraph-items-faqs.md b/Document-Processing/Word/Word-Library/NET/faqs/paragraph-and-paragraph-items-faqs.md index 255cd60974..86ee5bd521 100644 --- a/Document-Processing/Word/Word-Library/NET/faqs/paragraph-and-paragraph-items-faqs.md +++ b/Document-Processing/Word/Word-Library/NET/faqs/paragraph-and-paragraph-items-faqs.md @@ -13,8 +13,33 @@ The frequently asked questions about working with paragraph and paragraph items The following code illustrates how to modify the built-in style while creating new Word document. +N> Refer to the appropriate tabs in the code snippets section: ***C# [Cross-platform]*** for ASP.NET Core, Blazor, Xamarin, UWP, .NET MAUI, and WinUI; ***C# [Windows-specific]*** for WinForms and WPF; ***VB.NET [Windows-specific]*** for VB.NET applications. + {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +//Creates a new Word document +WordDocument document = new WordDocument(); +//Adds new section to the document +IWSection section = document.AddSection(); +//Creates built-in style and modifies its properties +Style style = Style.CreateBuiltinStyle(BuiltinStyle.Heading1, document) as Style; +style.CharacterFormat.Italic = true; +style.CharacterFormat.TextColor = Color.DarkGreen; +//Adds it to the styles collection +document.Styles.Add(style); +//Adds new paragraph to the section +IWParagraph paragraph = section.AddParagraph(); +IWTextRange text = paragraph.AppendText("A built-in style is modified and is applied to this paragraph."); +//Applies the new style to paragraph +paragraph.ApplyStyle(style.Name); +//Saves the Word document +MemoryStream stream = new MemoryStream(); +document.Save(stream, FormatType.Docx); +//Closes the document +document.Close(); +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} //Creates a new Word document WordDocument document = new WordDocument(); @@ -79,6 +104,32 @@ The following code illustrates how to set ligature types for text. {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +//Creates a new Word document +WordDocument document = new WordDocument(); +//Adds new section to the document +IWSection section = document.AddSection(); +//Adds new paragraph to the section +IWParagraph paragraph = section.AddParagraph(); +//Adds new text +IWTextRange text = paragraph.AppendText("Text to describe discretional ligatures"); +//Sets ligature type +text.CharacterFormat.Ligatures = LigatureType.Discretional; +text.CharacterFormat.FontName = "Arial"; +paragraph = section.AddParagraph(); +text = paragraph.AppendText("Text to describe contextual ligatures"); +text.CharacterFormat.Ligatures = LigatureType.Contextual; +text.CharacterFormat.FontName = "Arial"; +paragraph = section.AddParagraph(); +text = paragraph.AppendText("Text to describe historical ligatures"); +text.CharacterFormat.Ligatures = LigatureType.Historical; +text.CharacterFormat.FontName = "Arial"; +//Saves and closes the document +MemoryStream stream = new MemoryStream(); +document.Save(stream, FormatType.Docx); +document.Close(); +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} //Creates a new Word document WordDocument document = new WordDocument(); @@ -139,6 +190,25 @@ The following code example illustrates how to set contextual alternates. {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +//Creates a new Word document +WordDocument document = new WordDocument(); +//Adds new section to the document +IWSection section = document.AddSection(); +//Adds new paragraph to the section +IWParagraph paragraph = section.AddParagraph(); +//Adds new text +IWTextRange text = paragraph.AppendText("Text to describe contextual alternates"); +text.CharacterFormat.FontName = "Segoe Script"; +//Sets contextual alternates +text.CharacterFormat.UseContextualAlternates = true; +paragraph = section.AddParagraph(); +//Saves and closes the document +MemoryStream stream = new MemoryStream(); +document.Save(stream, FormatType.Docx); +document.Close(); +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} //Creates a new Word document WordDocument document = new WordDocument(); @@ -183,6 +253,29 @@ The following code example illustrates how to set number spacing. {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +//Creates a new Word document +WordDocument document = new WordDocument(); +//Adds new section to the document +IWSection section = document.AddSection(); +//Adds new paragraph to the section +IWParagraph paragraph = section.AddParagraph(); +//Adds new text +IWTextRange text = paragraph.AppendText("Numbers to describe tabular number spacing 0123456789"); +text.CharacterFormat.FontName = "Calibri"; +//Sets number spacing +text.CharacterFormat.NumberSpacing = NumberSpacingType.Tabular; +paragraph = section.AddParagraph(); +text = paragraph.AppendText("Numbers to describe proportional number spacing 0123456789"); +text.CharacterFormat.FontName = "Calibri"; +//Sets number spacing +text.CharacterFormat.NumberSpacing = NumberSpacingType.Proportional; +//Saves and closes the document +MemoryStream stream = new MemoryStream(); +document.Save(stream, FormatType.Docx); +document.Close(); +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} //Creates a new Word document WordDocument document = new WordDocument(); @@ -235,6 +328,29 @@ The following code example illustrates how to set number style. {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +//Creates a new Word document +WordDocument document = new WordDocument(); +//Adds new section to the document +IWSection section = document.AddSection(); +//Adds new paragraph to the section +IWParagraph paragraph = section.AddParagraph(); +//Adds new text +IWTextRange text = paragraph.AppendText("Numbers to describe oldstyle number form 0123456789"); +text.CharacterFormat.FontName = "Calibri"; +//Sets number style +text.CharacterFormat.NumberForm = NumberFormType.OldStyle; +paragraph = section.AddParagraph(); +text = paragraph.AppendText("Numbers to describe lining number form 0123456789"); +text.CharacterFormat.FontName = "Calibri"; +//Sets number style +text.CharacterFormat.NumberForm = NumberFormType.Lining; +//Saves and closes the document +MemoryStream stream = new MemoryStream(); +document.Save(stream, FormatType.Docx); +document.Close(); +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} //Creates a new Word document WordDocument document = new WordDocument(); @@ -287,6 +403,30 @@ The following code example illustrates how to set different styles for the text. {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +//Creates a new Word document +WordDocument document = new WordDocument(); +//Adds new section to the document +IWSection section = document.AddSection(); +//Adds new paragraph to the section +IWParagraph paragraph = section.AddParagraph(); +//Adds new text +IWTextRange text = paragraph.AppendText("Text to describe stylistic sets"); +text.CharacterFormat.FontName = "Gabriola"; +//Sets stylistic set +text.CharacterFormat.StylisticSet = StylisticSetType.StylisticSet06; +paragraph = section.AddParagraph(); +//Adds new text +text = paragraph.AppendText("Text to describe stylistic sets"); +text.CharacterFormat.FontName = "Gabriola"; +//Sets stylistic set +text.CharacterFormat.StylisticSet = StylisticSetType.StylisticSet15; +//Saves and closes the document +MemoryStream stream = new MemoryStream(); +document.Save(stream, FormatType.Docx); +document.Close(); +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} //Creates a new Word document WordDocument document = new WordDocument(); @@ -343,6 +483,37 @@ The following code illustrates how to extract the images in the document. {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +//Loads the template document +FileStream docStream = new FileStream("Template.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); +WordDocument document = new WordDocument(docStream, FormatType.Docx); +WTextBody textbody = document.Sections[0].Body; +Image image; +int i = 1; +//Iterates through the paragraphs +foreach (WParagraph paragraph in textbody.Paragraphs) +{ + //Iterates through the paragraph items + foreach (ParagraphItem item in paragraph.ChildEntities) + { + //Gets the picture and saves it into specified location + switch (item.EntityType) + { + case EntityType.Picture: + WPicture picture = item as WPicture; + image = picture.Image; + image.Save(@"D:/Data/Image" + i + ".jpeg", ImageFormat.Jpeg); + i++; + break; + default: + break; + } + } +} +//Closes the document +document.Close(); +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} //Loads the template document WordDocument document = new WordDocument("Template.docx"); @@ -406,6 +577,21 @@ The images in the document can be extracted into a specific location when export {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +//Loads the template document +FileStream docStream = new FileStream("Template.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); +WordDocument document = new WordDocument(docStream, FormatType.Docx); +//Sets the location to extract images +document.SaveOptions.HtmlExportImagesFolder = @"D:/Data/"; +//Saves the document as html file +HTMLExport export = new HTMLExport(); +export.SaveAsXhtml(document, "Template.html"); +MemoryStream stream = new MemoryStream(); +export.SaveAsXhtml(document, stream); +//Closes the document +document.Close(); +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} //Loads the template document WordDocument document = new WordDocument("Template.docx"); @@ -444,7 +630,16 @@ To detect the type of a shape in a Word document, you can use the [AutoShapeType {% tabs %} -{% highlight c# tabtitle="C#" %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +// Get the last paragraph from the document +WParagraph paragraph = document.LastParagraph; +// Access the shape from the paragraph's child entities +Shape shape = paragraph.ChildEntities[i] as Shape; +// Get the type of the shape +AutoShapeType shapeType = shape.AutoShapeType; +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} // Get the last paragraph from the document WParagraph paragraph = document.LastParagraph; // Access the shape from the paragraph's child entities @@ -453,7 +648,7 @@ Shape shape = paragraph.ChildEntities[i] as Shape; AutoShapeType shapeType = shape.AutoShapeType; {% endhighlight %} -{% highlight vb.net tabtitle="VB.NET" %} +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} ' Get the last paragraph from the document Dim paragraph As WParagraph = document.LastParagraph ' Access the shape from the paragraph's child entities @@ -500,7 +695,18 @@ The following code illustrates how to enable the "Don't add space between paragr {% tabs %} -{% highlight c# tabtitle="C#" %} +{% highlight c# tabtitle="C# [Cross-platform]" %} + // Find the "Normal" paragraph style in the document's styles collection + WParagraphStyle normalStyle = document.Styles.FindByName("Normal") as WParagraphStyle; +// Check if the "Normal" style is found, and if so, enable contextual spacing +if (normalStyle != null) +{ + // Enable contextual spacing to avoid adding extra space between paragraphs with the same style + normalStyle.ParagraphFormat.ContextualSpacing = true; +} +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} // Find the "Normal" paragraph style in the document's styles collection WParagraphStyle normalStyle = document.Styles.FindByName("Normal") as WParagraphStyle; // Check if the "Normal" style is found, and if so, enable contextual spacing @@ -511,7 +717,7 @@ if (normalStyle != null) } {% endhighlight %} -{% highlight vb.net tabtitle="VB.NET" %} +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} ' Find the "Normal" paragraph style in the document's styles collection Dim normalStyle As WParagraphStyle = TryCast(document.Styles.FindByName("Normal"), WParagraphStyle) ' Check if the "Normal" style is found, and if so, enable contextual spacing @@ -562,10 +768,8 @@ using (FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Template. } } // Save the modified document. - using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.Write)) - { - document.Save(outputStream, FormatType.Docx); - } + MemoryStream stream = new MemoryStream(); + document.Save(stream, FormatType.Docx); } } {% endhighlight %} @@ -682,14 +886,21 @@ The following code illustrates how to hide the chart legend. {% tabs %} -{% highlight c# tabtitle="C#" %} +{% highlight c# tabtitle="C# [Cross-platform]" %} + // To hide +chart.Legend.LegendEntries[3].IsDeleted = true; +// To restore +chart.Legend.LegendEntries[3].IsDeleted = false; +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} // To hide chart.Legend.LegendEntries[3].IsDeleted = true; // To restore chart.Legend.LegendEntries[3].IsDeleted = false; {% endhighlight %} -{% highlight vb.net tabtitle="VB.NET" %} +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} ' To hide chart.Legend.LegendEntries(3).IsDeleted = True ' To restore @@ -708,7 +919,47 @@ The following code illustrates how to apply formatting to a field while creating {% tabs %} -{% highlight c# tabtitle="C#" %} +{% highlight c# tabtitle="C# [Cross-platform]" %} + // Create a new Word document + WordDocument document = new WordDocument(); + // Add a new section to the document + IWSection section = document.AddSection(); + // Add a paragraph to the header with center alignment + IWParagraph headerParagraph = section.HeadersFooters.Header.AddParagraph(); + headerParagraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center; + // Add text and format it + IWTextRange text = headerParagraph.AppendText("Page Number: "); + text.CharacterFormat.FontSize = 8; + text.CharacterFormat.FontName = "Calibri"; + // Append a page number field to the header + IWField pageField = headerParagraph.AppendField("Page No:", FieldType.FieldPage); + // Initialize entity to iterate through field components + IEntity entity = pageField; + while (entity.NextSibling != null) + { + // Check if the current entity is a text range + if (entity is WTextRange) + { + // Cast the entity to a WTextRange type + WTextRange textRange = entity as WTextRange; + // Set character format for text ranges + textRange.CharacterFormat.FontSize = 8; + textRange.CharacterFormat.FontName = "Calibri"; + textRange.CharacterFormat.Bold = true; + } + // Break the loop at the end of the field + else if ((entity is WFieldMark) && (entity as WFieldMark).Type == FieldMarkType.FieldEnd) + break; + // Move to the next sibling item + entity = entity.NextSibling; + } + // Save and Close the document + MemoryStream stream = new MemoryStream(); + document.Save(stream, FormatType.Docx); + document.Close(); +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} // Create a new Word document WordDocument document = new WordDocument(); // Add a new section to the document @@ -747,7 +998,7 @@ The following code illustrates how to apply formatting to a field while creating document.Close(); {% endhighlight %} -{% highlight vb.net tabtitle="VB.NET" %} +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} ' Create a new Word document Dim document As New WordDocument() ' Add a new section to the document @@ -799,7 +1050,29 @@ To ensure that tabs are preserved, it is necessary to clear the tab settings in {% tabs %} -{% highlight c# tabtitle="C#" %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +// Loads the template document +FileStream docStream = new FileStream("Template.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); +WordDocument document = new WordDocument(docStream, FormatType.Docx); +// Loop through TOC styles from TOC 1 to TOC 9 +for (int i = 1; i <= 9; i++) +{ + // Find the style by name (e.g., "TOC 1", "TOC 2", ..., "TOC 9") + Style style = (Style)document.Styles.FindByName("TOC " + i); + // If the style exists and is a paragraph style, clear its tab stops + if (style != null) + (style as WParagraphStyle).ParagraphFormat.Tabs.Clear(); +} +// Updates the table of contents +document.UpdateTableOfContents(); +// Save the Word document +MemoryStream stream = new MemoryStream(); +document.Save(stream, FormatType.Docx); +// Close the Word document +document.Close(); +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} // Loads the template document WordDocument document = new WordDocument("Template.docx"); // Loop through TOC styles from TOC 1 to TOC 9 @@ -819,7 +1092,7 @@ document.Save("Output.docx"); document.Close(); {% endhighlight %} -{% highlight vb.net tabtitle="VB.NET" %} +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} ' Loads the template document Dim document As New WordDocument("Template.docx") ' Loop through TOC styles from TOC 1 to TOC 9 @@ -894,7 +1167,7 @@ For more details, refer [Working with styles](https://help.syncfusion.com/docume {% tabs %} -{% highlight c# tabtitle="C#" %} +{% highlight c# tabtitle="C# [Cross-platform]" %} PointF[] triangle = { new PointF(0f, 300f), @@ -905,6 +1178,27 @@ PointF[] triangle = { {% endhighlight %} +{% highlight c# tabtitle="C# [Windows-specific]" %} + +PointF[] triangle = { + new PointF(0f, 300f), + new PointF(200f, 0f), + new PointF(400f, 300f), + new PointF(0f, 300f) +} + +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Dim triangle As PointF() = { + New PointF(0.0F, 300.0F), + New PointF(200.0F, 0.0F), + New PointF(400.0F, 300.0F), + New PointF(0.0F, 300.0F) +} + +{% endhighlight %} + {% endtabs %} ## How to Set Stroke Thickness? diff --git a/Document-Processing/Word/Word-Library/NET/faqs/sections-faqs.md b/Document-Processing/Word/Word-Library/NET/faqs/sections-faqs.md index f8919ff8e4..23a9170032 100644 --- a/Document-Processing/Word/Word-Library/NET/faqs/sections-faqs.md +++ b/Document-Processing/Word/Word-Library/NET/faqs/sections-faqs.md @@ -13,8 +13,37 @@ The frequently asked questions about working with sections in Word documents usi The following code illustrates how to remove the header contents from the document. +N> Refer to the appropriate tabs in the code snippets section: ***C# [Cross-platform]*** for ASP.NET Core, Blazor, Xamarin, UWP, .NET MAUI, and WinUI; ***C# [Windows-specific]*** for WinForms and WPF; ***VB.NET [Windows-specific]*** for VB.NET applications. + {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +//Loads the template document +FileStream docStream = new FileStream("Template.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); +WordDocument document = new WordDocument(docStream, FormatType.Docx); +//Iterates through the sections +foreach (WSection section in document.Sections) +{ + HeaderFooter header; + //Gets even footer of current section + header = section.HeadersFooters[HeaderFooterType.EvenHeader]; + //Removes even footer + header.ChildEntities.Clear(); + //Gets odd footer of current section + header = section.HeadersFooters[HeaderFooterType.OddHeader]; + //Removes odd footer + header.ChildEntities.Clear(); + //Gets first page footer + header = section.HeadersFooters[HeaderFooterType.FirstPageHeader]; + //Removes first page footer + header.ChildEntities.Clear(); +} +//Saves and closes the document +MemoryStream stream = new MemoryStream(); +document.Save(stream, FormatType.Docx); +document.Close(); +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} //Loads the template document WordDocument document = new WordDocument("Template.docx", FormatType.Docx); @@ -72,6 +101,33 @@ The following code illustrates how to remove the footer contents from the docume {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +//Loads the template document +FileStream docStream = new FileStream("Template.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); +WordDocument document = new WordDocument(docStream, FormatType.Docx); +//Iterates through the sections +foreach (WSection section in document.Sections) +{ + HeaderFooter footer; + //Gets even footer of current section + footer = section.HeadersFooters[HeaderFooterType.EvenFooter]; + //Removes even footer + footer.ChildEntities.Clear(); + //Gets odd footer of current section + footer = section.HeadersFooters[HeaderFooterType.OddFooter]; + //Removes odd footer + footer.ChildEntities.Clear(); + //Gets first page footer + footer = section.HeadersFooters[HeaderFooterType.FirstPageFooter]; + //Removes first page footer + footer.ChildEntities.Clear(); +} +//Saves and closes the document +MemoryStream stream = new MemoryStream(); +document.Save(stream, FormatType.Docx); +document.Close(); +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} //Loads the template document WordDocument document = new WordDocument("Template.docx"); diff --git a/Document-Processing/Word/Word-Library/NET/faqs/tables-faqs.md b/Document-Processing/Word/Word-Library/NET/faqs/tables-faqs.md index a17db4eaf6..0dd631afc8 100644 --- a/Document-Processing/Word/Word-Library/NET/faqs/tables-faqs.md +++ b/Document-Processing/Word/Word-Library/NET/faqs/tables-faqs.md @@ -13,8 +13,50 @@ The frequently asked questions about working with tables in Word documents using You can create new table in a Word document and copy the contents from data table. The following code illustrates how to insert a data table as table in a Word document. +N> Refer to the appropriate tabs in the code snippets section: ***C# [Cross-platform]*** for ASP.NET Core, Blazor, Xamarin, UWP, .NET MAUI, and WinUI; ***C# [Windows-specific]*** for WinForms and WPF; ***VB.NET [Windows-specific]*** for VB.NET applications. + {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +//Creates new Word document +WordDocument document = new WordDocument(); +//Creates new data set and data table +DataSet dataset = new DataSet(); +GetDataTable(dataset); +DataTable datatable = new DataTable(); +datatable = dataset.Tables[0]; +//Adds new section +IWSection section = document.AddSection(); +//Adds new table +IWTable table = section.AddTable(); +//Adds new row to the table +WTableRow row = table.AddRow(); +foreach (DataColumn datacolumn in datatable.Columns) +{ + //Sets the column names for the table from the data table column names and cell width + WTableCell cell = row.AddCell(); + cell.AddParagraph().AppendText(datacolumn.ColumnName); + cell.Width = 150; +} +//Iterates through data table rows +foreach (DataRow datarow in datatable.Rows) +{ + //Adds new row to the table + row = table.AddRow(true, false); + foreach (object datacolumn in datarow.ItemArray) + { + //Adds new cell + WTableCell cell = row.AddCell(); + //Adds contents from the data table to the table cell + cell.AddParagraph().AppendText(datacolumn.ToString()); + } +} +//Saves and closes the document +MemoryStream stream = new MemoryStream(); +document.Save(stream, FormatType.Docx); +document.Close(); +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} //Creates new Word document WordDocument document = new WordDocument(); @@ -96,6 +138,31 @@ The following code illustrates the method to get data table. {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +private void GetDataTable(DataSet dataset) +{ + // List of syncfusion products. + string[] products = { "DocIO", "PDF", "XlsIO" }; + // Adds new Tables to the data set. + DataRow row; + dataset.Tables.Add(); + // Adds fields to the Products table. + dataset.Tables[0].TableName = "Products"; + dataset.Tables[0].Columns.Add("ProductName"); + dataset.Tables[0].Columns.Add("Binary"); + dataset.Tables[0].Columns.Add("Source"); + // Inserts values to the tables. + foreach (string product in products) + { + row = dataset.Tables["Products"].NewRow(); + row["ProductName"] = string.Concat("Essential ", product); + row["Binary"] = "$895.00"; + row["Source"] = "$1,295.00"; + dataset.Tables["Products"].Rows.Add(row); + } +} +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} private void GetDataTable(DataSet dataset) { @@ -154,6 +221,22 @@ An HTML string can be inserted to the Word document at text body or paragraph. T {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +//Loads the template document +FileStream docStream = new FileStream("Template.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); +WordDocument document = new WordDocument(docStream, FormatType.Docx); +//Gets the text body +WTextBody textbody = document.Sections[0].Body; +//Html string that represents table with two rows and two columns +string htmlString = "

First Row First Cell

First Row Second Cell

Second Row First Cell

Second Row Second Cell

"; +//Inserts the string to the text body +textbody.InsertXHTML(htmlString); +//Saves and closes the document +MemoryStream stream = new MemoryStream(); +document.Save(stream, FormatType.Docx); +document.Close(); +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} //Loads the template document WordDocument document = new WordDocument("Template.docx"); @@ -192,6 +275,35 @@ Each cell in the table can have its own width. The following code illustrates ho {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +//Creates new word document +FileStream docStream = new FileStream("Template.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); +WordDocument document = new WordDocument(docStream, FormatType.Docx); +//Gets the text body of first section +WTextBody textbody = document.Sections[0].Body; +//Gets the table +IWTable table = textbody.Tables[0]; +//Iterates through table rows +foreach (WTableRow row in table.Rows) +{ + //Sets width for cells + for (int i = 0; i < row.Cells.Count; i++) + { + WTableCell cell = row.Cells[i]; + if (i % 2 == 0) + //Sets width as 100 for cells in even column + cell.Width = 100; + else + //Sets width as 150 for cell in odd column + cell.Width = 150; + } +} +//Saves and closes the document +MemoryStream stream = new MemoryStream(); +document.Save(stream, FormatType.Docx); +document.Close(); +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} //Creates new word document WordDocument document = new WordDocument("Template.docx"); @@ -255,6 +367,23 @@ You can position a table in a Word document by setting position properties. The {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +//Loads the template document +FileStream docStream = new FileStream("Template.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); +WordDocument document = new WordDocument(docStream, FormatType.Docx); +//Gets the text body of first section +WTextBody textbody = document.Sections[0].Body; +//Gets the table +IWTable table = textbody.Tables[0]; +//Sets the horizontal and vertical position for table +table.TableFormat.Positioning.HorizPosition = 40; +table.TableFormat.Positioning.VertPosition = 100; +//Saves and closes the document +MemoryStream stream = new MemoryStream(); +document.Save(stream, FormatType.Docx); +document.Close(); +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} //Loads the template document WordDocument document = new WordDocument("Template.docx"); @@ -295,6 +424,29 @@ The contents of the table cell can be in vertical or horizontal direction. Each {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +//Loads the template document +FileStream docStream = new FileStream("Template.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); +WordDocument document = new WordDocument(docStream, FormatType.Docx); +//Gets the text body of first section +WTextBody textbody = document.Sections[0].Body; +//Gets the table +IWTable table = textbody.Tables[0]; +//Iterates through table rows +foreach (WTableRow row in table.Rows) +{ + foreach (WTableCell cell in row.Cells) + { + //Sets the text direction for the contents + cell.CellFormat.TextDirection = Syncfusion.DocIO.DLS.TextDirection.Vertical; + } +} +//Saves and closes the document +MemoryStream stream = new MemoryStream(); +document.Save(stream, FormatType.Docx); +document.Close(); +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} //Loads the template document WordDocument document = new WordDocument("Template.docx"); @@ -349,7 +501,7 @@ The following code demonstrates how to get the row height and height type from a {% tabs %} -{% highlight c# tabtitle="C#" %} +{% highlight c# tabtitle="C# [Cross-platform]" %} // Access the instance of the first row in the table WTableRow row = table.Rows[0]; // Get the row height @@ -358,7 +510,16 @@ float rowHeight = row.Height; TableRowHeightType rowHeightType = row.HeightType; {% endhighlight %} -{% highlight vb.net tabtitle="VB.NET" %} +{% highlight c# tabtitle="C# [Windows-specific]" %} +// Access the instance of the first row in the table +WTableRow row = table.Rows[0]; +// Get the row height +float rowHeight = row.Height; +// Get the row height type +TableRowHeightType rowHeightType = row.HeightType; +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} ' Access the instance of the first row in the table Dim row As WTableRow = table.Rows(0) ' Get the row height @@ -495,10 +656,20 @@ Yes, you can access and edit the content of tables in a Word document using seve You can access a table by its index in the document. Use the get(index) method to retrieve the table from the collection based on its position. Here’s an example: {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +// Access the second table in the last section +IWTable table = document.LastSection.Tables[1]; +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} // Access the second table in the last section IWTable table = document.LastSection.Tables[1]; {% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +' Access the second table in the last section +Dim table As IWTable = document.LastSection.Tables(1) +{% endhighlight %} {% endtabs %} **Approach 2: Retrieve All Tables in the Document** @@ -506,8 +677,29 @@ IWTable table = document.LastSection.Tables[1]; To work with all tables in the document, you can use the [FindAllItemsByProperty](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.WordDocument.html#Syncfusion_DocIO_DLS_WordDocument_FindAllItemsByProperty_Syncfusion_DocIO_DLS_EntityType_System_String_System_String_) API to retrieve all tables, then iterate through them: {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +FileStream docStream = new FileStream("Input.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); +WordDocument document = new WordDocument(docStream, FormatType.Docx); +// Find all tables in the document +List tables = document.FindAllItemsByProperty(EntityType.Table, null, null); +foreach (Entity entity in tables) +{ + WTable table = (WTable)entity; + foreach (WTableRow row in table.Rows) + { + foreach (WTableCell cell in row.Cells) + { + foreach (WParagraph paragraph in cell.Paragraphs) + { + // Perform your manipulation here + } + } + } +} +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} -WordDocument document = new WordDocument("Data\\Input.docx"); +WordDocument document = new WordDocument("Input.docx"); // Find all tables in the document List tables = document.FindAllItemsByProperty(EntityType.Table, null, null); foreach (Entity entity in tables) @@ -525,6 +717,23 @@ foreach (Entity entity in tables) } } {% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +' Load the Word document +Dim document As New WordDocument("Input.docx") +' Find all tables in the document +Dim tables As List(Of Entity) = document.FindAllItemsByProperty(EntityType.Table, Nothing, Nothing) +For Each entity As Entity In tables + Dim table As WTable = CType(entity, WTable) + For Each row As WTableRow In table.Rows + For Each cell As WTableCell In row.Cells + For Each paragraph As WParagraph In cell.Paragraphs + ' Perform your manipulation here + Next + Next + Next +Next +{% endhighlight %} {% endtabs %} **Approach 3: Access a Table by Alternate Text** @@ -532,9 +741,19 @@ foreach (Entity entity in tables) If your table has a unique Alternate Text (Title), you can access it directly using FindItemByProperty API: {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +// Find the first table in the document with the title "Table1" +WTable table = document.FindItemByProperty(EntityType.Table, "Title", "Table1") as WTable; +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} // Find the first table in the document with the title "Table1" WTable table = document.FindItemByProperty(EntityType.Table, "Title", "Table1") as WTable; {% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +' Find the first table in the document with the title "Table1" +Dim table As WTable = TryCast(document.FindItemByProperty(EntityType.Table, "Title", "Table1"), WTable) +{% endhighlight %} {% endtabs %} \ No newline at end of file diff --git a/Document-Processing/Word/Word-Library/NET/faqs/word-document-faqs.md b/Document-Processing/Word/Word-Library/NET/faqs/word-document-faqs.md index 156082e3a6..cdcc567671 100644 --- a/Document-Processing/Word/Word-Library/NET/faqs/word-document-faqs.md +++ b/Document-Processing/Word/Word-Library/NET/faqs/word-document-faqs.md @@ -13,8 +13,32 @@ The frequently asked questions about Word document manipulation using DocIO are A document can be opened as stream by using HttpWebResponse. This stream does not support seek operation and so the contents should be read manually to get the position and length of the stream. The following code illustrates how to load the document from stream. +N> Refer to the appropriate tabs in the code snippets section: ***C# [Cross-platform]*** for ASP.NET Core, Blazor, Xamarin, UWP, .NET MAUI, and WinUI; ***C# [Windows-specific]*** for WinForms and WPF; ***VB.NET [Windows-specific]*** for VB.NET applications. + {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +//Gets the document as stream +HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.swiftview.com/tech/letterlegal5.doc"); +HttpWebResponse response = (HttpWebResponse)request.GetResponse(); +Stream stream = response.GetResponseStream(); +//Converts it to byte array +byte[] buffer = ReadFully(stream, 32768); +//Stores bytes into the memory stream. +MemoryStream ms = new MemoryStream(); +ms.Write(buffer, 0, buffer.Length); +ms.Seek(0, SeekOrigin.Begin); +stream.Close(); +//Creates a new document. +WordDocument document = new WordDocument(); +//Opens the template document from the MemoryStream. +document.Open(ms, FormatType.Doc); +//Saves and closes the document +MemoryStream mstream = new MemoryStream(); +document.Save(mstream, FormatType.Docx); +document.Close(); +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} //Gets the document as stream HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.swiftview.com/tech/letterlegal5.doc"); @@ -63,6 +87,40 @@ The following code illustrates the method used to read the stream and convert th {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +public static byte[] ReadFully(Stream stream, int initialLength) +{ + //When an unhelpful initial length has been passed, just use 32K. + if (initialLength < 1) + initialLength = 32768; + byte[] buffer = new byte[initialLength]; + int read = 0; + int chunk; + while ((chunk = stream.Read(buffer, read, buffer.Length - read)) > 0) + { + read += chunk; + //After reaching the end of the buffer, check and see whether you can find any information. + if (read == buffer.Length) + { + int nextByte = stream.ReadByte(); + //End of stream? Then, you are done. + if (nextByte == -1) + return buffer; + //Resize the buffer, put in the byte you have just read, and continue. + byte[] newBuffer = new byte[buffer.Length * 2]; + Array.Copy(buffer, newBuffer, buffer.Length); + newBuffer[read] = (byte)nextByte; + buffer = newBuffer; + read++; + } + } + //Buffer is now too big. Shrink it. + byte[] ret = new byte[read]; + Array.Copy(buffer, ret, read); + return ret; +} +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} public static byte[] ReadFully(Stream stream, int initialLength) { @@ -137,6 +195,20 @@ The following code illustrates how to set the template for the document. {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +//Loads a source document +FileStream docStream = new FileStream("Template.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); +WordDocument document = new WordDocument(docStream, FormatType.Docx); +//Attaches the template document to the source document +document.AttachedTemplate.Path = @"D:/Data/Template.docx"; +//Updates the styles of the document from the attached template each time the document is opened +document.UpdateStylesOnOpen = true; +//Saves and closes the document +MemoryStream stream = new MemoryStream(); +document.Save(stream, FormatType.Docx); +document.Close(); +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} //Loads a source document WordDocument document = new WordDocument("Template.docx"); @@ -171,6 +243,20 @@ The [CompatibilityMode](https://help.syncfusion.com/cr/document-processing/Syncf {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +//Load an existing Word document. +FileStream docStream = new FileStream("Input.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); +using (WordDocument document = new WordDocument(docStream, FormatType.Docx)) +{ + //Get the compatibility mode. + CompatibilityMode compatibilityMode = document.Settings.CompatibilityMode; + Console.WriteLine(compatibilityMode); + //Save a Word document. + MemoryStream stream = new MemoryStream(); + document.Save(stream, FormatType.Docx); +} +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} //Load an existing Word document. using (WordDocument document = new WordDocument("Input.docx", FormatType.Docx)) @@ -214,7 +300,24 @@ Syncfusion® .NET Word Library (DocIO) uses points as the default uni {% tabs %} -{% highlight c# tabtitle="C#" %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +// Assuming you have a margin value in centimeters +float marginInCentimeter = 2f; +// Convert cm to points +float marginInPoints = marginInCentimeter * 28.3465f; + +// Assuming you have a margin value in millimeters +float marginInMillimeter = 20f; +// Convert cm to points +float marginInPoints = marginInMillimeter * 2.83465f; + +// Assuming you have a margin value in inches +float marginInInches = 1f; +// Convert cm to points +float marginInPoints = marginInInches * 72f; +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} // Assuming you have a margin value in centimeters float marginInCentimeter = 2f; // Convert cm to points @@ -231,7 +334,7 @@ float marginInInches = 1f; float marginInPoints = marginInInches * 72f; {% endhighlight %} -{% highlight vb.net tabtitle="VB.NET" %} +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} ' Assuming you have a margin value in centimeters Dim marginInCentimeter As Single = 2.0F ' Convert cm to points @@ -266,14 +369,21 @@ The following code demonstrates how to use a *using* block to handle file stream {% tabs %} -{% highlight c# tabtitle="C#" %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +using (FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read)) +{ + // Use the file stream here (e.g., read data, write data) +} +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} using (FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { // Use the file stream here (e.g., read data, write data) } {% endhighlight %} -{% highlight vb.net tabtitle="VB.NET" %} +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} Using stream As New FileStream(filePath, FileMode.Open, FileAccess.Read) ' Use the file stream here (e.g., read data, write data) End Using @@ -303,11 +413,15 @@ The following code illustrates how to get the current culture. {% tabs %} -{% highlight c# tabtitle="C#" %} +{% highlight c# tabtitle="C# [Cross-platform]" %} CultureInfo currentCulture = CultureInfo.CurrentCulture; {% endhighlight %} -{% highlight vb.net tabtitle="VB.NET" %} +{% highlight c# tabtitle="C# [Windows-specific]" %} +CultureInfo currentCulture = CultureInfo.CurrentCulture; +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} Dim currentCulture As CultureInfo = CultureInfo.CurrentCulture {% endhighlight %} @@ -317,13 +431,19 @@ The following code illustrates how to set the culture. {% tabs %} -{% highlight c# tabtitle="C#" %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +CultureInfo culture = new CultureInfo("fr-CA"); +CultureInfo.DefaultThreadCurrentCulture = culture; +CultureInfo.DefaultThreadCurrentUICulture = culture; +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} CultureInfo culture = new CultureInfo("fr-CA"); CultureInfo.DefaultThreadCurrentCulture = culture; CultureInfo.DefaultThreadCurrentUICulture = culture; {% endhighlight %} -{% highlight vb.net tabtitle="VB.NET" %} +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} Dim culture As New CultureInfo("fr-CA") CultureInfo.DefaultThreadCurrentCulture = culture CultureInfo.DefaultThreadCurrentUICulture = culture @@ -531,7 +651,7 @@ As a workaround, keep the same section and page setup properties in both the sou The following code illustrates how to set the page properties to source document as same as the destination document. {% tabs %} -{% highlight c# tabtitle="C#" %} +{% highlight c# tabtitle="C# [Cross-platform]" %} // Match page setup before importing IWSection sourceSection = sourceDoc.Sections[0]; IWSection destSection = destinationDoc.Sections[0]; @@ -543,6 +663,32 @@ sourceSection.PageSetup.PageSize = destSection.PageSetup.PageSize; // Now import the section destinationDoc.Sections.Add(sourceDoc.Sections[0].Clone()); {% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} +// Match page setup before importing +IWSection sourceSection = sourceDoc.Sections[0]; +IWSection destSection = destinationDoc.Sections[0]; +//Sets the destination document page setup properties to the source document sections. +sourceSection.PageSetup.DifferentFirstPage = destSecPageSetup.DifferentFirstPage; +sourceSection.PageSetup.Margins.All = destSection.PageSetup.Margins.All; +sourceSection.PageSetup.Orientation = destSection.PageSetup.Orientation; +sourceSection.PageSetup.PageSize = destSection.PageSetup.PageSize; +// Now import the section +destinationDoc.Sections.Add(sourceDoc.Sections[0].Clone()); +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +' Match page setup before importing +Dim sourceSection As IWSection = sourceDoc.Sections(0) +Dim destSection As IWSection = destinationDoc.Sections(0) +' Sets the destination document page setup properties to the source document sections +sourceSection.PageSetup.DifferentFirstPage = destSection.PageSetup.DifferentFirstPage +sourceSection.PageSetup.Margins.All = destSection.PageSetup.Margins.All +sourceSection.PageSetup.Orientation = destSection.PageSetup.Orientation +sourceSection.PageSetup.PageSize = destSection.PageSetup.PageSize +' Now import the section +destinationDoc.Sections.Add(sourceDoc.Sections(0).Clone()) +{% endhighlight %} {% endtabs %} ## Does DocIO process corrupted Word documents? @@ -614,30 +760,56 @@ The following code sample how to preserve the formatting of the source document {% tabs %} -{% highlight c# tabtitle="C#" %} - // Load the destination document - WordDocument destinationDocument = new WordDocument("DestinationDocument.docx"); - // Load the source document - WordDocument sourceDocument = new WordDocument("SourceDocument.docx"); - // Create a part of the source document for import - WordDocumentPart sourceDoc = new WordDocumentPart(sourceDocument); - // Set import options to keep source formatting - destinationDocument.ImportOptions = ImportOptions.KeepSourceFormatting; - // Create a bookmarks navigator for the destination document - BookmarksNavigator bookmarksNavigator = new BookmarksNavigator(destinationDocument); - // Move to the specified bookmark in the destination document - bookmarksNavigator.MoveToBookmark("bkmk1"); - // Replace the content at the bookmark with the source document content - bookmarksNavigator.ReplaceContent(sourceDoc); - // Save the modified destination document to a new file - destinationDocument.Save("Output.docx", FormatType.Docx); - // Close the documents - sourceDoc.Close(); - sourceDocument.Close(); - destinationDocument.Close(); -{% endhighlight %} - -{% highlight vb.net tabtitle="VB.NET" %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +// Load the destination document +FileStream destDocStream = new FileStream("DestinationDocument.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); +FileStream srcDocStream = new FileStream("SourceDocument.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); +WordDocument destinationDocument = new WordDocument(destDocStream, FormatType.Docx); +// Load the source document +WordDocument sourceDocument = new WordDocument(srcDocStream, FormatType.Docx); +// Create a part of the source document for import +WordDocumentPart sourceDoc = new WordDocumentPart(sourceDocument); +// Set import options to keep source formatting +destinationDocument.ImportOptions = ImportOptions.KeepSourceFormatting; +// Create a bookmarks navigator for the destination document +BookmarksNavigator bookmarksNavigator = new BookmarksNavigator(destinationDocument); +// Move to the specified bookmark in the destination document +bookmarksNavigator.MoveToBookmark("bkmk1"); +// Replace the content at the bookmark with the source document content +bookmarksNavigator.ReplaceContent(sourceDoc); +// Save the modified destination document to a new file +MemoryStream stream = new MemoryStream(); +destinationDocument.Save(stream, FormatType.Docx); +// Close the documents +sourceDoc.Close(); +sourceDocument.Close(); +destinationDocument.Close(); +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} +// Load the destination document +WordDocument destinationDocument = new WordDocument("DestinationDocument.docx"); +// Load the source document +WordDocument sourceDocument = new WordDocument("SourceDocument.docx"); +// Create a part of the source document for import +WordDocumentPart sourceDoc = new WordDocumentPart(sourceDocument); +// Set import options to keep source formatting +destinationDocument.ImportOptions = ImportOptions.KeepSourceFormatting; +// Create a bookmarks navigator for the destination document +BookmarksNavigator bookmarksNavigator = new BookmarksNavigator(destinationDocument); +// Move to the specified bookmark in the destination document +bookmarksNavigator.MoveToBookmark("bkmk1"); +// Replace the content at the bookmark with the source document content +bookmarksNavigator.ReplaceContent(sourceDoc); +// Save the modified destination document to a new file +destinationDocument.Save("Output.docx", FormatType.Docx); +// Close the documents +sourceDoc.Close(); +sourceDocument.Close(); +destinationDocument.Close(); +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} ' Load the destination document Dim destinationDocument As New WordDocument("DestinationDocument.docx") ' Load the source document @@ -688,7 +860,8 @@ No, DocIO does not support font substitution during DOCX‑to‑DOCX processing. The following code illustrates how to retrieve the all merge fields in a Word document. {% tabs %} -{% highlight c# tabtitle="C#" %} + +{% highlight c# tabtitle="C# [Cross-platform]" %} //Open the Word document file stream. using (FileStream inputStream = new FileStream("Input.docx", FileMode.Open, FileAccess.Read)) { @@ -700,6 +873,23 @@ using (FileStream inputStream = new FileStream("Input.docx", FileMode.Open, File } } {% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} +//Loads an existing Word document. +using (WordDocument wordDocument = new WordDocument("Input.docx", FormatType.Automatic)) +{ + // Get list of merge fields + List entity = wordDocument.FindAllItemsByProperty(EntityType.MergeField, null, null); +} +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +' Loads an existing Word document. +Using wordDocument As New WordDocument("Input.docx", FormatType.Automatic) + ' Get list of merge fields + Dim entity As List(Of Entity) = wordDocument.FindAllItemsByProperty(EntityType.MergeField, Nothing, Nothing) +End Using +{% endhighlight %} {% endtabs %} ## Why is memory not cleared after completing the conversion process in ASP NET Core Web Application using DocIO? diff --git a/Document-Processing/Word/Word-Library/NET/faqs/word-to-pdf-and-image-conversions-faqs.md b/Document-Processing/Word/Word-Library/NET/faqs/word-to-pdf-and-image-conversions-faqs.md index 2ae7eb28ab..8b9ea599a7 100644 --- a/Document-Processing/Word/Word-Library/NET/faqs/word-to-pdf-and-image-conversions-faqs.md +++ b/Document-Processing/Word/Word-Library/NET/faqs/word-to-pdf-and-image-conversions-faqs.md @@ -31,9 +31,9 @@ You can download a complete working sample from [GitHub](https://github.com/Sync ## Why are some fonts missing when converting a Word document to PDF in the Syncfusion® demo application? -The Syncfusion® [online demo](https://ej2.syncfusion.com/aspnetcore/word/wordtopdf#/bootstrap5) has a limited set of default fonts. If certain fonts are missing during the Word-to-PDF conversion, it may cause preservation problems. +The Syncfusion® [online demo](https://document.syncfusion.com/demos/word/wordtopdf#/tailwind) has a limited set of default fonts. If certain fonts are missing during the Word-to-PDF conversion, it may cause preservation problems. -To ensure the fonts appear exactly as they do in the Word document during PDF conversion in our [online demo](https://ej2.syncfusion.com/aspnetcore/word/wordtopdf#/bootstrap5), we recommend embedding the missing fonts directly into the Word document before performing the conversion. For detailed guidance on embedding fonts in a Word document using Microsoft Word, refer [here](https://support.syncfusion.com/kb/article/13969/how-to-resolve-font-problems-during-word-to-pdf-or-image-conversion#suggestion-3:-embed-fonts-in-docx). +To ensure the fonts appear exactly as they do in the Word document during PDF conversion in our [online demo](https://document.syncfusion.com/demos/word/wordtopdf#/tailwind), we recommend embedding the missing fonts directly into the Word document before performing the conversion. For detailed guidance on embedding fonts in a Word document using Microsoft Word, refer [here](https://support.syncfusion.com/kb/article/13969/how-to-resolve-font-problems-during-word-to-pdf-or-image-conversion#suggestion-3:-embed-fonts-in-docx). ## How to edit a Word document in Microsoft Word and convert it to PDF/image simultaneously using the DocIO library? @@ -78,6 +78,11 @@ The following code example illustrates how to initialize [ChartToImageConverter] //Initializes the ChartToImageConverter for converting charts during Word to pdf conversion wordDocument.ChartToImageConverter = new ChartToImageConverter(); {% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +'Initializes the ChartToImageConverter for converting charts during Word to pdf conversion +wordDocument.ChartToImageConverter = New ChartToImageConverter() +{% endhighlight %} {% endtabs %} For more details about the conversion, refer [here]( https://help.syncfusion.com/document-processing/word/conversions/word-to-pdf/overview?cs-save-lang=1&cs-lang=csharp#convert-word-to-pdf). diff --git a/Document-Processing/Word/Word-Library/NET/mail-merge/mail-merge-events.md b/Document-Processing/Word/Word-Library/NET/mail-merge/mail-merge-events.md index 0f9bff2284..26a1e09f86 100644 --- a/Document-Processing/Word/Word-Library/NET/mail-merge/mail-merge-events.md +++ b/Document-Processing/Word/Word-Library/NET/mail-merge/mail-merge-events.md @@ -67,10 +67,6 @@ document.Save("Sample.docx") document.Close() {% endhighlight %} -{% highlight c# tabtitle="UWP" %} -//ADO.NET object is supported in Windows Forms, WPF, ASP.NET, ASP.NET MVC, ASP.NET Core, and Xamarin platforms alone. -{% endhighlight %} - {% endtabs %} The following code example shows how to set text color to the alternate Mail merge record by using [MergeFieldEventHandler](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MergeFieldEventHandler.html). @@ -108,13 +104,10 @@ Private Sub ApplyAlternateRecordsTextColor(ByVal sender As Object, ByVal args As End Sub {% endhighlight %} -{% highlight c# tabtitle="UWP" %} -//ADO.NET object is supported in Windows Forms, WPF, ASP.NET, ASP.NET MVC, ASP.NET Core, and Xamarin platforms alone. -{% endhighlight %} - {% endtabs %} -N> While executing mail merge, DocIO internally uses a copy of a particular region for populating the contents. Sometimes, unexpected problems may arise due to inserting multiple body items into the region through the mail merge process. So, to insert multiple body items using the merge field event handler, you are recommended to use this [approach](https://www.syncfusion.com/kb/11701/how-to-replace-merge-field-with-html-string-using-mail-merge) at your side. +N> 1. While executing mail merge, DocIO internally uses a copy of a particular region for populating the contents. Sometimes, unexpected problems may arise due to inserting multiple body items into the region through the mail merge process. So, to insert multiple body items using the merge field event handler, you are recommended to use this [approach](https://www.syncfusion.com/kb/11701/how-to-replace-merge-field-with-html-string-using-mail-merge) at your side. +N> 2. The [ExecuteGroup(DataTable)](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MailMerge.html#Syncfusion_DocIO_DLS_MailMerge_ExecuteGroup_System_Data_DataTable_) method is not supported on the UWP platform. The following code example shows GetDataTable method which is used to get data for mail merge. @@ -169,10 +162,6 @@ Private Function GetDataTable() As DataTable End Function {% endhighlight %} -{% highlight c# tabtitle="UWP" %} -//ADO.NET object is supported in Windows Forms, WPF, ASP.NET, ASP.NET MVC, ASP.NET Core, and Xamarin platforms alone. -{% endhighlight %} - {% endtabs %} You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Mail-Merge/Event-for-mail-merge-field). @@ -351,10 +340,6 @@ document.Save("Sample.docx") document.Close() {% endhighlight %} -{% highlight c# tabtitle="UWP" %} -//ADO.NET object is supported in Windows Forms, WPF, ASP.NET, ASP.NET MVC, ASP.NET Core, and Xamarin platforms alone. -{% endhighlight %} - {% endtabs %} The following code example shows how to bind the data to unmerged fields during Mail merge process by using [BeforeClearFieldEventHandler](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.BeforeClearFieldEventHandler.html). @@ -437,10 +422,6 @@ Private Sub BeforeClearField(ByVal sender As Object, ByVal args As BeforeClearFi End Sub {% endhighlight %} -{% highlight c# tabtitle="UWP" %} -//ADO.NET object is supported in Windows Forms, WPF, ASP.NET, ASP.NET MVC, ASP.NET Core, and Xamarin platforms alone. -{% endhighlight %} - {% endtabs %} The following code example shows GetDataTable method which is used to get data for mail merge. @@ -524,10 +505,6 @@ Private Function GetDataTable() As DataTable End Function {% endhighlight %} -{% highlight c# tabtitle="UWP" %} -//ADO.NET object is supported in Windows Forms, WPF, ASP.NET, ASP.NET MVC, ASP.NET Core, and Xamarin platforms alone. -{% endhighlight %} - {% endtabs %} You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Mail-Merge/Event-to-bind-data-for-unmerged-fields). diff --git a/Document-Processing/Word/Word-Library/NET/mail-merge/mail-merge-for-group.md b/Document-Processing/Word/Word-Library/NET/mail-merge/mail-merge-for-group.md index eabea6b92d..0dbf67cd22 100644 --- a/Document-Processing/Word/Word-Library/NET/mail-merge/mail-merge-for-group.md +++ b/Document-Processing/Word/Word-Library/NET/mail-merge/mail-merge-for-group.md @@ -153,6 +153,8 @@ WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx); List employeeList = GetEmployees(); //Creates an instance of “MailMergeDataTable” by specifying mail merge group name and “IEnumerable” collection MailMergeDataTable dataTable = new MailMergeDataTable("Employees", employeeList); +//Uses the mail merge events handler for image fields. +document.MailMerge.MergeImageField += new MergeImageFieldEventHandler(MergeField_EmployeeImage); //Performs Mail merge document.MailMerge.ExecuteGroup(dataTable); //Saves the Word document to MemoryStream @@ -160,6 +162,18 @@ MemoryStream stream = new MemoryStream(); document.Save(stream, FormatType.Docx); //Closes the Word document document.Close(); + +private void MergeField_EmployeeImage(object sender, MergeImageFieldEventArgs args) +{ + //Binds image from file system during mail merge. + if (args.FieldName == "Photo") + { + string photoFileName = args.FieldValue.ToString(); + //Gets the image from file system. + FileStream imageStream = new FileStream(@"Data/" + photoFileName, FileMode.Open, FileAccess.Read); + args.ImageStream = imageStream; + } +} {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} @@ -169,11 +183,25 @@ WordDocument document = new WordDocument("Template.docx"); List employeeList = GetEmployees(); //Creates an instance of “MailMergeDataTable” by specifying mail merge group name and “IEnumerable” collection MailMergeDataTable dataTable = new MailMergeDataTable("Employees", employeeList); +//Uses the mail merge events handler for image fields. +document.MailMerge.MergeImageField += new MergeImageFieldEventHandler(MergeField_EmployeeImage); //Performs Mail merge document.MailMerge.ExecuteGroup(dataTable); //Saves and closes the Word document instance document.Save("Result.docx"); document.Close(); + +private void MergeField_EmployeeImage(object sender, MergeImageFieldEventArgs args) +{ + //Binds image from file system during mail merge. + if (args.FieldName == "Photo") + { + string photoFileName = args.FieldValue.ToString(); + //Gets the image from file system. + FileStream imageStream = new FileStream(@"Data/" + photoFileName, FileMode.Open, FileAccess.Read); + args.ImageStream = imageStream; + } +} {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} @@ -183,85 +211,23 @@ Dim document As New WordDocument("Template.docx") Dim employeeList As List(Of Employee) = GetEmployees() 'Creates an instance of “MailMergeDataTable” by specifying mail merge group name and “IEnumerable” collection Dim dataTable As New MailMergeDataTable("Employees", employeeList) +'Uses the mail merge events handler for image fields. +AddHandler document.MailMerge.MergeImageField, AddressOf MergeField_EmployeeImage 'Performs Mail merge document.MailMerge.ExecuteGroup(dataTable) 'Saves and closes the Word document instance document.Save("Result.docx") document.Close() -{% endhighlight %} - -{% highlight c# tabtitle="Xamarin" %} -//Opens the template document -Assembly assembly = typeof(App).GetTypeInfo().Assembly; -WordDocument document = new WordDocument(assembly.GetManifestResourceStream("Sample.Data.Template.docx"), FormatType.Docx); -//Gets the employee details as “IEnumerable” collection -List employeeList = GetEmployees(); -//Creates an instance of “MailMergeDataTable” by specifying mail merge group name and “IEnumerable” collection -MailMergeDataTable dataTable = new MailMergeDataTable("Employees", employeeList); -//Uses the mail merge events handler for image fields -document.MailMerge.MergeImageField += new MergeImageFieldEventHandler(MergeField_Image); -//Performs Mail merge -document.MailMerge.ExecuteGroup(dataTable); -//Saves the Word file to MemoryStream -MemoryStream stream = new MemoryStream(); -document.Save(stream, FormatType.Docx); -//Closes the document -document.Close(); -//Save the stream as a file in the device and invoke it for viewing -Xamarin.Forms.DependencyService.Get().SaveAndView("Sample.docx", "application/msword", stream); - -//Download the helper files from the following link to save the stream as file and open the file for viewing in Xamarin platform. -//https://help.syncfusion.com/document-processing/word/word-library/net/create-word-document-in-xamarin#helper-files-for-xamarin - -private void MergeField_Image(object sender, MergeImageFieldEventArgs args) -{ - //Binds image from file system during mail merge - if (args.FieldName == "Photo") - { - string ProductFileName = args.FieldValue.ToString(); - //Gets the image from file system - Assembly assembly = typeof(App).GetTypeInfo().Assembly; - Stream imageStream = assembly.GetManifestResourceStream("Sample.Data." + ProductFileName); - args.ImageStream = imageStream; - } -} -{% endhighlight %} - -{% highlight c# tabtitle="UWP" %} -//Creates an instance of a WordDocument -Assembly assembly = typeof(App).GetTypeInfo().Assembly; -WordDocument document = new WordDocument(); -document.Open(assembly.GetManifestResourceStream("Sample.Assets.Template.docx"), FormatType.Docx); -//Gets the employee details as “IEnumerable” collection -List employeeList = GetEmployees(); -//Creates an instance of “MailMergeDataTable” by specifying mail merge group name and “IEnumerable” collection -MailMergeDataTable dataTable = new MailMergeDataTable("Employees", employeeList); -//Uses the mail merge events handler for image fields -document.MailMerge.MergeImageField += new MergeImageFieldEventHandler(MergeField_Image); -//Performs Mail merge -document.MailMerge.ExecuteGroup(dataTable); -//Saves the Word file to MemoryStream -MemoryStream stream = new MemoryStream(); -await document.SaveAsync(stream, FormatType.Docx); -document.Close(); -//Saves the stream as Word file in local machine -Save(stream, "Sample.docx"); - -//Refer to the following link to save Word document in UWP platform. -//https://help.syncfusion.com/document-processing/word/word-library/net/create-word-document-in-uwp#save-word-document-in-uwp -private void MergeField_Image(object sender, MergeImageFieldEventArgs args) -{ - //Binds image from file system during mail merge - if (args.FieldName == "Photo") - { - string ProductFileName = args.FieldValue.ToString(); - //Gets the image from file system - Assembly assembly = typeof(App).GetTypeInfo().Assembly; - Stream imageStream = assembly.GetManifestResourceStream("Sample.Assets." + ProductFileName); - args.ImageStream = imageStream; - } -} +Private Sub MergeField_EmployeeImage(sender As Object, args As MergeImageFieldEventArgs) + 'Binds image from file system during mail merge. + If args.FieldName = "Photo" Then + Dim photoFileName As String = args.FieldValue.ToString() + 'Gets the image from file system. + Dim imageStream As New FileStream("Data/" & photoFileName, FileMode.Open, FileAccess.Read) + args.ImageStream = imageStream + End If +End Sub {% endhighlight %} {% endtabs %} @@ -308,32 +274,6 @@ Public Function GetEmployees() As List(Of Employee) End Function {% endhighlight %} -{% highlight c# tabtitle="Xamarin" %} -public List GetEmployees() -{ - List employees = new List(); - employees.Add(new Employee("Andy", "Bernard", "Sales Representative", "505 - 20th Ave. E. Apt. 2A,", "Seattle", "WA", "USA", "Andy.png")); - employees.Add(new Employee("Andrew", "Fuller", "Vice President, Sales", "908 W. Capital Way", "Tacoma", "WA", "USA", "Andrew.png")); - employees.Add(new Employee("Stanley", "Hudson", "Sales Representative", "722 Moss Bay Blvd.", "Kirkland", "WA", "USA", "Stanley.png")); - employees.Add(new Employee("Margaret", "Peacock", "Sales Representative", "4110 Old Redmond Rd.", "Redmond", "WA", "USA", "Margaret.png")); - employees.Add(new Employee("Steven", "Buchanan", "Sales Manager", "14 Garrett Hill", "London", string.Empty, "UK", "Steven.png")); - return employees; -} -{% endhighlight %} - -{% highlight c# tabtitle="UWP" %} -public List GetEmployees() -{ - List employees = new List(); - employees.Add(new Employee("Andy", "Bernard", "Sales Representative", "505 - 20th Ave. E. Apt. 2A,", "Seattle", "WA", "USA", "Andy.png")); - employees.Add(new Employee("Andrew", "Fuller", "Vice President, Sales", "908 W. Capital Way", "Tacoma", "WA", "USA", "Andrew.png")); - employees.Add(new Employee("Stanley", "Hudson", "Sales Representative", "722 Moss Bay Blvd.", "Kirkland", "WA", "USA", "Stanley.png")); - employees.Add(new Employee("Margaret", "Peacock", "Sales Representative", "4110 Old Redmond Rd.", "Redmond", "WA", "USA", "Margaret.png")); - employees.Add(new Employee("Steven", "Buchanan", "Sales Manager", "14 Garrett Hill", "London", string.Empty, "UK", "Steven.png")); - return employees; -} -{% endhighlight %} - {% endtabs %} The following code example shows the Employee class. @@ -477,56 +417,6 @@ Public Class Employee End Class {% endhighlight %} -{% highlight c# tabtitle="Xamarin" %} -public class Employee -{ - public string FirstName { get; set; } - public string LastName { get; set; } - public string Address { get; set; } - public string City { get; set; } - public string Region { get; set; } - public string Country { get; set; } - public string Title { get; set; } - public string Photo { get; set; } - public Employee(string firstName, string lastName, string title, string address, string city, string region, string country, string photoFileName) - { - FirstName = firstName; - LastName = lastName; - Title = title; - Address = address; - City = city; - Region = region; - Country = country; - Photo = photoFileName; - } -} -{% endhighlight %} - -{% highlight c# tabtitle="UWP" %} -public class Employee -{ - public string FirstName { get; set; } - public string LastName { get; set; } - public string Address { get; set; } - public string City { get; set; } - public string Region { get; set; } - public string Country { get; set; } - public string Title { get; set; } - public string Photo { get; set; } - public Employee(string firstName, string lastName, string title, string address, string city, string region, string country, string photoFileName) - { - FirstName = firstName; - LastName = lastName; - Title = title; - Address = address; - City = city; - Region = region; - Country = country; - Photo = photoFileName; - } -} -{% endhighlight %} - {% endtabs %} You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Mail-Merge/Mail-merge-with-.NET-objects). diff --git a/Document-Processing/Word/Word-Library/NET/mail-merge/mail-merge-for-nested-groups.md b/Document-Processing/Word/Word-Library/NET/mail-merge/mail-merge-for-nested-groups.md index 09c23abada..779f96d73f 100644 --- a/Document-Processing/Word/Word-Library/NET/mail-merge/mail-merge-for-nested-groups.md +++ b/Document-Processing/Word/Word-Library/NET/mail-merge/mail-merge-for-nested-groups.md @@ -97,14 +97,6 @@ document.Save("Sample.docx") document.Close() {% endhighlight %} -{% highlight c# tabtitle="Xamarin" %} -//OleDbConnection not supported in Xamarin platform. -{% endhighlight %} - -{% highlight c# tabtitle="UWP" %} -//OleDbConnection not supported in UWP platform. -{% endhighlight %} - {% endtabs %} The following code example shows GetCommands method which is used to get data for mail merge. @@ -115,7 +107,7 @@ The following code example shows GetCommands method which is used to get data fo //OleDbConnection supported in ASP.NET Core platform from 3.0 Preview 8 only. {% endhighlight %} -{% highlight c# tabtitle="C#" %} +{% highlight c# tabtitle="C# [Windows-specific]" %} private ArrayList GetCommands() { //ArrayList contains the list of commands @@ -150,14 +142,6 @@ Private Function GetCommands() As ArrayList End Function {% endhighlight %} -{% highlight c# tabtitle="Xamarin" %} -//OleDbConnection not supported in Xamarin platform. -{% endhighlight %} - -{% highlight c# tabtitle="UWP" %} -//OleDbConnection not supported in UWP platform. -{% endhighlight %} - {% endtabs %} You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Mail-Merge/Mail-merge-with-explicit-relational-data). @@ -249,42 +233,6 @@ document.Save("Sample.docx") document.Close() {% endhighlight %} -{% highlight c# tabtitle="Xamarin" %} -//Creating dynamic objects using dynamic keyword is not supported in Xamarin.iOS. -//You can use IDictionary collection to generate dynamic objects. -{% endhighlight %} - -{% highlight c# tabtitle="UWP" %} -Assembly assembly = typeof(App).GetTypeInfo().Assembly; -WordDocument document = new WordDocument(); -document.Open(assembly.GetManifestResourceStream("Sample.Assets.Template.docx"), FormatType.Docx); -//Creates an instance of the MailMergeDataSet -MailMergeDataSet dataSet = new MailMergeDataSet(); -//Creates the mail merge data table in order to perform mail merge -MailMergeDataTable dataTable = new MailMergeDataTable("Customers", GetCustomers()); -dataSet.Add(dataTable); -dataTable = new MailMergeDataTable("Orders", GetOrders()); -dataSet.Add(dataTable); -List commands = new List(); -//DictionaryEntry contain "Source table" (key) and "Command" (value) -DictionaryEntry entry = new DictionaryEntry("Customers", string.Empty); -commands.Add(entry); -//Retrieves the customer details -entry = new DictionaryEntry("Orders", "CustomerID = %Customers.CustomerID%"); -commands.Add(entry); -//Performs the mail merge operation with the dynamic collection -document.MailMerge.ExecuteNestedGroup(dataSet, commands); -//Saves the Word file to MemoryStream -MemoryStream stream = new MemoryStream(); -await document.SaveAsync(stream, FormatType.Docx); -//Closes the Word document -document.Close(); -//Saves the stream as Word file in local machine -Save(stream, "Sample.docx"); -//Refer to the following link to save Word document in UWP platform. -//https://help.syncfusion.com/document-processing/word/word-library/net/create-word-document-in-uwp#save-word-document-in-uwp -{% endhighlight %} - {% endtabs %} The following code example shows GetCustomers and GetOrders methods which are used to get data for mail merge. @@ -346,30 +294,6 @@ Private Function GetOrders() As List(Of ExpandoObject) End Function {% endhighlight %} -{% highlight c# tabtitle="Xamarin" %} -//Creating dynamic objects using dynamic keyword is not supported in Xamarin.iOS. -//You can use IDictionary collection to generate dynamic objects. -{% endhighlight %} - -{% highlight c# tabtitle="UWP" %} -private List GetCustomers() -{ - List customers = new List(); - customers.Add(GetDynamicCustomer(100, "Robert", "Syncfusion")); - customers.Add(GetDynamicCustomer(102, "John", "Syncfusion")); - customers.Add(GetDynamicCustomer(110,"David","Syncfusion")); - return customers; -} -private List GetOrders() -{ - List orders = new List(); - orders.Add(GetDynamicOrder(1001, "MSWord", 100)); - orders.Add(GetDynamicOrder(1002, "AdobeReader", 100)); - orders.Add(GetDynamicOrder(1003, "VisualStudio", 102)); - return orders; -} -{% endhighlight %} - {% endtabs %} The following code example shows GetDynamicCustomer and GetDynamicOrder methods, which are used to generate dynamic objects for mail merge. @@ -431,30 +355,6 @@ Private Function GetDynamicOrder(orderID As Integer, orderName As String, custom End Function {% endhighlight %} -{% highlight c# tabtitle="Xamarin" %} -//Creating dynamic objects using dynamic keyword is not supported in Xamarin.iOS. -//You can use IDictionary collection to generate dynamic objects. -{% endhighlight %} - -{% highlight c# tabtitle="UWP" %} -private dynamic GetDynamicCustomer(int customerID,string customerName, string companyName) -{ - dynamic dynamicCustomer = new ExpandoObject(); - dynamicCustomer.CustomerID = customerID; - dynamicCustomer.CustomerName = customerName; - dynamicCustomer.CompanyName = companyName; - return dynamicCustomer; -} -private dynamic GetDynamicOrder(int orderID, string orderName, int customerID) -{ - dynamic dynamicOrder = new ExpandoObject(); - dynamicOrder.OrderID = orderID; - dynamicOrder.OrderName = orderName; - dynamicOrder.CustomerID = customerID; - return dynamicOrder; -} -{% endhighlight %} - {% endtabs %} You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Mail-Merge/Mail-merge-with-dynamic-objects). diff --git a/Document-Processing/Word/Word-Library/NET/mail-merge/mail-merge-options.md b/Document-Processing/Word/Word-Library/NET/mail-merge/mail-merge-options.md index 588a20c733..e8b34b668e 100644 --- a/Document-Processing/Word/Word-Library/NET/mail-merge/mail-merge-options.md +++ b/Document-Processing/Word/Word-Library/NET/mail-merge/mail-merge-options.md @@ -803,14 +803,12 @@ document.Save("Sample.docx") document.Close() {% endhighlight %} -{% highlight c# tabtitle="UWP" %} -//ADO.NET object is supported in Windows Forms, WPF, ASP.NET, ASP.NET MVC, ASP.NET Core, and Xamarin platforms alone. -{% endhighlight %} - {% endtabs %} You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Mail-Merge/Insert-as-new-row). +N> The [ExecuteGroup(DataTable)](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MailMerge.html#Syncfusion_DocIO_DLS_MailMerge_ExecuteGroup_System_Data_DataTable_) method is not supported on the UWP platform. + ## Skip to merge image You can skip to merge particular image while performing mail merge in Word document. diff --git a/Document-Processing/Word/Word-Library/NET/mail-merge/mail-merge-troubleshooting-tips.md b/Document-Processing/Word/Word-Library/NET/mail-merge/mail-merge-troubleshooting-tips.md index 891d42965e..3598869836 100644 --- a/Document-Processing/Word/Word-Library/NET/mail-merge/mail-merge-troubleshooting-tips.md +++ b/Document-Processing/Word/Word-Library/NET/mail-merge/mail-merge-troubleshooting-tips.md @@ -6,7 +6,7 @@ control: DocIO documentation: UG --- -# Troubleshooting Mail Merge Issues in .NET Word Library +# Troubleshooting Mail merge Issues in .NET Word Library ## Why is mail merge not working correctly in DocIO? @@ -36,6 +36,24 @@ public class Employee public string LastName { get; set; } // Matches merge field name } {% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} +public class Employee +{ + public string FirstName { get; set; } // Matches merge field name + public string LastName { get; set; } // Matches merge field name +} +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Public Class Employee + 'Matches merge field name + Public Property FirstName As String + 'Matches merge field name + Public Property LastName As String +End Class +{% endhighlight %} + {% endtabs %} * **Show Field Codes:** Press Alt + F9 in Microsoft Word to reveal field codes and verify they are correct.