Excelize v2.7.0
《Excelize 權威指南》圖書出版,網路購買方式:人民郵電出版社 | 異步社區 | 天貓 | 京東 | 當當 | 亞馬遜 | 微店 | 抖音
- 釋出日期: 2023年1月9日
- GitHub Release: https://github.com/xuri/excelize/releases/tag/v2.7.0
版本說明
此版本中最顯著的變化包括:
相容性提示
- 升級至該版本需要您使用的 Go 語言為 1.16 或更高版本,以遷移不再支援的標準庫
ioutil - 當給定工作表名稱中存在無效字符時將傳回錯誤,不再自動略過無效字符
GetCellStyle函式不再傳回合併儲存格區域左上角儲存格的樣式- 重命名以下 5 個導出數據類型和錯誤常量:
- 將
PivotTableOption重命名為PivotTableOptions - 將
FormatHeaderFooter重命名為HeaderFooterOptions - 將
FormatSheetProtection重命名為SheetProtectionOptions - 將
SparklineOption重命名為SparklineOptions - 將
ErrExistsWorksheet重命名為ErrExistsSheet
- 將
- 移除了以下 54 項導出類型:
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 - 移除了 2 個導出常量:
OrientationPortrait和OrientationLandscape - 修改了以下 21 個函式的簽名:
- 將
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) bool修改為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 - 當 XML 反序列化異常時將傳回錯誤以代替輸出日誌,函式
GetComments,GetDefaultFont和SetDefaultFont增加了 error 類型的錯誤傳回值
新增功能
- 新增
GetDataValidations和GetConditionalFormats函式以支援獲取資料驗證設定和件式格式樣式,相關 issue #827 - 新增
ProtectWorkbook和UnprotectWorkbook以提供活頁簿保護設定支援 - 新增
SetSheetCol函式以支援按欄設定儲存格的值,相關 issue #1247 - 新增
GetColStyle函式以支援獲取欄樣式,相關 issue #1293 - 新增
SetSheetBackgroundFromBytes函式以支援根據給定的圖片數據設定工作表背景圖片,相關 issue #1405 - 新增導出變數
IndexedColorMapping以支援內建索引色彩轉換 - 新增 20 項導出類型:
AutoFilterListOptions,AutoFilterOptions,Chart,ChartAxis,ChartDimension,ChartLegend,ChartLine,ChartMarker,ChartPlotArea,ChartSeries,ChartTitle,ConditionalFormatOptions,PaneOptions,Panes,GraphicOptions,Shape,ShapeColor,ShapeLine,ShapeParagraph與TableOptions - 新增 2 項公式函式: AGGREGATE 與 SUBTOTAL
Save、Write和WriteTo函式支援指定存儲選項,相關 issue #744- 使用
AddChart函式添加圖表時,支援為折線圖設定是否使用平滑折線,相關 issue #1290 - 使用
AddChart函式添加圖表時,支援設定自訂折線圖線條色彩,相關 issue #1345 - 使用
AddChart函式添加圖表時,支援設定自訂坐標軸字型樣式,相關 issue #320 - 添加圖表函式
AddChart支援創建立體折線圖 - 以下函式新增併發安全支援:
SetColWidth、GetColWidth、SetColVisible、GetColVisible、SetColStyle與GetColStyle - 設定樣式時,當給定的樣式 ID 不存在時將傳回錯誤,相關 issue #1323
- 流式按列賦值時,若列號未遞增將傳回錯誤,以避免生成的活頁簿損壞,相關 issue #1139
- 按列流式寫入工作表時,支援透過指定
RowOpts為儲存格設定樣式,相關 issue #1354 - 支援流式設定窗格,相關 issue #1047
- 支援流式設定富文本儲存格
- 支援流式插入分頁符
- 新增 7 項導出錯誤信息:
ErrUnprotectWorkbook、ErrUnprotectWorkbookPassword、ErrStreamSetPanes、ErrSheetNameBlank、ErrSheetNameInvalid、ErrSheetNameLength與ErrSheetNameSingleQuote,以便開發者可根據不同的錯誤類型進行採取相應處理 - 新增 5 項導出數據類型:
HeaderFooterOptions、PageLayoutMarginsOptions、PageLayoutOptions、SheetPropsOptions與ViewOptions - 支援設定分級顯示的明細數據方向
- 支援讀取和設定儲存格字型的主題色彩和色調,相關 issue #1369
- 支援讀取帶有符合 ISO 8061 標準的時間類型儲存格的值
- 支援設定和讀取帶有內建色彩索引的字型色彩
- 活頁簿關閉函式將清理由流式寫入器生成的磁盤緩存文件
- 支援添加或刪除欄時自動調整受影響的欄樣式
- 透過
AddPicture添加圖片時,現已允許插入 SVG 格式圖片
相容性提升
問題修復
- 修復部分情況下讀取帶有內建數字格式樣式的浮點數精度有誤問題,解決 issue #1328,#1368 與 #1373
- 修復部分情況下讀取帶有 AM/PM 數字格式樣式的儲存格有誤問題,解決 issue #1338
- 修復部分情況下刪除註解時由於數組下標越界導致的 panic,解決 issue #1343
- 修復部分情況下讀取儲存格的值時出現 panic 的問題,解決 issue #1384 與 #1415
- 修復部分情況下誤將文本解析為浮點型數值的問題,解決 issue #1360
- 修復使用空字符創建工作表後生成的活頁簿損壞問題,解決 issue #1361
- 修復向工作表添加圖片後,獲取該圖片內容為空的問題
- 修復部分情況下插入列欄後生成的活頁簿損壞問題
- 刪除儲存格公式時將刪除公式計算鏈中的共享儲存格引用,以修復部分情況下生成的檔案損壞問題
- 修復部分情況下未對工作表名稱特殊字符及長度做正確處理的問題,解決 issue #1328
- 修復部分情況下公式函式
OR計算結果有誤的問題 - 修復在帶有單一儲存格區域引用的工作表中插入列或欄時,將收到異常的問題
- 修復獲取帶有單一儲存格區域引用合併儲存格區域時,收到異常的問題
- 修復部分情況下讀取富文本儲存格的值不完整問題
- 修復流式寫入時未轉義 XML 字符導致的檔案損壞問題,解決 issue #1391
- 修復公式計算函式 ADDRESS 在工作表名稱為空時計算結果有誤的問題,解決 issue #1396
- 修復部分情況下添加圖片結果有誤的問題,解決 issue #1404
性能優化
- 提高流式合併儲存格性能,相較於上一版本,耗時最高降低約 90%,記憶體使用最高減少約 86%
- 優化按列流式寫入工作表
SetRow函式的性能,相較於上一版本,耗時最高降低約 19%
其他
- Go Modules 依賴模塊更新
- 單元測試與文檔更新
- 優化內部變數與函式命名
- 包含簡體中文、英語、法語、俄語、日語、韓語、阿拉伯語、德語和西班牙語的多國語言文檔網站更新
致謝
感謝 Excelize 的所有貢獻者,以下是為此版本提交代碼的貢獻者列表:
- @cdenicola (Cooper de Nicola)
- @chenliu1993
- @davidborry
- @patsak (Kostya Privezentsev)
- @dafengge0913
- @Beeb0p (Artem Tarasenko)
- @invzhi
- @zhangzitao (Zitao)
- @jtwatson (Joseph Watson)
- @carbin-gun (charles.deng)
- @harrison3000 (Harrison)
- @strivek (GaoFei)
- @gonghaibinx
- @martinmr (Martin Martinez Rivera)
- @zclark (Zach Clark)
- @March0715 (March)
- @renxiaotu
- @devloppper
- @jianxinhou
- @nesstord
- @Bayzet (Bayzet Tlyupov)
- @guoweikuang (郭伟匡)
- @qinyuguang (Gin)
- @liron-l (Liron Levin)