Excelize v2.7.0
- 釋出日期: 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)