Background
My work is related to financial processing. As you know,
Excel file is very popular and widely used in processing date. Excel enables us
to do mathematical calculation of the data stored inside it. And I use it a lot
in my work. But when presenting the data, Excel is not a good solution for me.
I need other file format to present the data to my users. And Html is the format which I prefer. So I need
some sort of means to convert Excel files to Html. I surfed on the Internet and
found a free library – Spire.XLS that can meet my need. Check it here.
Introduction
Spire.XLS is a .NET component that enables you to create
Excel files, edit existing Excel files and convert Excel files. In a word,
using it you can manipulate Excel files very easily. Let’s create a very simple
Excel file using it.
First, create a Workbook instance. A Workbook instance
represents an Excel file.
Workbook workbook = new Workbook();
Then get the first
Worksheet.
Worksheet sheet =
workbook.Worksheets[0];
Set A1 in the first
Worksheet to “TEST”.
sheet.Range["A1"].Text = "TEST";
At last, save the
document.
workbook.SaveToFile("result.xlsx", FileFormat.Version2010);
It is neat to create
an Excel file using the library. Check the generated file here:
Convert to Html
format
In the last section, I introduce you how to create an Excel
file. In this part, I will introduce you how to convert Excel file to Html.
First, create a Workbook instance. A Workbook instance
represents an Excel file.
Workbook workbook = new Workbook();
Load the sample file.
workbook.LoadFromFile("sample.xlsx");
Then get the first
Worksheet.
Worksheet sheet =
workbook.Worksheets[0];
Convert the first
Worksheet to Html.
sheet.SaveToHtml("result.html");
Screenshot of generated html file:
I hope this article can do you some help. Thanks.
No comments:
Post a Comment