2020-04-09、2020-04-17、2020-04-28、2021-02-18、2023-01-15 更新
| 微軟官方並不建議在伺服器端使用直接存取 Excel 物件模型的方式來控制 Excel 檔案,除了上述的資源無法釋放的問題外,還有像是權限的問題,以及安全性問題等等,詳細的資料請參考: Considerations for server-side Automation of Office - Microsoft Support http://support.microsoft.com/default.aspx/kb/257757 |
https://support.microsoft.com/zh-tw/help/257757/considerations-for-server-side-automation-of-office
Considerations for server-side Automation of Office
https://support.microsoft.com/fi-fi/help/257757/considerations-for-server-side-automation-of-office
********************************************************************************
匯出、寫入Excel (.xlsx)
注意元件更新狀況,多年未更新或停止研發的建議別用。
[研究][C#][ASP.NET][WebForm] 用 ClosedXML 0.95.0 把 GridView1 匯出成 Excel (.xlsx)
https://shaurong.blogspot.com/2020/04/caspnetwebform-closedxml-0950-gridview1.html
ClosedXML 需要 Microsoft OpenXML SDK ( NuGet 上稱為 DocumentFormat.OpenXml )
[研究][C#][ASP.NET][WebForm] 使用 Microsoft OpenXML 2.10.1 (DocumentFormat.OpenXml) 把 GridView 匯出成 .xlsx
https://shaurong.blogspot.com/2020/04/caspnetwebform-openxml-2101.html
[研究][C#][ASP.NET] GridView 匯出成 Excel (.xlsx) (使用 Microsoft OpenXML SDK 2.5)
http://shaurong.blogspot.tw/2016/03/caspnet-gridview-excel-xlsx-openxml-sdk.html
[研究] [C#] 用 ClosedXML 在 Server端操作 Excel,安裝與試用 (NuGet安裝)
http://shaurong.blogspot.com/2017/11/c-closedxml-server-excel-nuget.html
EPPLus 待測
https://www.nuget.org/packages/EPPlus/
目前最新為 2020-04-07 的 v5.1.0 版
From version 5 EPPlus changes the licence model using a dual license, Polyform Non Commercial / Commercial license.
SpreadSheetLight 待測
https://www.nuget.org/packages/SpreadsheetLight/
http://spreadsheetlight.com/
目前最新 2020年11月的 3.5.0 版 ( 目前2021/02/09 )
需要 OpenXMLSDK 2.5
ExcelPackage 1.0.0
public static void WriteToExcel(string[] newInfoArray)
{
FileInfo fileInfo = new FileInfo(pathName);
using (ExcelPackage packge = new ExcelPackage(fileInfo))
{
ExcelWorksheet worksheet = packge.Workbook.Worksheets[sheetName];
for (int i = 0; i < newInfoArray.Length; ++i)
{
worksheet.Cells[selectIndex + 2, i + 1].Value = newInfoArray[i];
}
packge.Save();
}
}
********************************************************************************
Excel (.xlsx) 匯出、匯入 注意事項
目前拿來匯入的 .xlsx 檔案,若為直接用 Microsoft Excel 建立的,不會有問題。用任何元件匯出產生的 .xlsx,不保證匯入成功;就算此時再拿 Microsoft Excel 另存過一次也不保證匯入成功。
而用任何元件產生的 .xlsx 檔案,用 Microsoft Excel 開啟,也不保證 100% 成功。
有可能是元件本身相容性問題 or Bug or 程式寫法問題。
[研究][C#][ASP.NET][WebForm] ClosedXML 匯入錯誤:參數名稱: The range 工作表1!A1:L2 is already part of table 'Table1'
https://shaurong.blogspot.com/2020/04/closedxml-range-1a1l2-is-already-part.html
********************************************************************************
匯入、讀取Excel (.xlsx)
[研究][ASP.NET]使用 OpenXML SDK 2.12.1 讀取匯入 .xlsx 到資料庫
[研究][ASP.NET] 用 ExcelDataReader 讀取匯入 .xlsx , .xls , csv 檔案到 GridView1
https://shaurong.blogspot.com/2020/04/caspnetwebform-exceldatareader-xlsx-xls.html
Web Server 不需安裝 Office,目前最新為 2019/5/2 的 v3.6.0,支援 .csv, .xls, .xlsx 讀取,不支援寫入
[研究] [C#] [WinForm] 取得 Excel 的所有 工作表 名稱,及儲存格內容 (使用Access Database Engine 2010)
http://shaurong.blogspot.tw/2016/11/c-winform-excel.html
[研究] Excel 2016 (.xlsx) 匯入 SQL Server 2019
https://shaurong.blogspot.com/2019/12/excel-2016-xlsx-sql-server-2019.html
********************************************************************************
匯出 Excel (.xls)
[研究][C#][ASP.NET][WebForm] 使用 Microsoft OpenXML SDK 2.10.1 ( DocumentFormat.OpenXml ) 把 Excel .xlsx 匯入
https://shaurong.blogspot.com/2020/04/caspnetwebform-microsoft-openxml-sdk.html
[研究][C#][ASP.NET] GridView 匯出成 .xls (使用 Excel)
http://shaurong.blogspot.tw/2016/03/caspnet-gridview-xls-excel.html
電腦要安裝 Office 軟體
[研究][ASP.NET][C#]使用 NPOI 的 RenderDataTableToExcel 匯出資料成 Excel (.xls) 檔案
待測
Server電腦要不安裝 Office 軟體,NOPI 支援 xls, xlsx, docx.
[研究][C#][ASP.NET] 用 NPOI v2.2.1 在 Server 端存取 Excel 檔案 (從官方下載安裝)
http://shaurong.blogspot.com/2017/11/caspnet-npoi-v221-server-excel.html
NOPI 支援 xls, xlsx, docx.
[研究][C#][ASP.NET] 用 NPOI v2.3.0 在 Server 端存取 Excel 檔案 (NuGet安裝)
http://shaurong.blogspot.com/2017/11/caspnet-npoi-server-excel-nuget.html
[研究][C#][ASP.NET] GridView 匯出成 Excel (.xls)(以Html方式輸出)
http://shaurong.blogspot.tw/2016/03/caspnet-gridview-excel-xlshtml.html
EPPlus
https://github.com/JanKallman/EPPlus
EPPlus will from version 5 switch license from LGPL to Polyform Noncommercial 1.0.0 license.
With the new license EPPlus is still free to use in some cases, but will require a commercial license to be used in a commercial business.
EPPlus is a .NET library that reads and writes Excel files using the Office Open XML format (xlsx). EPPlus has no dependencies other than .NET.
EPPlus 待測
********************************************************************************
匯入 Excel (.xls)
待測
********************************************************************************
開放文件格式 (Open Document Format, ODF)
開放文檔格式 - 維基百科,自由的百科全書
https://zh.wikipedia.org/wiki/%E5%BC%80%E6%94%BE%E6%96%87%E6%A1%A3%E6%A0%BC%E5%BC%8F
ODF 中相對 MS-Excel 的試算表檔案為 .ods (OpenDocument Spreadsheet)
Office 2010 只支援到 ODF 1.1 版,Excel 2010 開啟 LibreOffice Calc 試算表 .ods 內容會失敗,Office 2013 和 2016 才支援目前最新的 ODF 1.2版
- OpenOffice.org 1.0 (May 2002) ~ 1.1.5 (Sep 2005)
- OpenOffice.org 2.0 (Oct 2005) 支援 ODF ~ 2.4.3 (Sep 2009)
- OpenOffice.org 3.0 (Oct 2008) ~ 3.3.0 (Jan 2011)
- Apache OpenOffice 4.0 (Apr 2011)
- LibreOffice 3.3.0 (January 25, 2011) 支援 ODF
- LibreOffice 4.0 (February 2013)
- LibreOffice 5.0 (August 2015)
- LibreOffice 6.0 (31 January 2018) 支援 ODF 1.2
- LibreOffice 7.0 (5 August 2020) 支援 ODF 1.3
- 3.4.0 2012-05-08,支援ODF
- 3.4.1 2012-08-23
- 4.0.0 2013-07-23,支援ODF 1.2
- 4.0.1 2013-10-01
- 4.1.0 2014-04-29
- 4.1.1 2014-08-21
- 4.1.2 2015-10-28
- 4.1.3 2016-10-12
- 4.1.4 2017-10-19
- 4.1.5 2017-12-30
- 4.1.6 2018-11-18
- 4.1.7 2019-09-21
- 4.1.9 2021-02-07,支援ODF 1.3
- 4.1.10 2021-05-04
- 4.1.11 2021-10-06
LibreOffice_6.3.5_Win_x64_sdk.msi
https://zh-tw.libreoffice.org/download/libreoffice-still/
OpenOffice 4.1.7 SDK
https://openoffice.apache.org/downloads.html
微軟 Office 軟體對 ODF 的支援 FAQ
https://docs.microsoft.com/zh-tw/archive/blogs/officetw/office-odf-faq
[研究] C# .NET 存取 OpenOffice Calc 試算表 .ods 套件評估
http://shaurong.blogspot.com/2016/12/c-net-openoffice-calc-ods.html
匯出、寫入ODF/.ODS
目前免費最佳做法是安裝 Java JRE + LibreOffice + LibreOffice SDK,沒有免費好用元件,或付費買元件用。
https://shaurong.blogspot.com/2020/04/caspnet-gridview-excel-odf-ods-html.html
[研究] [C#] 使用 LibreOffice 6.2.6 SDK、OpenOffice 4.1.6 SDK讀取/寫入試算表(Calc) 檔案 (.ods)
https://shaurong.blogspot.com/2019/08/c-libreoffice-626-sdk-calc-ods.html
Libre Office 或 Apache Open Office 當 .ods 的讀寫軟體就算了,它的 SDK 感覺不太穩;且
NuGet 排名前面的是付費元件 (可能有免費天數限制或功能限制的版本)
https://www.nuget.org/packages?q=ODS
匯入、讀取ODF/.ODS
目前免費最佳做法可能是安裝 Java JRE + LibreOffice + LibreOffice SDK,或使用使用 .NET 4.5 的 ZipFile,沒有免費好用元件,或付費買元件用。
[研究] [C#] 使用 LibreOffice 6.2.6 SDK、OpenOffice 4.1.6 SDK讀取/寫入試算表(Calc) 檔案 (.ods)
https://shaurong.blogspot.com/2019/08/c-libreoffice-626-sdk-calc-ods.html
這是 Windows Forms 程式
[研究] [C#] 使用 OpenOffice 4.1.3 SDK 讀取試算表(Calc) 檔案 (.ods)
http://shaurong.blogspot.com/2016/12/c-openoffice-413-sdk-calc-ods.html
[研究] [C#] 使用 LibreOffice 5.1.6、5.3.0 SDK 讀取試算表(Calc) 檔案 (.ods)
http://shaurong.blogspot.com/2016/12/c-libreoffice-516-sdk-calc-ods.html
[研究] [C#] 讀取 LibreOffice、OpenOffice 的試算表(Calc) 檔案 (.ods)(使用 .NET 4.5 的 ZipFile)
http://shaurong.blogspot.com/2016/12/c-libreoffice-516-calc-ods-net-45.html
[研究] [C#] 使用 Apose.Cells 讀取 LibreOffice 5.1.6、OpenOffice 4.1.3 試算表(Calc) 檔案 (.ods)
http://shaurong.blogspot.com/2017/01/c-aposecells-libreoffice-516openoffice.html
Apose.Cells 是商業付費元件,但有無限期的試用版,但是限制只能開啟 100 個檔案。
https://docs.aspose.com/display/cellsnet/Licensing#Licensing-EvaluationVersionLimitations
[研究] [C#] 使用 GemBox.Spreadsheet 讀取LibreOffice、OpenOffice試算表(Calc) 檔案 (.ods)
http://shaurong.blogspot.com/2016/12/c-gemboxspreadsheet-libreofficeopenoffi.html
這是商業付費軟體,雖然有30天試用版,但功能有限制
Maximum number of rows per sheet is 150.
Maximum number of sheets per workbook is 5.
[研究] OpenOffice 4.1.3 試算表(Calc) 保護鎖定儲存格不被修改
http://shaurong.blogspot.com/2016/12/openoffice-413-calc.html
[研究] 使用OpenOffice 4.1.3試算表(Calc)建立「下拉式選單」來輸入資料
http://shaurong.blogspot.com/2016/12/openoffice-413calc.html
********************************************************************************
相關文章 (其他)
[研究] 匯出、匯入 Excel 檔案 (.NET)
https://shaurong.blogspot.com/2017/11/excel-net.html
[研究] .ods、.csv 轉 .xlsx 檔案
https://shaurong.blogspot.com/2020/04/odscsv-xlsx.html
(待續)
相關文章
在 Server 端存取 Excel 檔案的利器:NPOI Library
https://msdn.microsoft.com/zh-tw/ee818993.aspx





