
Excelize 是 Go 語言編寫的用於操作 Office Excel 檔案基礎庫,基於 ECMA-376,ISO/IEC 29500 國際標準。可以使用它來讀取、寫入由 Microsoft Excel™ 2007 及以上版本創建的電子錶格檔案。支持 XLAM / XLSM / XLSX / XLTM / XLTX 等多種檔案格式,高度兼容帶有樣式、圖片(表)、樞紐分析表、切片器等複雜組件的檔案,並提供流式讀寫 API,用於處理包含大規模數據的活頁簿。可應用於各類報表平台、雲計算、邊緣計算等系統。入選 2020 Gopher China - Go 領域明星開源項目 (GSP)、 2018 開源中國碼雲 Gitee 最有價值開源項目 GVP,目前已成為 Go 語言最受歡迎的 Excel 檔案基礎庫。
2023年1月9日,社區正式釋出了 2.7.0 版本,該版本包含了多項新增功能、錯誤修復和兼容性提升優化。下面是有關該版本更新內容的摘要,完整的更改列表可查看 changelog。
此版本中最顯著的變化包括:
ioutil
GetCellStyle 函數不再返回合併存儲格區域左上角存儲格的樣式PivotTableOption 重命名為 PivotTableOptions
FormatHeaderFooter 重命名為 HeaderFooterOptions
FormatSheetProtection 重命名為 SheetProtectionOptions
SparklineOption 重命名為 SparklineOptions
ErrExistsWorksheet 重命名為 ErrExistsSheet
AutoPageBreaks, BaseColWidth, BlackAndWhite, CodeName, CustomHeight, Date1904, DefaultColWidth, DefaultGridColor, DefaultRowHeight, EnableFormatConditionsCalculation, FilterPrivacy, FirstPageNumber, FitToHeight, FitToPage, FitToWidth, OutlineSummaryBelow, PageLayoutOption, PageLayoutOptionPtr, PageLayoutOrientation, PageLayoutPaperSize, PageLayoutScale, PageMarginBottom, PageMarginFooter, PageMarginHeader, PageMarginLeft, PageMarginRight, PageMarginsOptions, PageMarginsOptionsPtr, PageMarginTop, Published, RightToLeft, SheetFormatPrOptions, SheetFormatPrOptionsPtr, SheetPrOption, SheetPrOptionPtr, SheetViewOption, SheetViewOptionPtr, ShowFormulas, ShowGridLines, ShowRowColHeaders, ShowRuler, ShowZeros, TabColorIndexed, TabColorRGB, TabColorTheme, TabColorTint, ThickBottom, ThickTop, TopLeftCell, View, WorkbookPrOption, WorkbookPrOptionPtr, ZeroHeight 和 ZoomScale
OrientationPortrait 和 OrientationLandscape
func (f *File) SetPageLayout(sheet string, opts ...PageLayoutOption) error 修改為 func (f *File) SetPageLayout(sheet string, opts *PageLayoutOptions) error
func (f *File) GetPageLayout(sheet string, opts ...PageLayoutOptionPtr) error 修改為 func (f *File) GetPageLayout(sheet string) (PageLayoutOptions, error)
func (f *File) SetPageMargins(sheet string, opts ...PageMarginsOptions) error 修改為 func (f *File) SetPageMargins(sheet string, opts *PageLayoutMarginsOptions) error
func (f *File) GetPageMargins(sheet string, opts ...PageMarginsOptionsPtr) error 修改為 func (f *File) GetPageMargins(sheet string) (PageLayoutMarginsOptions, error)
func (f *File) GetSheetIndex(sheet string) int 修改為 func (f *File) GetSheetIndex(sheet string) (int, error)
func (f *File) SetSheetName(source, target string) 修改為 func (f *File) SetSheetName(source, target string) error
func (f *File) GetSheetVisible(sheet string) 修改為 func (f *File) GetSheetVisible(sheet string) (bool, error)
func (f *File) DeleteSheet(sheet string) 修改為 func (f *File) DeleteSheet(sheet string) error
func (f *File) NewSheet(sheet string) int 修改為 func (f *File) NewSheet(sheet string) (int, error)
func (f *File) NewConditionalStyle(style string) (int, error) 修改為 func (f *File) NewConditionalStyle(style *Style) (int, error)
func (f *File) NewStyle(style interface{}) (int, error) 修改為 func (f *File) NewStyle(style *Style) (int, error)
func (f *File) AddChart(sheet, cell, opts string, combo ...string) error 修改為 func (f *File) AddChart(sheet, cell string, chart *ChartOptions, combo ...*ChartOptions) error
func (f *File) AddChartSheet(sheet, opts string, combo ...string) error 修改為 func (f *File) AddChartSheet(sheet string, chart *ChartOptions, combo ...*ChartOptions) error
func (f *File) AddShape(sheet, cell, opts string) error 修改為 func (f *File) AddShape(sheet, cell string, opts *Shape) error
func (f *File) AddPicture(sheet, cell, picture, format string) error 修改為 func (f *File) AddPicture(sheet, cell, picture string, opts *GraphicOptions) error
func (f *File) AddPictureFromBytes(sheet, cell, opts, name, extension string, file []byte) error 修改為 func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *GraphicOptions) error
func (f *File) AddTable(sheet, hCell, vCell, opts string) error 修改為 func (f *File) AddTable(sheet, rangeRef string, opts *TableOptions) error
func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error 修改為 func (sw *StreamWriter) AddTable(rangeRef string, opts *TableOptions) error
func (f *File) AutoFilter(sheet, hCell, vCell, opts string) error 修改為 func (f *File) AutoFilter(sheet, rangeRef string, opts *AutoFilterOptions) error
func (f *File) SetPanes(sheet, panes string) error 修改為 func (f *File) SetPanes(sheet string, panes *Panes) error
func (f *File) SetConditionalFormat(sheet, reference, opts string) error 修改為 func (f *File) SetConditionalFormat(sheet, rangeRef string, opts []ConditionalFormatOptions) error
SetSheetProps 代替 SetSheetPrOptions 和 SetSheetFormatPr 函數GetSheetProps 代替 GetSheetPrOptions 和 GetSheetFormatPr 函數SetSheetView 代替 SetSheetViewOptions 函數GetSheetView 代替 GetSheetViewOptions 函數SetWorkbookProps 代替 SetWorkbookPrOptions 函數GetWorkbookProps 代替 GetWorkbookPrOptions 函數InsertRows 代替 InsertRow 以支持批量添加列InsertCols 代替 InsertCol 以支持批量添加欄CellType 列舉值中添加 CellTypeFormula, CellTypeInlineString, CellTypeSharedString 並移除了 CellTypeString
AddComment 函數的簽名進行了更改,支持創建富文本註解,相關 issue #1204
GetComments, GetDefaultFont 和 SetDefaultFont 增加了 error 類型的錯誤返回值GetDataValidations 和 GetConditionalFormats 函數以支持獲取資料驗證設定和件式格式樣式,相關 issue #827
ProtectWorkbook 和 UnprotectWorkbook 以提供活頁簿保護設置支持SetSheetCol 函數以支持按欄設定存儲格的值,相關 issue #1247
GetColStyle 函數以支持設定欄樣式,相關 issue #1293
SetSheetBackgroundFromBytes 函數以支持根據給定的圖片數據設定工作表背景圖片,相關 issue #1405
IndexedColorMapping 以支持內建索引顏色轉換AutoFilterListOptions, AutoFilterOptions, Chart, ChartAxis, ChartDimension, ChartLegend, ChartLine, ChartMarker, ChartPlotArea, ChartSeries, ChartTitle, ConditionalFormatOptions, PaneOptions, Panes, GraphicOptions, Shape, ShapeColor, ShapeLine, ShapeParagraph 與 TableOptions
Save、Write 和 WriteTo 函數支持指定保存選項,相關 issue #744
AddChart 函數添加圖表時,支持為折線圖設定是否使用平滑折線,相關 issue #1290
AddChart 函數添加圖表時,支持設定自定義折線圖線條顏色,相關 issue #1345
AddChart 函數添加圖表時,支持設定自定義坐標軸字體樣式,相關 issue #320
AddChart 支持創建立體折線圖SetColWidth、GetColWidth、SetColVisible、GetColVisible、SetColStyle 與 GetColStyle
RowOpts 為存儲格設定樣式,相關 issue #1354
ErrUnprotectWorkbook、ErrUnprotectWorkbookPassword、ErrStreamSetPanes、ErrSheetNameBlank、ErrSheetNameInvalid、ErrSheetNameLength 與 ErrSheetNameSingleQuote,以便開發者可根據不同的錯誤類型進行採取相應處理HeaderFooterOptions、PageLayoutMarginsOptions、PageLayoutOptions、SheetPropsOptions 與 ViewOptions
AddPicture 添加圖片時,現已允許插入 SVG 格式圖片OR 計算結果有誤的問題SetRow 函數的性能,相較於上一版本,耗時最高降低約 19%感謝 Excelize 的所有貢獻者,以下是為此版本提交代碼的貢獻者列表: