using IronXL;
// Create new Excel WorkBook document
WorkBook workBook = WorkBook.Create();
// Create a blank WorkSheet
WorkSheet workSheet = workBook.CreateWorkSheet("new_sheet");
// Add data and styles to the new worksheet
workSheet["A1"].Value = "Hello World";
workSheet["A2"].Style.BottomBorder.SetColor("#ff6600");
// Save the excel file as XLS, XLSX, XLSM, CSV, TSV, JSON, XML, HTML
workBook.SaveAs("sample.xls");
workBook.SaveAs("sample.xlsx");
workBook.SaveAs("sample.tsv");
// Save the excel file as CSV
workBook.SaveAsCsv("sample.csv");
// Save the excel file as JSON
workBook.SaveAsJson("sample.json");
// Save the excel file as XML
workBook.SaveAsXml("sample.xml");
// Export the excel file as HTML
workBook.ExportToHtml("sample.html");
Imports IronXL
' Create new Excel WorkBook document
Private workBook As WorkBook = WorkBook.Create()
' Create a blank WorkSheet
Private workSheet As WorkSheet = workBook.CreateWorkSheet("new_sheet")
' Add data and styles to the new worksheet
Private workSheet("A1").Value = "Hello World"
workSheet("A2").Style.BottomBorder.SetColor("#ff6600")
' Save the excel file as XLS, XLSX, XLSM, CSV, TSV, JSON, XML, HTML
workBook.SaveAs("sample.xls")
workBook.SaveAs("sample.xlsx")
workBook.SaveAs("sample.tsv")
' Save the excel file as CSV
workBook.SaveAsCsv("sample.csv")
' Save the excel file as JSON
workBook.SaveAsJson("sample.json")
' Save the excel file as XML
workBook.SaveAsXml("sample.xml")
' Export the excel file as HTML
workBook.ExportToHtml("sample.html")
Install-Package IronXL.Excel
將 Excel 匯出為 CSV、XML、HTML、XLSX
IronXL 庫可以用來從 XLS 和 XLSX 格式創建 Excel 文件。使用 IronXL 直觀的 API 填充您的工作簿,並使用 SaveAs 方法將其保存為 XLS、XLSX、XLSM、CSV、TSV、JSON、XML 或 HTML 格式。使用 IronXL 也可以以程式碼數據類型導出,例如 HTML 字串、二進制、字節數組、數據集和內存流。
雖然 SaveAs 可以用來導出 CSV、JSON、XML 和 HTML 文件,但建議使用每種文件格式的專屬方法:
SaveAsCsv
SaveAsJson
SaveAsXml
ExportToHtml
請注意,對於 CSV、TSV、JSON 和 XML 文件格式,每個文件都會對應創建到每個工作表。命名規則為 fileName.sheetName.format。在上述示例中,導出的 CSV 格式文件將是 sample.new_sheet.csv。