diff --git a/Document-Processing-toc.html b/Document-Processing-toc.html index 853487ceb..6e1374d36 100644 --- a/Document-Processing-toc.html +++ b/Document-Processing-toc.html @@ -7096,6 +7096,32 @@ +
  • + Markdown to Excel Conversion + +
  • +
  • + Excel to Markdown Conversion + +
  • diff --git a/Document-Processing/Excel/Conversions/Excel-to-Markdown/NET/Excel-to-Markdown-Conversion.md b/Document-Processing/Excel/Conversions/Excel-to-Markdown/NET/Excel-to-Markdown-Conversion.md new file mode 100644 index 000000000..75ac722ea --- /dev/null +++ b/Document-Processing/Excel/Conversions/Excel-to-Markdown/NET/Excel-to-Markdown-Conversion.md @@ -0,0 +1,240 @@ +--- +title: Convert Excel to Markdown in C# | XlsIO | Syncfusion +description: Convert Excel to Markdown in C# using Syncfusion® .NET Excel (XlsIO) library without Microsoft Excel or interop dependencies +platform: document-processing +control: XlsIO +documentation: UG +--- + +# Excel to Markdown Conversion + +Markdown is a lightweight markup language that adds formatting elements to plain text documents. The .NET Excel (XlsIO) library supports the conversion of Excel to Markdown document and vice versa, which mostly follows the CommonMark specification and GitHub-flavored syntax. + +## Assemblies and NuGet packages required + +Refer to the following links for assemblies and NuGet packages required based on platforms to convert an Excel document to Markdown using the .NET Excel Library (XlsIO). + +* [Excel to Markdown conversion assemblies](https://help.syncfusion.com/document-processing/excel/excel-library/net/assemblies-required) +* [Excel to Markdown conversion NuGet packages](https://help.syncfusion.com/document-processing/excel/excel-library/net/nuget-packages-required) + +## Convert Excel to Markdown document + +Convert an existing Excel file to Markdown using the .NET Excel (XlsIO) library. + +The following code example shows how to convert an Excel to Markdown file. + +{% tabs %} + +{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/XlsIO-Examples/master/Excel%20to%20Markdown/Excel-to-Markdown/.NET/Excel-to-Markdown/Excel-to-Markdown/Program.cs,180" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + + IWorkbook workbook = application.Workbooks.Open(@"Data/Markdown.xlsx"); + + using (FileStream fileStream = new FileStream(@"Output/ExcelToMarkdown.md", FileMode.Create, FileAccess.Write)) + { + workbook.SaveAs(fileStream, ExcelSaveType.Markdown); + } +} +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + + IWorkbook workbook = application.Workbooks.Open(@"Data/Markdown.xlsx"); + + using (FileStream fileStream = new FileStream(@"Output/ExcelToMarkdown.md", FileMode.Create, FileAccess.Write)) + { + workbook.SaveAs(fileStream, ExcelSaveType.Markdown); + } +} +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Using excelEngine As New ExcelEngine() + Dim application As IApplication = excelEngine.Excel + application.DefaultVersion = ExcelVersion.Xlsx + + Dim workbook As IWorkbook = application.Workbooks.Open("Markdown.xlsx") + + Using fileStream As New FileStream("ExcelToMarkdown.md", FileMode.Create, FileAccess.Write) + workbook.SaveAs(fileStream, ExcelSaveType.Markdown) + End Using +End Using +{% endhighlight %} + +{% endtabs %} + +You can download a complete working sample from this GitHub page. + +## Customize image saving + +### Export images to folder + +Specify the folder location to export the images using the **MarkdownExportImagesFolder** API. + +The following code example demonstrates how to set the images folder for exporting images while converting an Excel document to a Markdown file. + +{% tabs %} + +{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/XlsIO-Examples/master/Excel%20to%20Markdown/Export_images_to_folder/.NET/Export_images_to_folder/Export_images_to_folder/Program.cs,180" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + + IWorkbook workbook = application.Workbooks.Open(@"Data/Markdown.xlsx"); + + MarkdownExportOptions exportOptions = new MarkdownExportOptions(); + exportOptions.SaveOptions.MarkdownExportImagesFolder = @"D:/Temp/Image1.png"; + + using (FileStream fileStream = new FileStream(@"Output/ExcelToMarkdown.md", FileMode.Create, FileAccess.Write)) + { + workbook.SaveAs(fileStream, exportOptions); + } +} +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + + IWorkbook workbook = application.Workbooks.Open(@"Data/Markdown.xlsx"); + + MarkdownExportOptions exportOptions = new MarkdownExportOptions(); + exportOptions.SaveOptions.MarkdownExportImagesFolder = @"D:/Temp/Image1.png"; + + using (FileStream fileStream = new FileStream(@"Output/ExcelToMarkdown.md", FileMode.Create, FileAccess.Write)) + { + workbook.SaveAs(fileStream, exportOptions); + } +} +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Using excelEngine As New ExcelEngine() + Dim application As IApplication = excelEngine.Excel + Dim workbook As IWorkbook = application.Workbooks.Open("Markdown.xlsx") + + Dim exportOptions As New MarkdownExportOptions() + exportOptions.SaveOptions.MarkdownExportImagesFolder = "D:/Temp/Image1.png" + + Using fileStream As New FileStream("ExcelToMarkdown.md", FileMode.Create, FileAccess.Write) + workbook.SaveAs(fileStream, exportOptions) + End Using +End Using +{% endhighlight %} + +{% endtabs %} + +You can download a complete working sample from this GitHub page. + +### Customize the image path + +XlsIO provides an **ImageNodeVisited** event, which is used to customize the image path to set in the output Markdown file and save images externally while converting an Excel document to a Markdown. + +The following code example illustrates how to save Image files during Excel to Markdown Conversion. + +{% tabs %} + +{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/XlsIO-Examples/master/Excel%20to%20Markdown/Customize-image-path/.NET/Customize-image-path/Customize-image-path/Program.cs,180" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + + IWorkbook workbook = application.Workbooks.Open(@"Data/Markdown.xlsx"); + + MarkdownExportOptions exportOptions = new MarkdownExportOptions(); + exportOptions.SaveOptions.ImageNodeVisited += MdExportSettings_ImageNodeVisited; + + using (FileStream fileStream = new FileStream(@"ExcelToMarkdown.md", FileMode.Create, FileAccess.Write)) + { + workbook.SaveAs(fileStream, exportOptions); + } +} +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + + IWorkbook workbook = application.Workbooks.Open(@"Data/Markdown.xlsx"); + + MarkdownExportOptions exportOptions = new MarkdownExportOptions(); + exportOptions.SaveOptions.ImageNodeVisited += MdExportSettings_ImageNodeVisited; + + using (FileStream fileStream = new FileStream(@"ExcelToMarkdown.md", FileMode.Create, FileAccess.Write)) + { + workbook.SaveAs(fileStream, exportOptions); + } +} +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Using excelEngine As New ExcelEngine() + Dim application As IApplication = excelEngine.Excel + + Dim workbook As IWorkbook = application.Workbooks.Open("Markdown.xlsx") + + ' Configure Markdown export options + Dim exportOptions As New MarkdownExportOptions() + AddHandler exportOptions.SaveOptions.ImageNodeVisited, AddressOf MdExportSettings_ImageNodeVisited + + ' Save as Markdown file + Using fileStream As New FileStream("Output.md", FileMode.Create, FileAccess.Write) + workbook.SaveAs(fileStream, exportOptions) + End Using +End Using +{% endhighlight %} + +{% endtabs %} + +The following code examples show the event handler to customize the image path and save the image in an external folder. + +{% tabs %} + +{% highlight c# tabtitle="C# [Cross-platform]" %} +private static void MdExportSettings_ImageNodeVisited(object sender, SaveImageNodeVisitedEventArgs args) +{ + string imagepath = @"D:\Temp\Image1.png"; + //Save the image stream as a file. + using (FileStream fileStreamOutput = File.Create(imagepath)) + args.ImageStream.CopyTo(fileStreamOutput); + //Set the image URI to be used in the output markdown. + args.Uri = imagepath; +} +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} +private static void MdExportSettings_ImageNodeVisited(object sender, SaveImageNodeVisitedEventArgs args) +{ + string imagepath = @"D:\Temp\Image1.png"; + //Save the image stream as a file. + using (FileStream fileStreamOutput = File.Create(imagepath)) + args.ImageStream.CopyTo(fileStreamOutput); + //Set the image URI to be used in the output markdown. + args.Uri = imagepath; +} +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Private Sub MdExportSettings_ImageNodeVisited(sender As Object, args As SaveImageNodeVisitedEventArgs) + Dim imagePath As String = "D:\Temp\Image1.png" + ' Save the image stream as a file + Using fileStreamOutput As FileStream = File.Create(imagePath) + args.ImageStream.CopyTo(fileStreamOutput) + End Using + ' Set the image URI to be used in the output markdown + args.Uri = imagePath +End Sub +{% endhighlight %} + +{% endtabs %} + +You can download a complete working sample from this GitHub page. \ No newline at end of file diff --git a/Document-Processing/Excel/Conversions/Excel-to-Markdown/overview.md b/Document-Processing/Excel/Conversions/Excel-to-Markdown/overview.md new file mode 100644 index 000000000..75ac722ea --- /dev/null +++ b/Document-Processing/Excel/Conversions/Excel-to-Markdown/overview.md @@ -0,0 +1,240 @@ +--- +title: Convert Excel to Markdown in C# | XlsIO | Syncfusion +description: Convert Excel to Markdown in C# using Syncfusion® .NET Excel (XlsIO) library without Microsoft Excel or interop dependencies +platform: document-processing +control: XlsIO +documentation: UG +--- + +# Excel to Markdown Conversion + +Markdown is a lightweight markup language that adds formatting elements to plain text documents. The .NET Excel (XlsIO) library supports the conversion of Excel to Markdown document and vice versa, which mostly follows the CommonMark specification and GitHub-flavored syntax. + +## Assemblies and NuGet packages required + +Refer to the following links for assemblies and NuGet packages required based on platforms to convert an Excel document to Markdown using the .NET Excel Library (XlsIO). + +* [Excel to Markdown conversion assemblies](https://help.syncfusion.com/document-processing/excel/excel-library/net/assemblies-required) +* [Excel to Markdown conversion NuGet packages](https://help.syncfusion.com/document-processing/excel/excel-library/net/nuget-packages-required) + +## Convert Excel to Markdown document + +Convert an existing Excel file to Markdown using the .NET Excel (XlsIO) library. + +The following code example shows how to convert an Excel to Markdown file. + +{% tabs %} + +{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/XlsIO-Examples/master/Excel%20to%20Markdown/Excel-to-Markdown/.NET/Excel-to-Markdown/Excel-to-Markdown/Program.cs,180" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + + IWorkbook workbook = application.Workbooks.Open(@"Data/Markdown.xlsx"); + + using (FileStream fileStream = new FileStream(@"Output/ExcelToMarkdown.md", FileMode.Create, FileAccess.Write)) + { + workbook.SaveAs(fileStream, ExcelSaveType.Markdown); + } +} +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + + IWorkbook workbook = application.Workbooks.Open(@"Data/Markdown.xlsx"); + + using (FileStream fileStream = new FileStream(@"Output/ExcelToMarkdown.md", FileMode.Create, FileAccess.Write)) + { + workbook.SaveAs(fileStream, ExcelSaveType.Markdown); + } +} +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Using excelEngine As New ExcelEngine() + Dim application As IApplication = excelEngine.Excel + application.DefaultVersion = ExcelVersion.Xlsx + + Dim workbook As IWorkbook = application.Workbooks.Open("Markdown.xlsx") + + Using fileStream As New FileStream("ExcelToMarkdown.md", FileMode.Create, FileAccess.Write) + workbook.SaveAs(fileStream, ExcelSaveType.Markdown) + End Using +End Using +{% endhighlight %} + +{% endtabs %} + +You can download a complete working sample from this GitHub page. + +## Customize image saving + +### Export images to folder + +Specify the folder location to export the images using the **MarkdownExportImagesFolder** API. + +The following code example demonstrates how to set the images folder for exporting images while converting an Excel document to a Markdown file. + +{% tabs %} + +{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/XlsIO-Examples/master/Excel%20to%20Markdown/Export_images_to_folder/.NET/Export_images_to_folder/Export_images_to_folder/Program.cs,180" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + + IWorkbook workbook = application.Workbooks.Open(@"Data/Markdown.xlsx"); + + MarkdownExportOptions exportOptions = new MarkdownExportOptions(); + exportOptions.SaveOptions.MarkdownExportImagesFolder = @"D:/Temp/Image1.png"; + + using (FileStream fileStream = new FileStream(@"Output/ExcelToMarkdown.md", FileMode.Create, FileAccess.Write)) + { + workbook.SaveAs(fileStream, exportOptions); + } +} +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + + IWorkbook workbook = application.Workbooks.Open(@"Data/Markdown.xlsx"); + + MarkdownExportOptions exportOptions = new MarkdownExportOptions(); + exportOptions.SaveOptions.MarkdownExportImagesFolder = @"D:/Temp/Image1.png"; + + using (FileStream fileStream = new FileStream(@"Output/ExcelToMarkdown.md", FileMode.Create, FileAccess.Write)) + { + workbook.SaveAs(fileStream, exportOptions); + } +} +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Using excelEngine As New ExcelEngine() + Dim application As IApplication = excelEngine.Excel + Dim workbook As IWorkbook = application.Workbooks.Open("Markdown.xlsx") + + Dim exportOptions As New MarkdownExportOptions() + exportOptions.SaveOptions.MarkdownExportImagesFolder = "D:/Temp/Image1.png" + + Using fileStream As New FileStream("ExcelToMarkdown.md", FileMode.Create, FileAccess.Write) + workbook.SaveAs(fileStream, exportOptions) + End Using +End Using +{% endhighlight %} + +{% endtabs %} + +You can download a complete working sample from this GitHub page. + +### Customize the image path + +XlsIO provides an **ImageNodeVisited** event, which is used to customize the image path to set in the output Markdown file and save images externally while converting an Excel document to a Markdown. + +The following code example illustrates how to save Image files during Excel to Markdown Conversion. + +{% tabs %} + +{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/XlsIO-Examples/master/Excel%20to%20Markdown/Customize-image-path/.NET/Customize-image-path/Customize-image-path/Program.cs,180" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + + IWorkbook workbook = application.Workbooks.Open(@"Data/Markdown.xlsx"); + + MarkdownExportOptions exportOptions = new MarkdownExportOptions(); + exportOptions.SaveOptions.ImageNodeVisited += MdExportSettings_ImageNodeVisited; + + using (FileStream fileStream = new FileStream(@"ExcelToMarkdown.md", FileMode.Create, FileAccess.Write)) + { + workbook.SaveAs(fileStream, exportOptions); + } +} +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + + IWorkbook workbook = application.Workbooks.Open(@"Data/Markdown.xlsx"); + + MarkdownExportOptions exportOptions = new MarkdownExportOptions(); + exportOptions.SaveOptions.ImageNodeVisited += MdExportSettings_ImageNodeVisited; + + using (FileStream fileStream = new FileStream(@"ExcelToMarkdown.md", FileMode.Create, FileAccess.Write)) + { + workbook.SaveAs(fileStream, exportOptions); + } +} +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Using excelEngine As New ExcelEngine() + Dim application As IApplication = excelEngine.Excel + + Dim workbook As IWorkbook = application.Workbooks.Open("Markdown.xlsx") + + ' Configure Markdown export options + Dim exportOptions As New MarkdownExportOptions() + AddHandler exportOptions.SaveOptions.ImageNodeVisited, AddressOf MdExportSettings_ImageNodeVisited + + ' Save as Markdown file + Using fileStream As New FileStream("Output.md", FileMode.Create, FileAccess.Write) + workbook.SaveAs(fileStream, exportOptions) + End Using +End Using +{% endhighlight %} + +{% endtabs %} + +The following code examples show the event handler to customize the image path and save the image in an external folder. + +{% tabs %} + +{% highlight c# tabtitle="C# [Cross-platform]" %} +private static void MdExportSettings_ImageNodeVisited(object sender, SaveImageNodeVisitedEventArgs args) +{ + string imagepath = @"D:\Temp\Image1.png"; + //Save the image stream as a file. + using (FileStream fileStreamOutput = File.Create(imagepath)) + args.ImageStream.CopyTo(fileStreamOutput); + //Set the image URI to be used in the output markdown. + args.Uri = imagepath; +} +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} +private static void MdExportSettings_ImageNodeVisited(object sender, SaveImageNodeVisitedEventArgs args) +{ + string imagepath = @"D:\Temp\Image1.png"; + //Save the image stream as a file. + using (FileStream fileStreamOutput = File.Create(imagepath)) + args.ImageStream.CopyTo(fileStreamOutput); + //Set the image URI to be used in the output markdown. + args.Uri = imagepath; +} +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Private Sub MdExportSettings_ImageNodeVisited(sender As Object, args As SaveImageNodeVisitedEventArgs) + Dim imagePath As String = "D:\Temp\Image1.png" + ' Save the image stream as a file + Using fileStreamOutput As FileStream = File.Create(imagePath) + args.ImageStream.CopyTo(fileStreamOutput) + End Using + ' Set the image URI to be used in the output markdown + args.Uri = imagePath +End Sub +{% endhighlight %} + +{% endtabs %} + +You can download a complete working sample from this GitHub page. \ No newline at end of file diff --git a/Document-Processing/Excel/Conversions/Markdown-to-Excel/NET/Markdown-to-Excel-Conversion.md b/Document-Processing/Excel/Conversions/Markdown-to-Excel/NET/Markdown-to-Excel-Conversion.md new file mode 100644 index 000000000..6b090da83 --- /dev/null +++ b/Document-Processing/Excel/Conversions/Markdown-to-Excel/NET/Markdown-to-Excel-Conversion.md @@ -0,0 +1,185 @@ +--- +title: Convert Markdown to Excel in C# | XlsIO | Syncfusion +description: Convert Markdown to Excel in C# using Syncfusion® .NET Excel (XlsIO) library without Microsoft Excel or interop dependencies +platform: document-processing +control: XlsIO +documentation: UG +--- + +# Markdown to Excel Conversion + +Markdown is a lightweight markup language that adds formatting elements to plain text documents. The .NET Excel (XlsIO) library supports the conversion of Markdown to Excel document and vice versa, which mostly follows the CommonMark specification and GitHub-flavored syntax. + +## Assemblies and NuGet packages required + +Refer to the following links for assemblies and NuGet packages required based on platforms to convert a Markdown file to an Excel document using the .NET Excel Library (XlsIO). + +* [Markdown to Excel conversion assemblies](https://help.syncfusion.com/document-processing/excel/excel-library/net/assemblies-required) +* [Markdown to Excel conversion NuGet packages](https://help.syncfusion.com/document-processing/excel/excel-library/net/nuget-packages-required) + +## Convert Markdown to Excel document + +Convert an existing Markdown file to an Excel document using the .NET Excel (XlsIO) library. + +The following code example shows how to convert Markdown to Excel document. + +{% tabs %} + +{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/XlsIO-Examples/master/Markdown%20to%20Excel/Markdown-to-Excel/.NET/Markdown-to-Excel/Markdown-to-Excel/Program.cs,180" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + + IWorkbook workbook = application.Workbooks.Open(@"Data/Sample.md", ExcelOpenType.Markdown); + + workbook.SaveAs(Path.GetFullPath("Output/MarkdownToExcel.xlsx")); +} +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + + IWorkbook workbook = application.Workbooks.Open(@"Data/Sample.md", ExcelOpenType.Markdown); + + workbook.SaveAs(Path.GetFullPath("Output/MarkdownToExcel.xlsx")); +} +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Using excelEngine As New ExcelEngine() + Dim application As IApplication = excelEngine.Excel + application.DefaultVersion = ExcelVersion.Xlsx + + Dim workbook As IWorkbook = application.Workbooks.Open("Sample.md", ExcelOpenType.Markdown) + + workbook.SaveAs("MarkdownToExcel.xlsx") +End Using +{% endhighlight %} + +{% endtabs %} + +You can download a complete working sample from this GitHub page. + +## Customize image data + +The .NET Excel (XlsIO) library provides a **ImageNodeVisited** event, which customizes image data while importing a Markdown file. Implement the logic to customize the image data by using this **ImageNodeVisited** event. + +The following code example shows how to load image data based on the image source path when importing the Markdown files. + +{% tabs %} + +{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/XlsIO-Examples/master/Markdown%20to%20Excel/Customize-Image/.NET/Customize-Image/Customize-Image/Program.cs,180" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + + MdImportSettings settings = new MdImportSettings(); + + settings.ImageNodeVisited += MdImportSettings_ImageNodeVisited; + + IWorkbook workbook = application.Workbooks.Open(@"Data/Sample1.md", settings); + + workbook.SaveAs(Path.GetFullPath("Output/MarkdownToExcel.xlsx")); +} +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + + MdImportSettings settings = new MdImportSettings(); + + settings.ImageNodeVisited += MdImportSettings_ImageNodeVisited; + + IWorkbook workbook = application.Workbooks.Open(@"Data/Sample1.md", settings); + + workbook.SaveAs(Path.GetFullPath("Output/MarkdownToExcel.xlsx")); +} +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Using excelEngine As New ExcelEngine() + Dim application As IApplication = excelEngine.Excel + application.DefaultVersion = ExcelVersion.Xlsx + + Dim settings As New MdImportSettings() + AddHandler settings.ImageNodeVisited, AddressOf MdImportSettings_ImageNodeVisited + + Dim workbook As IWorkbook = application.Workbooks.Open("Sample.md", settings) + + workbook.SaveAs("MarkdownToExcel.xlsx") +End Using +{% endhighlight %} + +{% endtabs %} + +The following code examples show the event handler to customize the image based on the source path. + +{% tabs %} + +{% highlight c# tabtitle="C# [Cross-platform]" %} +private static void MdImportSettings_ImageNodeVisited(object sender, MdImageNodeVisitedEventArgs args) +{ + //Set the image stream based on the image name from the input Markdown. + if (args.Uri == "Image_1.png") + args.ImageStream = new FileStream(Path.GetFullPath("Data/Image_1.png"), FileMode.Open); + else if (args.Uri == "Image_2.png") + args.ImageStream = new FileStream(Path.GetFullPath("Data/Image_2.png"), FileMode.Open); + //Retrive the image from the website and use it. + else if (args.Uri.StartsWith("https://")) + { + WebClient client = new WebClient(); + byte[] image = client.DownloadData(args.Uri); + Stream stream = new MemoryStream(image); + args.ImageStream = stream; + } +} +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} +private static void MdImportSettings_ImageNodeVisited(object sender, MdImageNodeVisitedEventArgs args) +{ + //Set the image stream based on the image name from the input Markdown. + if (args.Uri == "Image_1.png") + args.ImageStream = new FileStream(Path.GetFullPath("Data/Image_1.png"), FileMode.Open); + else if (args.Uri == "Image_2.png") + args.ImageStream = new FileStream(Path.GetFullPath("Data/Image_2.png"), FileMode.Open); + //Retrive the image from the website and use it. + else if (args.Uri.StartsWith("https://")) + { + WebClient client = new WebClient(); + byte[] image = client.DownloadData(args.Uri); + Stream stream = new MemoryStream(image); + args.ImageStream = stream; + } +} +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Private Sub MdImportSettings_ImageNodeVisited(sender As Object, args As MdImageNodeVisitedEventArgs) + ' Set the image stream based on the image name from the input Markdown. + If args.Uri = "Image_1.png" Then + args.ImageStream = New FileStream(Path.GetFullPath("D:\UG Branch\1029061-MarkdownExample\Markdown to Excel\Markdown-to-Excel\.NET\Markdown-to-Excel\Markdown-to-Excel\Data\Image_1.png"), FileMode.Open) + ElseIf args.Uri = "Image_2.png" Then + args.ImageStream = New FileStream(Path.GetFullPath("D:\UG Branch\1029061-MarkdownExample\Markdown to Excel\Markdown-to-Excel\.NET\Markdown-to-Excel\Markdown-to-Excel\Data\.png"), FileMode.Open) + ElseIf args.Uri.StartsWith("https://") Then + Dim client As New WebClient() + Dim imageBytes As Byte() = client.DownloadData(args.Uri) + Dim stream As New MemoryStream(imageBytes) + args.ImageStream = stream + End If +End Sub +{% endhighlight %} + +{% endtabs %} + +You can download a complete working sample from this GitHub page. + +N> Hook the event handler before opening Excel document as per the above code example. \ No newline at end of file diff --git a/Document-Processing/Excel/Conversions/Markdown-to-Excel/overview.md b/Document-Processing/Excel/Conversions/Markdown-to-Excel/overview.md new file mode 100644 index 000000000..6b090da83 --- /dev/null +++ b/Document-Processing/Excel/Conversions/Markdown-to-Excel/overview.md @@ -0,0 +1,185 @@ +--- +title: Convert Markdown to Excel in C# | XlsIO | Syncfusion +description: Convert Markdown to Excel in C# using Syncfusion® .NET Excel (XlsIO) library without Microsoft Excel or interop dependencies +platform: document-processing +control: XlsIO +documentation: UG +--- + +# Markdown to Excel Conversion + +Markdown is a lightweight markup language that adds formatting elements to plain text documents. The .NET Excel (XlsIO) library supports the conversion of Markdown to Excel document and vice versa, which mostly follows the CommonMark specification and GitHub-flavored syntax. + +## Assemblies and NuGet packages required + +Refer to the following links for assemblies and NuGet packages required based on platforms to convert a Markdown file to an Excel document using the .NET Excel Library (XlsIO). + +* [Markdown to Excel conversion assemblies](https://help.syncfusion.com/document-processing/excel/excel-library/net/assemblies-required) +* [Markdown to Excel conversion NuGet packages](https://help.syncfusion.com/document-processing/excel/excel-library/net/nuget-packages-required) + +## Convert Markdown to Excel document + +Convert an existing Markdown file to an Excel document using the .NET Excel (XlsIO) library. + +The following code example shows how to convert Markdown to Excel document. + +{% tabs %} + +{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/XlsIO-Examples/master/Markdown%20to%20Excel/Markdown-to-Excel/.NET/Markdown-to-Excel/Markdown-to-Excel/Program.cs,180" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + + IWorkbook workbook = application.Workbooks.Open(@"Data/Sample.md", ExcelOpenType.Markdown); + + workbook.SaveAs(Path.GetFullPath("Output/MarkdownToExcel.xlsx")); +} +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + + IWorkbook workbook = application.Workbooks.Open(@"Data/Sample.md", ExcelOpenType.Markdown); + + workbook.SaveAs(Path.GetFullPath("Output/MarkdownToExcel.xlsx")); +} +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Using excelEngine As New ExcelEngine() + Dim application As IApplication = excelEngine.Excel + application.DefaultVersion = ExcelVersion.Xlsx + + Dim workbook As IWorkbook = application.Workbooks.Open("Sample.md", ExcelOpenType.Markdown) + + workbook.SaveAs("MarkdownToExcel.xlsx") +End Using +{% endhighlight %} + +{% endtabs %} + +You can download a complete working sample from this GitHub page. + +## Customize image data + +The .NET Excel (XlsIO) library provides a **ImageNodeVisited** event, which customizes image data while importing a Markdown file. Implement the logic to customize the image data by using this **ImageNodeVisited** event. + +The following code example shows how to load image data based on the image source path when importing the Markdown files. + +{% tabs %} + +{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/XlsIO-Examples/master/Markdown%20to%20Excel/Customize-Image/.NET/Customize-Image/Customize-Image/Program.cs,180" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + + MdImportSettings settings = new MdImportSettings(); + + settings.ImageNodeVisited += MdImportSettings_ImageNodeVisited; + + IWorkbook workbook = application.Workbooks.Open(@"Data/Sample1.md", settings); + + workbook.SaveAs(Path.GetFullPath("Output/MarkdownToExcel.xlsx")); +} +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + + MdImportSettings settings = new MdImportSettings(); + + settings.ImageNodeVisited += MdImportSettings_ImageNodeVisited; + + IWorkbook workbook = application.Workbooks.Open(@"Data/Sample1.md", settings); + + workbook.SaveAs(Path.GetFullPath("Output/MarkdownToExcel.xlsx")); +} +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Using excelEngine As New ExcelEngine() + Dim application As IApplication = excelEngine.Excel + application.DefaultVersion = ExcelVersion.Xlsx + + Dim settings As New MdImportSettings() + AddHandler settings.ImageNodeVisited, AddressOf MdImportSettings_ImageNodeVisited + + Dim workbook As IWorkbook = application.Workbooks.Open("Sample.md", settings) + + workbook.SaveAs("MarkdownToExcel.xlsx") +End Using +{% endhighlight %} + +{% endtabs %} + +The following code examples show the event handler to customize the image based on the source path. + +{% tabs %} + +{% highlight c# tabtitle="C# [Cross-platform]" %} +private static void MdImportSettings_ImageNodeVisited(object sender, MdImageNodeVisitedEventArgs args) +{ + //Set the image stream based on the image name from the input Markdown. + if (args.Uri == "Image_1.png") + args.ImageStream = new FileStream(Path.GetFullPath("Data/Image_1.png"), FileMode.Open); + else if (args.Uri == "Image_2.png") + args.ImageStream = new FileStream(Path.GetFullPath("Data/Image_2.png"), FileMode.Open); + //Retrive the image from the website and use it. + else if (args.Uri.StartsWith("https://")) + { + WebClient client = new WebClient(); + byte[] image = client.DownloadData(args.Uri); + Stream stream = new MemoryStream(image); + args.ImageStream = stream; + } +} +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} +private static void MdImportSettings_ImageNodeVisited(object sender, MdImageNodeVisitedEventArgs args) +{ + //Set the image stream based on the image name from the input Markdown. + if (args.Uri == "Image_1.png") + args.ImageStream = new FileStream(Path.GetFullPath("Data/Image_1.png"), FileMode.Open); + else if (args.Uri == "Image_2.png") + args.ImageStream = new FileStream(Path.GetFullPath("Data/Image_2.png"), FileMode.Open); + //Retrive the image from the website and use it. + else if (args.Uri.StartsWith("https://")) + { + WebClient client = new WebClient(); + byte[] image = client.DownloadData(args.Uri); + Stream stream = new MemoryStream(image); + args.ImageStream = stream; + } +} +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Private Sub MdImportSettings_ImageNodeVisited(sender As Object, args As MdImageNodeVisitedEventArgs) + ' Set the image stream based on the image name from the input Markdown. + If args.Uri = "Image_1.png" Then + args.ImageStream = New FileStream(Path.GetFullPath("D:\UG Branch\1029061-MarkdownExample\Markdown to Excel\Markdown-to-Excel\.NET\Markdown-to-Excel\Markdown-to-Excel\Data\Image_1.png"), FileMode.Open) + ElseIf args.Uri = "Image_2.png" Then + args.ImageStream = New FileStream(Path.GetFullPath("D:\UG Branch\1029061-MarkdownExample\Markdown to Excel\Markdown-to-Excel\.NET\Markdown-to-Excel\Markdown-to-Excel\Data\.png"), FileMode.Open) + ElseIf args.Uri.StartsWith("https://") Then + Dim client As New WebClient() + Dim imageBytes As Byte() = client.DownloadData(args.Uri) + Dim stream As New MemoryStream(imageBytes) + args.ImageStream = stream + End If +End Sub +{% endhighlight %} + +{% endtabs %} + +You can download a complete working sample from this GitHub page. + +N> Hook the event handler before opening Excel document as per the above code example. \ No newline at end of file