19.19. v2.7.0
Excelize v2.7.0
- 发布日期: 2023年1月9日
- GitHub Release: github.com/xuri/excelize/releases/...
版本说明
此版本中最显著的变化包括:
兼容性提示
- 升级至该版本需要您使用的 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)修改为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)
Excelize 开发者指南
关于 LearnKu