.NET (1322)
Children categories
This article demonstrates how to add hyperlinks to SmartArt Nodes in a PowerPoint document in C# and VB.NET using Spire.Presentation for .NET.
using Spire.Presentation;
using Spire.Presentation.Diagrams;
namespace SmartArt
{
class Program
{
static void Main(string[] args)
{
//Create a Presentation instance
Presentation ppt = new Presentation();
//Load the PowerPoint document
ppt.LoadFromFile("SmartArt.pptx");
//Get the first slide
ISlide slide = ppt.Slides[0];
//Get the SmartArt
ISmartArt smartArt = slide.Shapes[0] as ISmartArt;
//Add hyperlink to the first node of the SmartArt to link to a web page
smartArt.Nodes[0].Click = new ClickHyperlink("https://www.e-iceblue.com");
//Add hyperlink to the first node of the SmartArt to link to a specific slide
smartArt.Nodes[1].Click = new ClickHyperlink(ppt.Slides[1]);
//Save the result document
ppt.SaveToFile("Result.pptx", FileFormat.Pptx2013);
}
}
}
Imports Spire.Presentation
Imports Spire.Presentation.Diagrams
Namespace SmartArt
Class Program
Private Shared Sub Main(ByVal args As String())
Dim ppt As Presentation = New Presentation()
ppt.LoadFromFile("SmartArt.pptx")
Dim slide As ISlide = ppt.Slides(0)
Dim smartArt As ISmartArt = TryCast(slide.Shapes(0), ISmartArt)
smartArt.Nodes(0).Click = New ClickHyperlink("https://www.e-iceblue.com")
smartArt.Nodes(1).Click = New ClickHyperlink(ppt.Slides(1))
ppt.SaveToFile("Result.pptx", FileFormat.Pptx2013)
End Sub
End Class
End Namespace
Output:

This article demonstrates how to ungroup grouped shapes in a PowerPoint document using Spire.Presentation for .NET.
The input PowerPoint document:

using Spire.Presentation;
namespace UngroupShapes
{
class Program
{
static void Main(string[] args)
{
//Create a Presentation instance
Presentation ppt = new Presentation();
//Load the PowerPoint document
ppt.LoadFromFile("Sample.pptx");
//Get the first slide
ISlide slide = ppt.Slides[0];
//Loop through the shapes in the slide
for(int i = 0; i< slide.Shapes.Count;i++)
{
IShape shape = slide.Shapes[i];
//Detect if the shape is a grouped shape
if (shape is GroupShape)
{
GroupShape groupShape = shape as GroupShape;
//Ungroup the grouped shape
slide.Ungroup(groupShape);
}
}
//Save the resultant document
ppt.SaveToFile("UngroupShapes.pptx", FileFormat.Pptx2013);
}
}
}
Imports Spire.Presentation
Namespace UngroupShapes
Class Program
Private Shared Sub Main(ByVal args As String())
Dim ppt As Presentation = New Presentation()
ppt.LoadFromFile("Sample.pptx")
Dim slide As ISlide = ppt.Slides(0)
For i As Integer = 0 To slide.Shapes.Count - 1
Dim shape As IShape = slide.Shapes(i)
If TypeOf shape Is GroupShape Then
Dim groupShape As GroupShape = TryCast(shape, GroupShape)
slide.Ungroup(groupShape)
End If
Next
ppt.SaveToFile("UngroupShapes.pptx", FileFormat.Pptx2013)
End Sub
End Class
End Namespace
The output PowerPoint document after ungrouping shapes:

This article demonstrates how to remove a specific section or all the sections but keep the slide(s) in the section(s) in PowerPoint by using Spire.Presentation for .NET.
Below is the screenshot of the input PowerPoint document which contains two sections:

//Create a Presentation instance
Presentation ppt = new Presentation();
//Load a PowerPoint document
ppt.LoadFromFile("AddSection.pptx");
//Remove the second section
ppt.SectionList.RemoveAt(1);
//Remove all the sections
//ppt.SectionList.RemoveAll();
//Save the result document
ppt.SaveToFile("RemoveSection.pptx", FileFormat.Pptx2013);
'Create a Presentation instance
Dim ppt As Presentation = New Presentation
'Load a PowerPoint document
ppt.LoadFromFile("AddSection.pptx")
'Remove the second section
ppt.SectionList.RemoveAt(1)
'Remove all the sections
'ppt.SectionList.RemoveAll()
'Save the result document
ppt.SaveToFile("RemoveSection.pptx", FileFormat.Pptx2013)
The output PowerPoint document after removing the second section:

We have demonstrated how to use Spire.XLS for .NET to hide/show Excel worksheets. From Spire.XLS v 10.9.0, it starts to support hide the current window of Excel workbook by setting the property of workbook.IsHideWindow.
using Spire.Xls;
namespace HideWindow
{
class Program
{
static void Main(string[] args)
{
//Load Sample Document
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
//Hide Excel Window
workbook.IsHideWindow = true;
//Save the document to file
workbook.SaveToFile("result.xlsx", ExcelVersion.Version2013);
}
}
}
Imports Spire.Xls
Namespace HideWindow
Class Program
Private Shared Sub Main(ByVal args() As String)
'Load Sample Document
Dim workbook As Workbook = New Workbook
workbook.LoadFromFile("Sample.xlsx")
'Hide Excel Window
workbook.IsHideWindow = true
'Save the document to file
workbook.SaveToFile("result.xlsx", ExcelVersion.Version2013)
End Sub
End Class
End Namespace

Sections in PowerPoint is a feature that allows you to organize slides into different groups/segments for easy management. Adding sections with unique names can help keep track of specific groups of slides, or can also help outline the topics of a PowerPoint presentation. In this article, you will learn how to programmatically add or remove sections in a PowerPoint document using Spire.Presentation for .NET.
- Add a Section at the End of a PowerPoint Document in C# and VB.NET
- Insert a Section Before a Specified Section in PowerPoint in C# and VB.NET
- Add a Section Before a Specified Slide in PowerPoint in C# and VB.NET
- Remove a Section from a PowerPoint Document in C# and VB.NET
Install Spire.Presentation for .NET
To begin with, you need to add the DLL files included in the Spire.Presentation for.NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.Presentation
Add a Section at the End of a PowerPoint Document in C# and VB.NET
Spire.Presentation for .NET provides the Presentation.SectionList.Append(string sectionName) method to append a section with section name at the end of a PowerPoint document. The detailed steps are as follows.
- Initialize an instance of Presentation class.
- Load a PowerPoint document using Presentation.LoadFromFile() method.
- Append a section at the end of the document using Presentation.SectionList.Append(string sectionName) method.
- Save the result document using Presentation.SaveToFile() method.
- C#
- VB.NET
using Spire.Presentation;
namespace AppendSectionAtEnd
{
class Program
{
static void Main(string[] args)
{
//Create a Presentation instance
Presentation ppt = new Presentation();
//Load a sample PowerPoint document
ppt.LoadFromFile("Test.pptx");
//Add a section at the end of the document
Section section = ppt.SectionList.Append("End Section");
//Save the result document
ppt.SaveToFile("AddSectionAtEnd.pptx", FileFormat.Pptx2013);
}
}
}

Insert a Section Before a Specified Section in PowerPoint in C# and VB.NET
If you want to insert a section before an existing section to make the document more logical, Spire.Presentation for .NET provides the Presentation.SectionList.Insert(int sectionIndex, string sectionName) method. The following are the steps to insert a section at a specified position by section index.
- Initialize an instance of Presentation class.
- Load a PowerPoint document using Presentation.LoadFromFile() method.
- Insert a new section before the specified section using Presentation.SectionList.Insert(int sectionIndex, string sectionName) method.
- Save the result document using Presentation.SaveToFile() method.
- C#
- VB.NET
using Spire.Presentation;
namespace InsertSectionAtSpecifiedPosition
{
class Program
{
static void Main(string[] args)
{
//Create a Presentation instance
Presentation ppt = new Presentation();
//Load a sample PowerPoint document
ppt.LoadFromFile("Test.pptx");
//Insert a section before the second section
Section section = ppt.SectionList.Insert(1, "New Section");
//Save the result document
ppt.SaveToFile("InsertSectionAtSpecifiedPosition.pptx", FileFormat.Pptx2013);
}
}
}

Add a Section Before a Specified Slide in PowerPoint in C# and VB.NET
To divided the existing PowerPoint slides into different sections, you can use the Presentation.SectionList.Add(string sectionName, ISlide slide) method to insert a section before a specified slide. The detailed steps are as follows.
- Initialize an instance of Presentation class.
- Load a PowerPoint document using Presentation.LoadFromFile() method.
- Get a specified slide using Presentation.Slides property.
- Add a section before the specified slide using Presentation.SectionList.Add(string sectionName, ISlide slide) method.
- Save the result document using Presentation.SaveToFile() method.
- C#
- VB.NET
using Spire.Presentation;
namespace AddSectionBeforeSlide
{
class Program
{
static void Main(string[] args)
{
//Create a Presentation instance
Presentation ppt = new Presentation();
//Load a sample PowerPoint document
ppt.LoadFromFile("Test.pptx");
//Get the second slide in the document
ISlide slide = ppt.Slides[1];
//Add a section before the second slide
Section section = ppt.SectionList.Add("New Section", slide);
//Save the result document
ppt.SaveToFile("AddSectionBeforeSlide.pptx", FileFormat.Pptx2013);
}
}
}

Remove a Section from a PowerPoint Document in C# and VB.NET
If you do not need a particular section, you can simply remove it using Presentation.SectionList.RemoveAt(int index) method. Note that removing a section does not remove the slides in that section. The following are the steps to remove a specified section but keep the slides in it.
- Initialize an instance of Presentation class.
- Load a PowerPoint document using Presentation.LoadFromFile() method.
- Remove a specified section using Presentation.SectionList.RemoveAt(int index) method. Or you can remove all the sections in the document using Presentation.SectionList.RemoveAll() method.
- Save the result document using Presentation.SaveToFile() method.
- C#
- VB.NET
using Spire.Presentation;
namespace RemoveSection
{
class Program
{
static void Main(string[] args)
{
//Create a Presentation instance
Presentation ppt = new Presentation();
//Load a sample PowerPoint document
ppt.LoadFromFile("Test.pptx");
//Remove the second section
ppt.SectionList.RemoveAt(1);
//Remove all the sections
//ppt.SectionList.RemoveAll();
//Save the result document
ppt.SaveToFile("RemoveSection.pptx", FileFormat.Pptx2013);
}
}
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
It is not uncommon at work that we may receive two versions of a Word document and face the need to find the differences between them. Document comparison is particularly important and popular in the fields of laws, regulations and education. In this article, you will learn how to compare two Word documents in C# and VB.NET by using Spire.Doc for .NET.
- Compare Two Documents and Save Result in a Third Word Document
- Compare Two Documents and Return Insertions and Deletions in Lists
Below is a screenshot of the two Word documents that’ll be compared.

Install Spire.Doc for .NET
To begin with, you need to add the DLL files included in the Spire.Doc for .NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.Doc
Compare Two Documents and Save Result in a Third Word Document
Saving the comparison result in a separate Word document allows us to see all the changes made to the original document, including insertions, deletions as well as modifications on formatting. The following are the steps to compare two documents and save the result in a third Word document using Spire.Doc for .NET.
- Load two Word documents separately while initialing the Document objects.
- Compare these two documents using Document.Compare() method.
- Save the result in a third Word document using ;Document.SaveToFile() method.
- C#
- VB.NET
using Spire.Doc;
namespace CompareDocuments
{
class Program
{
static void Main(string[] args)
{
//Load one Word document
Document doc1 = new Document("C:\\Users\\Administrator\\Desktop\\original.docx");
//Load the other Word document
Document doc2 = new Document("C:\\Users\\Administrator\\Desktop\\revised.docx");
//Compare two documents
doc1.Compare(doc2, "John");
//Save the differences in a third document
doc1.SaveToFile("Differences.docx", FileFormat.Docx2013);
doc1.Dispose();
}
}
}

Compare Two Documents and Return Insertions and Deletions in Lists
Developers may only want to obtain the insertions and deletions instead of the whole differences. The following are the steps to get insertions and deletions in two separate lists.
- Load two Word documents separately while initialing the Document objects.
- Compare two documents using Document.Compare() method.
- Get the revisions using the constructor function of the DifferRevisions ;class.
- Get a list of insertions through DifferRevisions.InsertRevisions property.
- Get a list of deletions through DifferRevisions.DeleteRevisions property.
- Loop through the elements in the two lists to get the specific insertion and deletion.
- C#
- VB.NET
using Spire.Doc;
using Spire.Doc.Fields;
using System;
namespace GetDifferencesInList
{
class Program
{
static void Main(string[] args)
{
//Load one Word document
Document doc1 = new Document("C:\\Users\\Administrator\\Desktop\\original.docx");
//Load the other Word document
Document doc2 = new Document("C:\\Users\\Administrator\\Desktop\\revised.docx");
//Compare the two Word documents
doc1.Compare(doc2, "Author");
//Get the revisions
DifferRevisions differRevisions = new DifferRevisions(doc1);
//Return the insertion revisions in a list
var insetRevisionsList = differRevisions.InsertRevisions;
//Return the deletion revisions in a list
var deletRevisionsList = differRevisions.DeleteRevisions;
//Create two int variables
int m = 0;
int n = 0;
//Loop through the insertion revision list
for (int i = 0; i < insetRevisionsList.Count; i++)
{
if (insetRevisionsList[i] is TextRange)
{
m += 1;
//Get the specific revision and get its content
TextRange textRange = insetRevisionsList[i] as TextRange;
Console.WriteLine("Insertion #" + m + ":" + textRange.Text);
}
}
Console.WriteLine("=====================");
//Loop through the deletion revision list
for (int i = 0; i < deletRevisionsList.Count; i++)
{
if (deletRevisionsList[i] is TextRange)
{
n += 1;
//Get the specific revision and get its content
TextRange textRange = deletRevisionsList[i] as TextRange;
Console.WriteLine("Deletion #" + n + ":" + textRange.Text);
}
}
Console.ReadKey();
}
}
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
PDF is a versatile file format, but it is difficult to edit. If you want to modify and calculate PDF data, converting PDF to Excel would be an ideal solution. In this article, you will learn how to convert PDF to Excel in C# and VB.NET using Spire.PDF for .NET.
Install Spire.PDF for .NET
To begin with, you need to add the DLL files included in the Spire.PDF for.NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.PDF
Convert PDF to Excel in C# and VB.NET
The following are the steps to convert a PDF document to Excel:
- Initialize an instance of PdfDocument class.
- Load the PDF document using PdfDocument.LoadFromFile(filePath) method.
- Save the document to Excel using PdfDocument.SaveToFile(filePath, FileFormat.XLSX) method.
- C#
- VB.NET
using Spire.Pdf;
using Spire.Pdf.Conversion;
namespace ConvertPdfToExcel
{
class Program
{
static void Main(string[] args)
{
//Initialize an instance of PdfDocument class
PdfDocument pdf = new PdfDocument();
//Load the PDF document
pdf.LoadFromFile("Sample.pdf");
//Save the PDF document to XLSX
pdf.SaveToFile("PdfToExcel.xlsx", FileFormat.XLSX);
}
}
}

Convert a Multi-Page PDF to One Excel Worksheet in C# and VB.NET
The following are the steps to covert a multi-page PDF to one Excel worksheet:
- Initialize an instance of PdfDocument class.
- Load the PDF document using PdfDocument.LoadFromFile(filePath) method.
- Initialize an instance of XlsxLineLayoutOptions class, in the class constructor, setting the first parameter - convertToMultipleSheet as false.
- Set PDF to XLSX convert options using PdfDocument.ConvertOptions.SetPdfToXlsxOptions(XlsxLineLayoutOptions) method.
- Save the document to Excel using PdfDocument.SaveToFile(filePath, FileFormat.XLSX) method.
- C#
- VB.NET
using Spire.Pdf;
using Spire.Pdf.Conversion;
namespace ConvertPdfToExcel
{
class Program
{
static void Main(string[] args)
{
//Initialize an instance of PdfDocument class
PdfDocument pdf = new PdfDocument();
//Load the PDF document
pdf.LoadFromFile("Sample1.pdf");
//Initialize an instance of XlsxLineLayoutOptions class, in the class constructor, setting the first parameter - convertToMultipleSheet as false.
//The four parameters represent: convertToMultipleSheet, showRotatedText, splitCell, wrapText
XlsxLineLayoutOptions options = new XlsxLineLayoutOptions(false, true, true, true);
//Set PDF to XLSX convert options
pdf.ConvertOptions.SetPdfToXlsxOptions(options);
//Save the PDF document to XLSX
pdf.SaveToFile("PdfToOneExcelSheet.xlsx", FileFormat.XLSX);
}
}
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
SVG is a file format for vector graphics, used to create images that can be scaled without loss of quality. However, PDF is more suitable for sharing and printing due to its support for high-quality printing, encryption, digital signatures, and other features. Converting SVG to PDF ensures good image display on different devices and environments, and better protects intellectual property. In this tutorial, we will show you how to convert SVG to PDF and how to add a SVG image to PDF in C# and VB.NET using Spire.PDF for .NET.
Install Spire.PDF for .NET
To begin with, you need to add the DLL files included in the Spire.PDF for .NET package as references in your .NET project. The DLLs files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.PDF
Convert SVG to PDF in C# and VB.NET
Spire.PDF for .NET provides the PdfDocument.SaveToFile(String, FileFormat) method, which allows users to save an SVG file as a PDF. The detailed steps are as follows.
- Create a PdfDocument object.
- Load a sample SVG file using PdfDocument.LoadFromFile() method.
- Convert the SVG file to PDF using PdfDocument.SaveToFile(String, FileFormat) method.
- C#
- VB.NET
using Spire.Pdf;
namespace SVGtoPDF
{
class Program
{
static void Main(string[] args)
{
//Create a PdfDocument object
PdfDocument doc = new PdfDocument();
//Load a sample SVG file
doc.LoadFromSvg("Sample.svg");
//Save result document
doc.SaveToFile("Result.pdf", FileFormat.PDF);
doc.Dispose();
}
}
}

Add SVG image to PDF in C# and VB.NET
In addition to converting SVG to PDF directly, it also supports adding SVG image files to the specified locations in PDF. Please check the steps as below:
- Create a PdfDocument object and load an SVG file using PdfDocument. LoadFromSvg() method.
- Create a template based on the content of the SVG file using PdfDocument. Pages[].CreateTemplate() method.
- Get the width and height of the template on the page.
- Create another PdfDocument object and load a PDF file using PdfDocument.LoadFromFile() method.
- Draw the template with a custom size at a specified location using PdfDocument.Pages[].Canvas.DrawTemplate() method.
- Save to PDF file using PdfDocument.SaveToFile(String, FileFormat) method.
- C#
- VB.NET
using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;
namespace AddSVGImagetoPDF
{
class Program
{
static void Main(string[] args)
{
//Create a PdfDocument object
PdfDocument doc1 = new PdfDocument();
//Load an SVG file
doc1.LoadFromSvg("C:\\Users\\Administrator\\Desktop\\sample.svg");
//Create a template based on the content of the SVG file
PdfTemplate template = doc1.Pages[0].CreateTemplate();
//Get the width and height of the template
float width = template.Width;
float height = template.Height;
//Create another PdfDocument object
PdfDocument doc2 = new PdfDocument();
//Load a PDF file
doc2.LoadFromFile("C:\\Users\\Administrator\\Desktop\\sample.pdf");
//Draw the template with a custom size at a specified location
doc2.Pages[0].Canvas.DrawTemplate(template, new PointF(0, 0), new SizeF(width * 0.8f, height * 0.8f));
//Save to PDF file
doc2.SaveToFile("AddSvgToPdf.pdf", FileFormat.PDF);
doc2.Dispose();
}
}
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
A PDF portfolio is a collection of files that can contain text documents, spreadsheets, emails, images, PowerPoint presentations and drawings. Although a PDF portfolio assembles different types of files into a single unit, each of the files in it retains their original formatting, resolutions and sizes. In this article, you will learn how to programmatically create a PDF portfolio using Spire.PDF for .NET.
Install Spire.PDF for .NET
To begin with, you need to add the DLL files included in the Spire.PDF for.NET package as references in your .NET project. The DLLs files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.PDF
Create a PDF Portfolio and Add Files to It
As a PDF portfolio is a collection of files, Spire.PDF for .NET allows you to create it easily using PdfDocument.Collection property. Then you can add files to the PDF portfolio using PdfCollection.AddFile() method. The detailed steps are as follows:
- Specify the files that need to be added to the PDF portfolio.
- Create PdfDocument instance.
- Create a PDF portfolio and add files to it using PdfDocument.Collection.AddFile() method.
- Save the result file using PdfDocument.SaveToFile() method.
- C#
- VB.NET
using System;
using Spire.Pdf;
namespace CreatePDFPortfolio
{
class Program
{
static void Main(string[] args)
{
// Specify the files
String[] files = new String[] { "input.pdf", "sample.docx", "report.xlsx", "Intro.pptx", "logo.png" };
//Create a PdfDocument instance
using (PdfDocument pdf = new PdfDocument())
{
//Create a PDF portfolio and add files to it
for (int i = 0; i < files.Length; i++)
{
pdf.Collection.AddFile(files[i]);
}
//Save the result file
pdf.SaveToFile("PortfolioWithFiles.pdf", FileFormat.PDF);
pdf.Dispose();
}
}
}
}

Create a PDF Portfolio and Add Folders to It
After creating a PDF portfolio, Spire.PDF for .NET also allows you to create folders within the PDF portfolio to further manage the files. The detailed steps are as follows:
- Specify the files that need to be added to the PDF portfolio.
- Create PdfDocument instance.
- Create a PDF Portfolio using PdfDocument.Collection property.
- Add folders to the PDF portfolio using PdfCollection.Folders.CreateSubfolder() method, and then add files to the folders using PdfFolder.AddFile() method.
- Save the result file using PdfDocument.SaveToFile() method.
- C#
- VB.NET
using System;
using Spire.Pdf;
using Spire.Pdf.Collections;
namespace CreatePDFPortfolio
{
class Program
{
static void Main(string[] args)
{
// Specify the files
String[] files = new String[] { "input.pdf", "sample.docx", "report.xlsx", "Intro.pptx", "logo.png" };
//Create a PdfDocument instance
using (PdfDocument pdf = new PdfDocument())
{
//Create a PDF portfolio and add folders to it
for (int i = 0; i < files.Length; i++)
{
PdfFolder folder = pdf.Collection.Folders.CreateSubfolder("Folder" + i);
//Add files to the folders
folder.AddFile(files[i]);
}
//Save the result file
pdf.SaveToFile("PortfolioWithFolders.pdf", FileFormat.PDF);
pdf.Dispose();
}
}
}
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
HTML (HyperText Markup Language) is primarily used for structuring content on web pages. While it excels at presenting information visually on the web, it lacks the robust analytical capabilities and data manipulation features found in spreadsheet software like Excel. By converting HTML data to Excel, users can leverage Excel's advanced functionalities like formulas, charts, tables, and macros to organize and analyze data efficiently. In this article, we will explain how to convert HTML to Excel in C# using Spire.XLS for .NET.
Install Spire.XLS for .NET
To begin with, you need to add the DLL files included in the Spire.XLS for .NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.XLS
Convert HTML to Excel in C#
Spire.XLS for .NET offers the Workbook.LoadFromHtml() method to load an HTML file. After loading the HTML file, you can easily save it in Excel format using the Workbook.SaveToFile() method. The detailed steps are as follows.
- Create an object of the Workbook class.
- Load an HTML file using the Workbook.LoadFromHtml() method.
- Save the HTML file in Excel format using the Workbook.SaveToFile() method.
- C#
using Spire.Xls;
namespace ConvertHtmlToExcel
{
internal class Program
{
static void Main(string[] args)
{
// Specify the input HTML file path
string filePath = @"C:\Users\Administrator\Desktop\Sample.html";
// Create an object of the workbook class
Workbook workbook = new Workbook();
// Load the HTML file
workbook.LoadFromHtml(filePath);
// Save the HTML file in Excel XLSX format
string result = @"C:\Users\Administrator\Desktop\ToExcel.xlsx";
workbook.SaveToFile(result, ExcelVersion.Version2013);
workbook.Dispose();
}
}
}

Insert HTML String to Excel in C#
In addition to converting HTML files to Excel, Spire.XLS for .NET also allows you to insert HTML strings into Excel cells by using the CellRange.HtmlString property. The detailed steps are as follows.
- Create an object of the Workbook class.
- Get a specific worksheet by its index (0-based) using the Workbook.Worksheets[index] property.
- Get the cell that you want to add an HTML string to using the Worksheet.Range[] property.
- Add an HTML sting to the cell using the CellRange.HtmlString property.
- Save the resulting workbook to a new file using the Workbook.SaveToFile() method.
- C#
using Spire.Xls;
namespace InsertHtmlStringInExcel
{
internal class Program
{
static void Main(string[] args)
{
// Create an object of the workbook class
Workbook workbook = new Workbook();
// Get the first sheet
Worksheet sheet = workbook.Worksheets[0];
// Specify the HTML string
string htmlCode = "<p><font size='12'>This is a <b>paragraph</b> with <span style='color: red;'>colored text</span>.</font></p>";
// Get the cell that you want to add the HTML string to
CellRange range = sheet.Range["A1"];
// Add the HTML string to the cell
range.HtmlString = htmlCode;
// Auto-adjust the width of the first column based on its content
sheet.AutoFitColumn(1);
// Save the resulting workbook to a new file
string result = @"C:\Users\Administrator\Desktop\InsertHtmlStringIntoCell.xlsx";
workbook.SaveToFile(result, ExcelVersion.Version2013);
workbook.Dispose();
}
}
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.