翻譯|使用教程|編輯:胡濤|2022-05-16 10:33:27.763|閱讀 212 次
概述:本文將從以下兩個方面演示如何使用Spire.XLS for .NET以編程方式將 Excel 轉(zhuǎn)換為 HTML 。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
當(dāng)您創(chuàng)建 Excel 表格并希望將其作為網(wǎng)頁在線發(fā)布時,最簡單的方法是將其轉(zhuǎn)換為 HTML 文件。本文將從以下兩個方面演示如何使用Spire.XLS for .NET以編程方式將 Excel 轉(zhuǎn)換為 HTML 。
首先,您需要添加 Spire.XLS for .NET 包中包含的 DLL 文件作為 .NET 項目中的引用。DLL 文件可以從此鏈接下載或通過NuGet安裝。
PM> Install-Package Spire.XLS
Spire.XLS for .NET 支持使用Worksheet.SaveToHtml()方法將特定的 Excel 工作表轉(zhuǎn)換為 HTML 。下面列出了詳細(xì)的步驟。
【C#】
using Spire.Xls; namespace XLSToHTML { class Program { static void Main(string[] args) { //Create a Workbook instance Workbook workbook = new Workbook(); //Load an Excel sample document workbook.LoadFromFile(@"sample.xlsx"); //Get the first worksheet of the document Worksheet sheet = workbook.Worksheets[0]; //Save the worksheet to HTML sheet.SaveToHtml("ExcelToHTML.html"); } } }
【VB.NET】
Imports Spire.Xls Namespace Xls2Html Class Program Private Shared Sub Main(args As String()) 'Create a Workbook instance Dim workbook As New Workbook() 'Load an Excel sample document workbook.LoadFromFile("sample.xlsx") 'Get the first worksheet of the document Dim sheet As Worksheet = workbook.Worksheets(0) 'Save the worksheet to HTML sheet.SaveToHtml("XLSToHTML.html") End Sub End Class End Namespace
以下是將 Excel 工作表轉(zhuǎn)換為嵌入圖像的 HTML 的步驟。
【C#】
using Spire.Xls; using Spire.Xls.Core.Spreadsheet; namespace XLSToHTML { class Program { static void Main(string[] args) { //Create a Workbook instance Workbook workbook = new Workbook(); //Load an Excel sample document workbook.LoadFromFile(@"sample.xlsx"); //Get the first worksheet of the document Worksheet sheet = workbook.Worksheets[0]; //Create an HTMLOptions instance HTMLOptions options = new HTMLOptions(); //Embed images to HTML options.ImageEmbedded = true; //Save the worksheet to HTML sheet.SaveToHtml("XLS2HTML.html"); } } }
【VB.NET】
Imports Spire.Xls Imports Spire.Xls.Core.Spreadsheet Namespace Xls2Html Class Program Private Shared Sub Main(args As String()) 'Create a Workbook instance Dim workbook As New Workbook() 'Load an Excel sample document workbook.LoadFromFile("sample.xlsx") 'Get the first worksheet of the document Dim sheet As Worksheet = workbook.Worksheets(0) 'Create an HTMLOptions instance Dim options As New HTMLOptions() 'Embed images to HTML options.ImageEmbedded = True 'Save the worksheet to HTML sheet.SaveToHtml("Xls2HTML.html") End Sub End Class
歡迎下載|體驗更多E-iceblue產(chǎn)品
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn