Skip to content

Instantly share code, notes, and snippets.

@b2977053
Last active October 25, 2019 07:04
Show Gist options
  • Save b2977053/b8f95a0367bdc552b5e0a645d29065a2 to your computer and use it in GitHub Desktop.
Save b2977053/b8f95a0367bdc552b5e0a645d29065a2 to your computer and use it in GitHub Desktop.
比較三個 Excel轉ODS檔案 or HTML轉Excel檔案
string Content = getContent("http://localhost/xxx");
byte[] byteArray = Encoding.UTF8.GetBytes(Content);
MemoryStream stream = new MemoryStream(byteArray);
#region Spire.Xls 不支援讀取HTML
//https://www.e-iceblue.com/forum/html-to-excel-xls-t7246.html
//Spire.Xls.Workbook Spire_book = new Spire.Xls.Workbook();
//Spire_book.LoadFromStream(stream, Spire.Xls.ExcelVersion.ODS); // System.InvalidOperationException: 'This is not a structured storage file.'
//Spire_book.SaveToFile("test0.ods", Spire.Xls.ExcelVersion.ODS);
//Spire_book.SaveToFile("test0.xlsx", Spire.Xls.ExcelVersion.Version2010);
#endregion
#region GemBox.Spreadsheet 吃不到欄位寬度
SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");
ExcelFile workbook = ExcelFile.Load(stream, GemBox.Spreadsheet.LoadOptions.HtmlDefault);
workbook.Save("test1.ods", GemBox.Spreadsheet.SaveOptions.OdsDefault); // Save to ODS file.
workbook.Save("test1.xlsx"); // Save to XLSX file.
#endregion
#region Aspose.Cells
Aspose.Cells.LoadOptions loadOptions = new Aspose.Cells.LoadOptions(LoadFormat.Html);
loadOptions.LoadFilter = new LoadFilter(LoadDataFilterOptions.CellData);
Workbook book = new Workbook((Stream)stream, loadOptions);
book.Save("test2.ods", SaveFormat.ODS);
book.Save("test2.xlsx");
#endregion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment