1621 lines
44 KiB
Plaintext
Executable File
1621 lines
44 KiB
Plaintext
Executable File
Type ExcelFile = Class
|
||
/// Version: V1.0 2022-01-10
|
||
/// 适用于 Microsoft Excel? 2007 及以上版本创建的电子表格文档。支持 XLSX / XLSM / XLTM / XLTX 等多种文档格式,高度兼容带有样式、图片(表)、透视表、切片器等复杂组件的文档。
|
||
/// windows: plugin\TSXlsx_plugin.dll、tsxlsx.dll
|
||
/// linux: plugin/libtsxlsx_plugin.so、libTsXlsx.so
|
||
/// ExcelFile所有类方法返回值:
|
||
/// [err, v] := f.SetActiveSheet();
|
||
/// if err then
|
||
/// Println("ErrorNo={}, ErrorMsg={}", err, v)
|
||
/// else
|
||
/// Println("return value={}", v);
|
||
///
|
||
/// ExcelFile底层基于Excelize
|
||
/// Excelize是 Go 语言编写的用于操作 Office Excel 文档基础库
|
||
/// https://xuri.me/excelize/zh-hans/
|
||
|
||
fh_; //文件句柄
|
||
|
||
///缺省构造函数
|
||
Function Create(); overload;
|
||
Begin
|
||
End;
|
||
|
||
///构造函数,打开已经存在的excel文件
|
||
///alias: string,文件目录别名
|
||
///fname: string,文件名
|
||
///[opt]: string,参数同OpenFile
|
||
Function Create(alias, fname, opt); overload;
|
||
Begin
|
||
OpenFile(alias, fname, opt);
|
||
End;
|
||
|
||
///析构函数
|
||
Function Destory();
|
||
Begin
|
||
xlsx_call("Close",fh_);
|
||
End;
|
||
|
||
///打开已经存在的excel文件
|
||
///alias: string,文件目录别名
|
||
///fname: string,文件名
|
||
///[opt]: string,可选参数,打开、创建文件option,json字符串
|
||
///定义输入、输出字符集(默认GBK),excel文件是否需要密码打开
|
||
///eg. opt := '{"in":"utf8","out":"utf8","password":"******"}';
|
||
///返回: [err, info]
|
||
Function OpenFile(alias, fname, opt);
|
||
Begin
|
||
if not ifstring(opt) or opt="" then opt := "{}";
|
||
[err, fh, n] := xlsx_call("OpenFile", alias, fname, opt);
|
||
if err then
|
||
PrintLn("OpenFile fail: {}, fname: {}", fh, n)
|
||
else
|
||
fh_ := fh;
|
||
println("fh={}",fh);
|
||
return array(err, fh);
|
||
End;
|
||
|
||
///创建新xlsx文件
|
||
///[opt]: string,参数同openfile,NewFile方法不支持password加密文件
|
||
///返回: [err, info]
|
||
Function NewFile(opt);
|
||
Begin
|
||
[err, fh_] := xlsx_call("NewFile", opt);
|
||
return array(err, fh_);
|
||
End;
|
||
|
||
///保存文件
|
||
///返回: [err, info]
|
||
Function Save();
|
||
Begin
|
||
return xlsx_call("Save", fh_);
|
||
End;
|
||
|
||
///另存为
|
||
///alias: string,文件目录别名
|
||
///fname: string,文件名
|
||
///返回: [err, info]
|
||
Function SaveAs(alias, fname);
|
||
Begin
|
||
return xlsx_call("SaveAs", fh_, alias, fname);
|
||
End;
|
||
|
||
///创建新sheet
|
||
///sheet: string,工作表名称
|
||
///返回: [err, info]
|
||
Function NewSheet(sheet);
|
||
Begin
|
||
return xlsx_call("NewSheet", fh_, sheet);
|
||
End;
|
||
|
||
///删除sheet
|
||
///sheet: string,工作表名称
|
||
///返回: [err, info]
|
||
Function DeleteSheet(sheet);
|
||
Begin
|
||
return xlsx_call("DeleteSheet", fh_, sheet);
|
||
End;
|
||
|
||
///复制sheet
|
||
///from_sheet: string,工作表名称
|
||
///to_sheet: string,工作表名称
|
||
///返回: [err, info]
|
||
Function CopySheet(from_sheet, to_sheet);
|
||
Begin
|
||
return xlsx_call("CopySheet", fh_, from_sheet, to_sheet);
|
||
End;
|
||
|
||
///工作表分组
|
||
///sheets: json字符串,sheet数组
|
||
///eg. sheets := '["sheet1","sheet2"]';
|
||
///返回: [err, info]
|
||
Function GroupSheets(sheets);
|
||
Begin
|
||
return xlsx_call("GroupSheets", fh_, sheets);
|
||
End;
|
||
|
||
///取消工作表分组
|
||
///sheets: json字符串,sheet数组
|
||
///eg. sheets := '["sheet1","sheet2"]';
|
||
///返回: [err, info]
|
||
Function UnGroupSheets(sheets);
|
||
Begin
|
||
return xlsx_call("UnGroupSheets", fh_, sheets);
|
||
End;
|
||
|
||
///设置工作表背景图片
|
||
///picture: string,图片文件路径
|
||
///返回: [err, info]
|
||
Function SetSheetBackground(picture);
|
||
Begin
|
||
return xlsx_call("SetSheetBackground", fh_, picture);
|
||
End;
|
||
|
||
///设置默认(活动)工作表
|
||
///index: 整数, 工作表索引 >= 0
|
||
///返回: [err, info]
|
||
Function SetActiveSheet(index);
|
||
Begin
|
||
return xlsx_call("SetActiveSheet", fh_, index);
|
||
End;
|
||
|
||
///获取默认(活动)工作表索引
|
||
///返回: [err, index:int]
|
||
Function GetActiveSheet();
|
||
Begin
|
||
return xlsx_call("GetActiveSheet", fh_);
|
||
End;
|
||
|
||
///设置工作表可见性
|
||
///sheet: string,工作表名称
|
||
///visible: bool
|
||
///返回: [err, info]
|
||
Function SetSheetVisible(sheet, visible);
|
||
Begin
|
||
return xlsx_call("SetSheetVisible", fh_, sheet, visible);
|
||
End;
|
||
|
||
///获取工作表可见性
|
||
///sheet: string,工作表名称
|
||
///返回: [err, visible:int]
|
||
Function GetSheetVisible(sheet);
|
||
Begin
|
||
return xlsx_call("GetSheetVisible", fh_, sheet);
|
||
End;
|
||
|
||
///设置工作表格式属性
|
||
///sheet: string,工作表名称
|
||
///opts: string,json字符串,表格属性:
|
||
/// BaseColWidth int
|
||
/// DefaultColWidth double
|
||
/// DefaultRowHeight double
|
||
/// CustomHeight bool
|
||
/// ZeroHeight bool
|
||
/// ThickTop bool
|
||
/// ThickBottom bool
|
||
///eg. opts := '{"BaseColWidth":8,"DefaultColWidth":4.2,"ZeroHeight":true}';
|
||
///返回: [err, info]
|
||
Function SetSheetFormatPr(sheet, opts);
|
||
Begin
|
||
return xlsx_call("SetSheetFormatPr", fh_, sheet, opts);
|
||
End;
|
||
|
||
///获取工作表格式属性
|
||
///sheet: string,工作表名称
|
||
///返回: [err, option:json],json字符串表格属性,参考SetSheetFormatPr
|
||
Function GetSheetFormatPr(sheet);
|
||
Begin
|
||
return xlsx_call("GetSheetFormatPr", fh_, sheet);
|
||
End;
|
||
|
||
///设置工作表视图属性
|
||
///sheet: string,工作表名称
|
||
///viewIndex: int,视图索引,viewIndex 可以是负数,如果是这样,则向后计数(-1 代表最后一个视图)
|
||
///opts: string,json字符串,工作表视图属性:
|
||
///
|
||
/// DefaultGridColor bool
|
||
/// RightToLeft bool
|
||
/// ShowFormulas bool
|
||
/// ShowGridLines bool
|
||
/// ShowRowColHeaders bool
|
||
/// ZoomScale double
|
||
/// TopLeftCell string
|
||
/// ShowZeros bool
|
||
///eg. opts := '{"DefaultGridColor":true,"DefaultGridColor":2.0,"TopLeftCell":"A4"}';
|
||
///返回: [err, info]
|
||
Function SetSheetViewOptions(sheet, viewIndex, opts);
|
||
Begin
|
||
return xlsx_call("SetSheetViewOptions", fh_, sheet, viewIndex, opts);
|
||
End;
|
||
|
||
///获取工作表视图属性
|
||
///sheet: string,工作表名称
|
||
///viewindex: int,视图索引,viewIndex 可以是负数,如果是这样,则向后计数(-1 代表最后一个视图)
|
||
///返回: [err, option:json],json字符串表格属性,参考SetSheetViewOptions
|
||
Function GetSheetViewOptions(sheet, viewIndex);
|
||
Begin
|
||
return xlsx_call("GetSheetViewOptions", fh_, viewIndex);
|
||
End;
|
||
|
||
///设置工作表页面布局
|
||
///sheet: string,工作表名称
|
||
///opts: string,json字符串,页面布局参数:
|
||
/// BlackAndWhite bool //BlackAndWhite specified print black and white.
|
||
/// FirstPageNumber int //FirstPageNumber specified the first printed page number. If no value is specified, then 'automatic' is assumed.
|
||
/// PageLayoutOrientation string //PageLayoutOrientation defines the orientation of page layout for a worksheet.
|
||
/// PageLayoutPaperSize int //PageLayoutPaperSize defines the paper size of the worksheet.
|
||
/// FitToHeight int //FitToHeight specified the number of vertical pages to fit on.
|
||
/// FitToWidth int //FitToWidth specified the number of horizontal pages to fit on.
|
||
/// PageLayoutScale int //PageLayoutScale defines the print scaling. This attribute is restricted to values ranging from 10 (10%) to 400 (400%). This setting is overridden when fitToWidth and/or fitToHeight are in use.
|
||
///eg. opts := '{"BlackAndWhite":true,"FirstPageNumber":1,"PageLayoutScale":10}';
|
||
///返回: [err, info]
|
||
Function SetPageLayout(sheet, opts);
|
||
Begin
|
||
return xlsx_call("SetPageLayout", fh_, sheet, opts);
|
||
End;
|
||
|
||
///获取工作表页面布局
|
||
///sheet: string,工作表名称
|
||
///返回: [err, option:json],json字符串表格属性,参考SetPageLayout
|
||
Function GetPageLayout(sheet);
|
||
Begin
|
||
return xlsx_call("GetPageLayout", fh_, sheet);
|
||
End;
|
||
|
||
///设置工作表页边距
|
||
///sheet: string,工作表名称
|
||
///opts: string,json字符串,页边距参数:
|
||
/// PageMarginBotom double
|
||
/// PageMarginFooter double
|
||
/// PageMarginHeader double
|
||
/// PageMarginLeft double
|
||
/// PageMarginRight double
|
||
/// PageMarginTop double
|
||
///eg. opts := '{"PageMarginBotom":4.2,"PageMarginLeft":1,"PageMarginTop":4.2}';
|
||
///返回: [err, info]
|
||
Function SetPageMargins(sheet, opts);
|
||
Begin
|
||
return xlsx_call("SetPageMargins", fh_, sheet, opts);
|
||
End;
|
||
|
||
///获取工作表页边距
|
||
///sheet: string,工作表名称
|
||
///返回: [err, option:json],json字符串表格属性,参考SetPageMargins
|
||
Function GetPageMargins(sheet);
|
||
Begin
|
||
return xlsx_call("GetPageMargins", fh_, sheet);
|
||
End;
|
||
|
||
///设置页眉和页脚
|
||
///sheet: string,工作表名称
|
||
///opts: string,json字符串,页眉和页脚参数:
|
||
/// AlignWithMargins bool //设定页眉页脚页边距与页边距对齐
|
||
/// DifferentFirst bool //设定第一页页眉和页脚
|
||
/// DifferentOddEven bool //设定奇数和偶数页页眉和页脚
|
||
/// ScaleWithDoc bool //设定页眉和页脚跟随文档缩放
|
||
/// OddFooter string //奇数页页脚控制字符
|
||
/// OddHeader string //奇数页页眉控制字符
|
||
/// EvenFooter string //偶数页页脚控制字符
|
||
/// EvenHeader string //偶数页页眉控制字符
|
||
/// FirstFooter string //首页页脚控制字符
|
||
/// FirstHeader string //首页页眉控制字符
|
||
///eg. opts := '{"AlignWithMargins":true,"ScaleWithDoc":true,"EvenHeader":"&L&D&R&T"}';
|
||
///返回: [err, info]
|
||
Function SetHeaderFooter(sheet, opts);
|
||
Begin
|
||
return xlsx_call("SetHeaderFooter", fh_, sheet, opts);
|
||
End;
|
||
|
||
///设置名称,根据给定的名称和引用区域设置名称,默认范围是工作簿。
|
||
///opts: string,json字符串,参数:
|
||
/// Name string
|
||
/// Comment string
|
||
/// RefersTo string
|
||
/// Scope string
|
||
///eg. opts := '{"Name":"Amount","RefersTo":"Sheet1!$A$2:$D$5","Comment":"defined name comment","Scope":"Sheet2"}';
|
||
///返回: [err, info]
|
||
Function SetDefinedName(opts);
|
||
Begin
|
||
return xlsx_call("SetDefinedName", fh_, opts);
|
||
End;
|
||
|
||
///获取作用范围内的工作簿和工作表的名称列表
|
||
///返回: [err, definedname:json],json字符串,所有名称列表,参见SetDefinedName
|
||
Function GetDefinedName();
|
||
Begin
|
||
return xlsx_call("GetDefinedName", fh_);
|
||
End;
|
||
|
||
///删除名称,根据给定的名称和名称作用范围删除已定义的名称,默认名称的作用范围为工作簿。
|
||
///opts: string,json字符串,参见SetDefinedName
|
||
///返回: [err, info]
|
||
Function DeleteDefinedName(opts);
|
||
Begin
|
||
return xlsx_call("DelDefinedName", fh_, opts);
|
||
End;
|
||
|
||
///设置工作簿应用程序属性
|
||
///opts: string,json字符串,参数:
|
||
/// Application string
|
||
/// ScaleCrop bool
|
||
/// DocSecurity int
|
||
/// Company string
|
||
/// LinksUpToDate bool
|
||
/// HyperlinksChanged bool
|
||
/// AppVersion string
|
||
///eg. opts := '{"Application":"TS_Xlsx_Test","Company":"Shenzhen Tinysoft Co.,LTD","LinksUpToDate":true,"AppVersion":"10.1"}';
|
||
///返回: [err, info]
|
||
Function SetAppProps(opts);
|
||
Begin
|
||
return xlsx_call("SetAppProps", fh_, opts);
|
||
End;
|
||
|
||
///获取应用程序属性
|
||
///返回: [err, props:json],json字符串,所有名称列表,参见SetAppProps
|
||
Function GetAppProps();
|
||
Begin
|
||
return xlsx_call("GetAppProps", fh_);
|
||
End;
|
||
|
||
///设置工作簿的核心属性
|
||
///opts: string,json字符串,参数:
|
||
/// Title string 文档标题
|
||
/// Subject string 文档主题
|
||
/// Creator string 创作者
|
||
/// Keywords string 文档关键词
|
||
/// Description string 资源内容的说明
|
||
/// LastModifiedBy string 执行上次修改的用户
|
||
/// Language string 文档内容的主要语言
|
||
/// Identifier string 对给定上下文中的资源的明确引用
|
||
/// Revision string 文档修订版本
|
||
/// ContentStatus string 文档内容的状态。例如: 值可能包括 "Draft"、"Reviewed" 和 "Final"
|
||
/// Category string 文档内容的分类
|
||
/// Version string 版本号,该值由用户或应用程序设置
|
||
///eg. opts := '{"Title":"Test","Subject":"test","Creator":"Hans"}';
|
||
///返回: [err, info]
|
||
Function SetDocProps(opts);
|
||
Begin
|
||
return xlsx_call("SetDocProps", fh_, opts);
|
||
End;
|
||
|
||
///获取工作簿的核心属性
|
||
///返回: [err, props:json],json字符串,所有名称列表,参见SetDocProps
|
||
Function GetDocProps();
|
||
Begin
|
||
return xlsx_call("GetDocProps", fh_);
|
||
End;
|
||
|
||
///设置列可见性
|
||
///sheet: string,工作表
|
||
///col: string,列,如: "A"
|
||
///visible: bool
|
||
///返回: [err, info]
|
||
Function SetColVisible(sheet, col, visible);
|
||
Begin
|
||
return xlsx_call("SetColVisible", fh_, sheet, col, visible);
|
||
End;
|
||
|
||
///设置列宽度
|
||
///sheet: string,工作表
|
||
///startcol: string,开始列,如: "A"
|
||
///endcol: string,结束列,如: "D"
|
||
///width: double
|
||
///返回: [err, info]
|
||
Function SetColWidth(sheet, startcol, endcol, width);
|
||
Begin
|
||
return xlsx_call("SetColWidth", fh_, sheet, startcol, endcol, width);
|
||
End;
|
||
|
||
///设置行可见性
|
||
///sheet: string,工作表
|
||
///row: int,行
|
||
///visible: bool
|
||
///返回: [err, info]
|
||
Function SetRowVisible(sheet, row, visible);
|
||
Begin
|
||
return xlsx_call("SetRowVisible", fh_, sheet, row, visible);
|
||
End;
|
||
|
||
///设置行高度
|
||
///sheet: string,工作表
|
||
///row: int,行
|
||
///height: double
|
||
///返回: [err, info]
|
||
Function SetRowHeight(sheet, row, height);
|
||
Begin
|
||
return xlsx_call("SetRowHeight", fh_, sheet, row, height);
|
||
End;
|
||
|
||
///获取工作表名
|
||
///index: int,工作表索引
|
||
///返回: [err, sheetname:string]
|
||
Function GetSheetName(index);
|
||
Begin
|
||
return xlsx_call("GetSheetName", fh_, index);
|
||
End;
|
||
|
||
///获取工作表索引
|
||
///sheet: string,工作表名
|
||
///返回: [err, sheetindex:int]
|
||
Function GetSheetIndex(sheet);
|
||
Begin
|
||
return xlsx_call("GetSheetIndex", fh_, sheet);
|
||
End;
|
||
|
||
///获取工作表映射表
|
||
///返回: [err, namemap:json],json串 {"1":"Sheet1","2":"Sheet2"}
|
||
Function GetSheetMap();
|
||
Begin
|
||
return xlsx_call("GetSheetMap", fh_);
|
||
End;
|
||
|
||
///获取工作表列表
|
||
///返回: [err, nameArr:json],json串 ["Sheet1","Sheet2"]
|
||
Function GetSheetS();
|
||
Begin
|
||
return xlsx_call("GetSheetS", fh_);
|
||
End;
|
||
|
||
///设置工作表名称
|
||
///oldname: string
|
||
///newname: string
|
||
///返回: [err, info]
|
||
Function SetSheetName(oldname, newname);
|
||
Begin
|
||
return xlsx_call("SetSheetName", fh_, oldname, newname);
|
||
End;
|
||
|
||
///设置工作表属性
|
||
///根据给定的工作表名称(大小写敏感)和筛选项设置工作表属性。
|
||
///sheet: string,工作表名称
|
||
///opts: string,json字符串,属性:
|
||
/// CodeName string
|
||
/// EnableFormatConditionsCalculation bool
|
||
/// Published bool
|
||
/// FitToPage bool
|
||
/// TabColor string
|
||
/// AutoPageBreaks bool
|
||
/// OutlineSummaryBelow bool
|
||
///eg. opts := '{"CodeName":"code","EnableFormatConditionsCalculation":false,"TabColor":"#FFFF00","AutoPageBreaks":true}';
|
||
///返回: [err, info]
|
||
Function SetSheetPrOptions(sheet, opts);
|
||
Begin
|
||
return xlsx_call("SetSheetPrOptions", fh_, sheet, opts);
|
||
End;
|
||
|
||
///获取工作表属性
|
||
///根据给定的工作表名称(大小写敏感)和筛选项获取工作表属性。
|
||
///sheet: string,工作表名称
|
||
///返回: [err, options:json],json串,参见: SetSheetPrOptions
|
||
Function GetSheetPrOptions(sheet);
|
||
Begin
|
||
return xlsx_call("GetSheetPrOptions", fh_, sheet);
|
||
End;
|
||
|
||
///插入列,在指定列前插入空白列
|
||
///sheet: string,工作表名称
|
||
///col: string 列名,如: "D"
|
||
///返回: [err, info]
|
||
Function InsertCol(sheet, col);
|
||
Begin
|
||
return xlsx_call("InsertCol", fh_, sheet, col);
|
||
End;
|
||
|
||
///插入行,在指定列前插入空白行
|
||
///sheet: string,工作表名称
|
||
///row: int
|
||
///返回: [err, info]
|
||
Function InsertRow(sheet, row);
|
||
Begin
|
||
return xlsx_call("InsertRow", fh_, sheet, row);
|
||
End;
|
||
|
||
///追加复制行,根据给定的工作表名称(大小写敏感)和行号,在该行后追加复制。
|
||
///sheet: string,工作表名称
|
||
///row: int
|
||
///返回: [err, info]
|
||
Function DuplicateRow(sheet, row);
|
||
Begin
|
||
return xlsx_call("DuplicateRow", fh_, sheet, row);
|
||
End;
|
||
|
||
///复制行,根据给定的工作表名称(大小写敏感)和行号,在指定行后复制该行。
|
||
///sheet: string,工作表名称
|
||
///row: int
|
||
///row2: int
|
||
///返回: [err, info]
|
||
Function DuplicateRowTo(sheet, row, row2);
|
||
Begin
|
||
return xlsx_call("DuplicateRowTo", fh_, sheet, row, row2);
|
||
End;
|
||
|
||
///创建行的分级显示,根据给定的工作表名称(大小写敏感)、行号和分级参数创建组。
|
||
///sheet: string,工作表名称
|
||
///row: int
|
||
///level: int,分级参数
|
||
///返回: [err, info]
|
||
Function SetRowOutlineLevel(sheet, row, level);
|
||
Begin
|
||
return xlsx_call("SetRowOutlineLevel", fh_, sheet, row, level);
|
||
End;
|
||
|
||
///创建列的分级显示,根据给定的工作表名称(大小写敏感)、列名称和分级参数创建组。
|
||
///sheet: string,工作表名称
|
||
///col: string
|
||
///level: int,分级参数
|
||
///返回: [err, info]
|
||
Function SetColOutlineLevel(sheet, col, level);
|
||
Begin
|
||
return xlsx_call("SetColOutlineLevel", fh_, sheet, col, level);
|
||
End;
|
||
|
||
///获取行的分级显示
|
||
///sheet: string,工作表名称
|
||
///row: int
|
||
///返回: [err, level:int]
|
||
Function GetRowOutlineLevel(sheet, row);
|
||
Begin
|
||
return xlsx_call("GetRowOutlineLevel", fh_, sheet, row);
|
||
End;
|
||
|
||
///获取列的分级显示
|
||
///sheet: string,工作表名称
|
||
///col: string
|
||
///返回: [err, level:int]
|
||
Function GetColOutlineLevel(sheet, col);
|
||
Begin
|
||
return xlsx_call("GetColOutlineLevel", fh_, sheet, col);
|
||
End;
|
||
|
||
///在工作表中搜索,根据给定的工作表名称(大小写敏感),单元格值或正则表达式来获取坐标。此函数仅支持字符串和数字的完全匹配,不支持公式计算后的结果、格式化数字和条件搜索。如果搜索结果是合并的单元格,将返回合并区域左上角的坐标。
|
||
///sheet: string,工作表名称
|
||
///value: string
|
||
///reg: bool,是否正则表达式
|
||
///返回: [err, coordinates:json],json串,满足条件的坐标数组
|
||
Function SearchSheet(sheet, value, reg);
|
||
Begin
|
||
return xlsx_call("SearchSheet", fh_, value, reg);
|
||
End;
|
||
|
||
///保护工作表,防止其他用户意外或有意更改、移动或删除工作表中的数据。
|
||
///sheet: string,工作表名称
|
||
///opts: string,json字符串,属性:
|
||
/// AutoFilter bool
|
||
/// DeleteColumns bool
|
||
/// DeleteRows bool
|
||
/// EditObjects bool
|
||
/// EditScenarios bool
|
||
/// FormatCells bool
|
||
/// FormatColumns bool
|
||
/// FormatRows bool
|
||
/// InsertColumns bool
|
||
/// InsertHyperlinks bool
|
||
/// InsertRows bool
|
||
/// Password string
|
||
/// PivotTables bool
|
||
/// SelectLockedCells bool
|
||
/// SelectUnlockedCells bool
|
||
/// Sort bool
|
||
///eg. opts := '{"AutoFilter":true,"DeleteRows":true}';
|
||
///返回: [err, info]
|
||
Function ProtectSheet(sheet, opts);
|
||
Begin
|
||
return xlsx_call("ProtectSheet", fh_, sheet, opts);
|
||
End;
|
||
|
||
///取消保护工作表
|
||
///sheet: string,工作表名称
|
||
///返回: [err, info]
|
||
Function UnProtectSheet(sheet);
|
||
Begin
|
||
return xlsx_call("UnProtectSheet", fh_, sheet);
|
||
End;
|
||
|
||
///删除列
|
||
///sheet: string,工作表名称
|
||
///col: string,如: "D"
|
||
///返回: [err, info]
|
||
Function RemoveCol(sheet, col);
|
||
Begin
|
||
return xlsx_call("RemoveCol", fh_, sheet, col);
|
||
End;
|
||
|
||
///删除行
|
||
///sheet: string,工作表名称
|
||
///row: int
|
||
///返回: [err, info]
|
||
Function RemoveRow(sheet, row);
|
||
Begin
|
||
return xlsx_call("RemoveRow", fh_, sheet, row);
|
||
End;
|
||
|
||
///按行赋值
|
||
///sheet: string,工作表名称
|
||
///axis: string,起始坐标,如: "A4"
|
||
///slice: [string,array],一维数组或json串一维数组,如: '[1,3,2,2.1,"hello"]' array(1,2,3,2,1,"hello")
|
||
///返回: [err, info]
|
||
Function SetSheetRow(sheet, axis, slice);
|
||
Begin
|
||
if ifarray(slice) then slice := ExportJsonString(slice);
|
||
return xlsx_call("SetSheetRow", fh_, sheet, axis, slice);
|
||
End;
|
||
|
||
///插入分页符
|
||
///sheet: string,工作表名称
|
||
///cell: string,单元格坐标,如: "A4"
|
||
///返回: [err, info]
|
||
Function InsertPageBreak(sheet, cell);
|
||
Begin
|
||
return xlsx_call("InsertPageBreak", fh_, sheet, cell);
|
||
End;
|
||
|
||
///删除分页符
|
||
///sheet: string,工作表名称
|
||
///cell: string,单元格坐标
|
||
///返回: [err, info]
|
||
Function RemovePageBreak(sheet, cell);
|
||
Begin
|
||
return xlsx_call("RemovePageBreak", fh_, sheet, cell);
|
||
End;
|
||
|
||
///按列获取全部单元格的值
|
||
///根据给定的工作表名(大小写敏感)按列获取该工作表上全部单元格的值,以二维数组形式返回,其中单元格的值将转换为 string 类型。如果可以将单元格格式应用于单元格的值,将使用应用后的值,否则将使用原始值。
|
||
///sheet: string,工作表名称
|
||
///opts: string,输出格式
|
||
///返回: [err, results:json], json串二维字符串数组
|
||
Function GetRows(sheet);
|
||
Begin
|
||
return xlsx_call("GetRows", fh_, sheet, opts);
|
||
End;
|
||
|
||
///按行获取全部单元格的值
|
||
///根据给定的工作表名(大小写敏感)按行获取该工作表上全部单元格的值,以二维数组形式返回,其中单元格的值将转换为 string 类型。如果可以将单元格格式应用于单元格的值,将使用应用后的值,否则将使用原始值。
|
||
///sheet: string,工作表名称
|
||
///opts: string,输出格式
|
||
///返回: [err, results:json], json串二维字符串数组
|
||
Function GetCols(sheet, opts);
|
||
Begin
|
||
return xlsx_call("GetCols", fh_, sheet, opts);
|
||
End;
|
||
|
||
///设置单元格的值
|
||
///sheet: string,工作表名称
|
||
///axis: string,单元格坐标,如: "A6"
|
||
///val: Var,可以是整数、字符串、数值型
|
||
///返回: [err, info]
|
||
Function SetCellValue(sheet, axis, val);
|
||
Begin
|
||
return xlsx_call("SetCellValue", fh_, sheet, axis, val);
|
||
End;
|
||
|
||
///获取单元格的值
|
||
///sheet: string,工作表名称
|
||
///axis: string,单元格坐标,如: "A6"
|
||
///opts: string,输出格式
|
||
///返回: [err, value:string, datatype:int],datatype参见GetCellType
|
||
Function GetCellValue(sheet, axis, opts);
|
||
Begin
|
||
return xlsx_call("GetCellValue", fh_, sheet, axis, opts);
|
||
End;
|
||
|
||
///设置布尔型值
|
||
///sheet: string,工作表名称
|
||
///axis: string,单元格坐标,如: "A6"
|
||
///val: bool
|
||
///返回: [err, info]
|
||
Function SetCellBool(sheet, axis, val);
|
||
Begin
|
||
return xlsx_call("SetCellBool", fh_, sheet, axis,val);
|
||
End;
|
||
|
||
///设置默认字符型值
|
||
///sheet: string,工作表名称
|
||
///axis: string,单元格坐标,如: "A6"
|
||
///val: string,缺省值
|
||
///返回: [err, info]
|
||
Function SetCellDefault(sheet, axis, val);
|
||
Begin
|
||
return xlsx_call("SetCellDefault", fh_, sheet, axis, val);
|
||
End;
|
||
|
||
///创建单元格样式
|
||
/// Alignment 映射单元格对齐样式设置。
|
||
/// type Alignment struct {
|
||
/// Horizontal string
|
||
/// Indent int
|
||
/// JustifyLastLine bool
|
||
/// ReadingOrder int64
|
||
/// RelativeIndent int
|
||
/// ShrinkToFit bool
|
||
/// TextRotation int
|
||
/// Vertical string
|
||
/// WrapText bool
|
||
/// }
|
||
///
|
||
/// Border 映射单元格边框样式设置。
|
||
/// type Border struct {
|
||
/// Type string
|
||
/// Color string
|
||
/// Style int
|
||
/// }
|
||
/// Font 映射字体样式设置。
|
||
/// type Font struct {
|
||
/// Bold bool
|
||
/// Italic bool
|
||
/// Underline string
|
||
/// Family string
|
||
/// Size double
|
||
/// Strike bool
|
||
/// Color string
|
||
/// }
|
||
///
|
||
/// Fill 映射单元格样式填充设置。
|
||
/// type Fill struct {
|
||
/// Type string
|
||
/// Pattern int
|
||
/// Color string数组
|
||
/// Shading int
|
||
/// }
|
||
///
|
||
/// Protection 映射保护单元格属性设置。
|
||
/// type Protection struct {
|
||
/// Hidden bool
|
||
/// Locked bool
|
||
/// }
|
||
///
|
||
/// Style 映射单元格样式设置。
|
||
/// type Style struct {
|
||
/// Border Border数组
|
||
/// Fill Fill
|
||
/// Font Font
|
||
/// Alignment Alignment
|
||
/// Protection Protection
|
||
/// NumFmt int
|
||
/// DecimalPlaces int
|
||
/// CustomNumFmt string
|
||
/// Lang string
|
||
/// NegRed bool
|
||
/// }
|
||
///opts: string,json串,Style结构体
|
||
///返回: [err, StyleID:int]
|
||
Function NewStyle(opts);
|
||
Begin
|
||
return xlsx_call("NewStyle", fh_, opts);
|
||
End;
|
||
|
||
///设置单元格样式
|
||
///sheet: string,工作表名称
|
||
///hcell: string,左上角坐标
|
||
///vcell: string,右下角坐标
|
||
///styleid: int,样式Id
|
||
///返回: [err, info]
|
||
Function SetCellStyle(sheet, hcell, vcell, styleid);
|
||
Begin
|
||
return xlsx_call("SetCellStyle", fh_, sheet, hcell, vcell, styleid);
|
||
End;
|
||
|
||
///设置超链接
|
||
///sheet: string,工作表名称
|
||
///axis: string,单元格,如"A7"
|
||
///link: string,链接URL
|
||
///linkType: string,链接类型,资源类型分为外部链接地址 External 和工作簿内部位置链接 Location 两种。
|
||
///opts: string,json串
|
||
///type HyperlinkOpts struct {
|
||
/// Display string
|
||
/// Tooltip string
|
||
///}
|
||
///返回: [err, info]
|
||
Function SetCellHyperLink(sheet, axis, link, linkType, opts);
|
||
Begin
|
||
return xlsx_call("SetCellHyperLink", fh_, sheet, axis, link, linkType, opts);
|
||
End;
|
||
|
||
///获取超链接
|
||
///sheet: string,工作表名称
|
||
///axis: string,单元格,如"A7"
|
||
///返回: [err, link:string]
|
||
Function GetCellHyperLink(sheet, axis);
|
||
Begin
|
||
return xlsx_call("GetCellHyperLink", fh_, sheet);
|
||
End;
|
||
|
||
///设置富文本格式
|
||
///sheet: string,工作表名称
|
||
///axis: string,单元格,如"A7"
|
||
///txt: string,json串,RichText结构数组
|
||
/// type RichText struct {
|
||
/// Font Font
|
||
/// Text string
|
||
/// }
|
||
/// type Font struct {
|
||
/// Bold bool
|
||
/// Italic bool
|
||
/// Underline string
|
||
/// Family string
|
||
/// Size double
|
||
/// Strike bool
|
||
/// Color string
|
||
/// }
|
||
///返回: [err, info]
|
||
Function SetCellRichText(sheet, axis, txt);
|
||
Begin
|
||
return xlsx_call("SetCellRichText", fh_, sheet, axis, txt);
|
||
End;
|
||
|
||
///获取富文本格式
|
||
///sheet: string,工作表名称
|
||
///axis: string,单元格,如"A7"
|
||
///返回: [err, txt:json],参见SetCellRichText
|
||
Function GetCellRichText(sheet, axis);
|
||
Begin
|
||
return xlsx_call("GetCellRichText", fh_, sheet, axis);
|
||
End;
|
||
|
||
///获取单元格数据类型
|
||
///sheet: string,工作表名称
|
||
///axis: string,单元格,如"A7"
|
||
///返回: [err, datatype:int],(Int = 0, Int64 = 20, Double = 1, String = 2, Date = 3, UnSet = 10, Err = -1)
|
||
Function GetCellType(sheet, axis);
|
||
Begin
|
||
return xlsx_call("GetCellType", fh_, sheet, axis);
|
||
End;
|
||
|
||
///获取单元格样式索引,获取到的索引可以在复制单元格样式时,作为调用 SetCellValue 函数的参数使用。
|
||
///sheet: string,工作表名称
|
||
///axis: string,单元格,如"A7"
|
||
///返回: [err, datastyle: int]
|
||
Function GetCellStyle(sheet, axis);
|
||
Begin
|
||
return xlsx_call("GetCellStyle", fh_, sheet, axis);
|
||
End;
|
||
|
||
///合并单元格
|
||
///sheet: string,工作表名称
|
||
///hcell: string,左上角坐标
|
||
///vcell: string,右下角坐标
|
||
///返回: [err, info]
|
||
Function MergeCell(sheet, hcell, vcell);
|
||
Begin
|
||
return xlsx_call("MergeCell", fh_, sheet, hcell, vcell);
|
||
End;
|
||
|
||
///取消合并单元格
|
||
///sheet: string,工作表名称
|
||
///hcell: string,左上角坐标
|
||
///vcell: string,右下角坐标
|
||
///返回: [err, info]
|
||
Function UnMergeCell(sheet, hcell, vcell);
|
||
Begin
|
||
return xlsx_call("UnMergeCell", fh_, sheet, hcell, vcell);
|
||
End;
|
||
|
||
///获取全部合并单元格的坐标区域和值。
|
||
///sheet: string,工作表名称
|
||
///返回: [err, value:json],返回工作表所有合并区域数组
|
||
Function GetMergeCells(sheet);
|
||
Begin
|
||
return xlsx_call("GetMergeCells", fh_, sheet);
|
||
End;
|
||
|
||
///添加批注
|
||
///sheet: string,工作表名称
|
||
///axis: string,单元格,如"A7"
|
||
///comment: string
|
||
///返回: [err, info]
|
||
Function AddComment(sheet, axis, comment);
|
||
Begin
|
||
return xlsx_call("AddComment", fh_, sheet, axis, comment);
|
||
End;
|
||
|
||
///获取批注
|
||
///返回: [err, allcomments:json],获取全部工作表中的批注。
|
||
Function GetComments();
|
||
Begin
|
||
return xlsx_call("GetComments", fh_);
|
||
End;
|
||
|
||
///设置公式
|
||
///sheet: string,工作表名称
|
||
///axis: string,单元格,如"A7"
|
||
///formula: string,公式
|
||
///返回: [err, info]
|
||
Function SetCellFormula(sheet, axis, formula);
|
||
Begin
|
||
return xlsx_call("SetCellFormula", fh_, sheet, axis, formula);
|
||
End;
|
||
|
||
///获取公式
|
||
///sheet: string,工作表名称
|
||
///axis: string,单元格,如"A7"
|
||
///返回: [err, formula:string]
|
||
Function GetCellFormula(sheet, axis);
|
||
Begin
|
||
return xlsx_call("GetCellFormula", fh_, sheet, axis);
|
||
End;
|
||
|
||
///计算单元格的值
|
||
///sheet: string,工作表名称
|
||
///axis: string,单元格,如"A7"
|
||
///返回: [err, result:string]
|
||
Function CalcCellValue(sheet, axis);
|
||
Begin
|
||
return xlsx_call("CalcCellValue", fh_, sheet, axis);
|
||
End;
|
||
|
||
///添加图表
|
||
///sheet: string,工作表名称
|
||
///col:string,左上角坐标
|
||
///format:string,json串
|
||
///eg. opts := '{
|
||
/// "type": "col",
|
||
/// "series": [
|
||
/// {
|
||
/// "name": "Sheet1!$A$2",
|
||
/// "categories": "Sheet1!$B$1:$D$1",
|
||
/// "values": "Sheet1!$B$2:$D$2"
|
||
/// },
|
||
/// {
|
||
/// "name": "Sheet1!$A$3",
|
||
/// "categories": "Sheet1!$B$1:$D$1",
|
||
/// "values": "Sheet1!$B$3:$D$3"
|
||
/// }],
|
||
/// "format":
|
||
/// {
|
||
/// "x_scale": 1.0,
|
||
/// "y_scale": 1.0,
|
||
/// "x_offset": 15,
|
||
/// "y_offset": 10,
|
||
/// "print_obj": true,
|
||
/// "lock_aspect_ratio": false,
|
||
/// "locked": false
|
||
/// },
|
||
/// "legend":
|
||
/// {
|
||
/// "position": "left",
|
||
/// "show_legend_key": false
|
||
/// },
|
||
/// "title":
|
||
/// {
|
||
/// "name": "簇状柱形图 - 折线图"
|
||
/// },
|
||
/// "plotarea":
|
||
/// {
|
||
/// "show_bubble_size": true,
|
||
/// "show_cat_name": false,
|
||
/// "show_leader_lines": false,
|
||
/// "show_percent": true,
|
||
/// "show_series_name": true,
|
||
/// "show_val": true
|
||
/// }
|
||
/// }';
|
||
///combo:string,json串,用来指定创建组合图表,该图表将两个或多个图表类型组合在一个图表中。
|
||
///返回: [err, info]
|
||
Function AddChart(sheet, cell, format, combo);
|
||
Begin
|
||
return xlsx_call("AddChart", fh_, sheet, cell, format, combo);
|
||
End;
|
||
|
||
///创建图表工作表
|
||
///sheet: string,工作表名称
|
||
///format:string,json串,参见AddChart
|
||
///combo:string,json串,参见AddChart
|
||
///返回: [err, info]
|
||
Function AddChartSheet(sheet, format, combo);
|
||
Begin
|
||
return xlsx_call("AddChartSheet", fh_, sheet, format, combo);
|
||
End;
|
||
|
||
///删除图表
|
||
///sheet: string,工作表名称
|
||
///cell: string,单元格
|
||
///返回: [err, info]
|
||
Function DeleteChart(sheet, cell);
|
||
Begin
|
||
return xlsx_call("DeleteChart", fh_, sheet, cell);
|
||
End;
|
||
|
||
///插入图片
|
||
///sheet: string,工作表名称
|
||
///cell: string,单元格
|
||
///picture: string,图片文件路径
|
||
///format: string,json串,图片格式(例如偏移、缩放和打印设置等)
|
||
///eg. format := '{
|
||
/// "x_scale": 0.5,
|
||
/// "y_scale": 0.5,
|
||
/// "hyperlink": "#Sheet2!D8",
|
||
/// "hyperlink_type": "Location"}';
|
||
///返回: [err, info]
|
||
Function AddPicture(sheet, cell, picture, format);
|
||
Begin
|
||
return xlsx_call("AddPicture", fh_, sheet, cell, picture, format);
|
||
End;
|
||
|
||
///删除图片
|
||
///sheet: string,工作表名称
|
||
///cell: string,单元格
|
||
///返回: [err, info]
|
||
Function DeletePicture(sheet, cell);
|
||
Begin
|
||
return xlsx_call("DeletePicture", fh_, sheet, cell);
|
||
End;
|
||
|
||
///添加形状
|
||
///sheet: string,工作表名称
|
||
///cell: string,单元格
|
||
///format: string,json串,样式(包括偏移、缩放、拉伸、宽高比和打印属性等)
|
||
///eg. format := '{
|
||
/// "type": "rect",
|
||
/// "color":
|
||
/// {
|
||
/// "line": "#4286F4",
|
||
/// "fill": "#8eb9ff"
|
||
/// },
|
||
/// "paragraph": [
|
||
/// {
|
||
/// "text": "Rectangle Shape",
|
||
/// "font":
|
||
/// {
|
||
/// "bold": true,
|
||
/// "italic": true,
|
||
/// "family": "Times New Roman",
|
||
/// "size": 36,
|
||
/// "color": "#777777",
|
||
/// "underline": "sng"
|
||
/// }
|
||
/// }],
|
||
/// "width": 180,
|
||
/// "height": 90,
|
||
/// "line":
|
||
/// {
|
||
/// "width": 1.5
|
||
/// }
|
||
/// }';
|
||
///返回: [err, info]
|
||
Function AddShape(sheet, cell, format);
|
||
Begin
|
||
return xlsx_call("AddShape", fh_, sheet, cell, format);
|
||
End;
|
||
|
||
///添加迷你图
|
||
///sheet: string,工作表名称
|
||
///opt:string,json串
|
||
/// type SparklineOption struct {
|
||
/// Location string-array
|
||
/// Range string-array
|
||
/// Max int
|
||
/// CustMax int
|
||
/// Min int
|
||
/// CustMin int
|
||
/// Type string
|
||
/// Weight double
|
||
/// DateAxis bool
|
||
/// Markers bool
|
||
/// High bool
|
||
/// Low bool
|
||
/// First bool
|
||
/// Last bool
|
||
/// Negative bool
|
||
/// Axis bool
|
||
/// Hidden bool
|
||
/// Reverse bool
|
||
/// Style int
|
||
/// SeriesColor string
|
||
/// NegativeColor string
|
||
/// MarkersColor string
|
||
/// FirstColor string
|
||
/// LastColor string
|
||
/// HightColor string
|
||
/// LowColor string
|
||
/// EmptyCells string
|
||
///}
|
||
///eg. opt := '"Location":["A1", "A2", "A3"],"Range": ["Sheet2!A1:J1", "Sheet2!A2:J2", "Sheet2!A3:J3"],"Markers":true}';
|
||
///返回: [err, info]
|
||
Function AddSparkLine(sheet, opt);
|
||
Begin
|
||
return xlsx_call("AddSparkLine", fh_, sheet, opt);
|
||
End;
|
||
|
||
///设置列样式
|
||
///sheet: string,工作表名称
|
||
///columns: string,列名,"A" "D:H"
|
||
///styleID: int,样式ID,参见NewStyle
|
||
///返回: [err, info]
|
||
Function SetColStyle(sheet, columns, styleID);
|
||
Begin
|
||
return xlsx_call("SetColStyle", fh_, sheet, columns, styleID);
|
||
End;
|
||
|
||
///设置行样式
|
||
///sheet: string,工作表名称
|
||
///row1: int
|
||
///row2: int
|
||
///styleID: int,样式ID,参见NewStyle
|
||
///返回: [err, info]
|
||
Function SetRowStyle(sheet, row1, row2, styelID);
|
||
Begin
|
||
return xlsx_call("SetRowStyle", fh_, sheet, row1, row2, styelID);
|
||
End;
|
||
|
||
///设置默认字体
|
||
///fontName: string
|
||
///返回: [err, info]
|
||
Function SetDefaultFont(sheet, fontName);
|
||
Begin
|
||
return xlsx_call("SetDefaultFont", fh_, fontName);
|
||
End;
|
||
|
||
///获取默认字体
|
||
///返回: [err, fontName:string]
|
||
Function GetDefaultFont();
|
||
Begin
|
||
return xlsx_call("GetDefaultFont", fh_);
|
||
End;
|
||
|
||
///添加数据验证
|
||
///sheet: string,工作表名称
|
||
///opt: string,json串
|
||
/// type DataValidation struct {
|
||
/// AllowBlank bool
|
||
/// Error string
|
||
/// ErrorStyle string
|
||
/// ErrorTitle string
|
||
/// Operator string
|
||
/// Prompt string
|
||
/// PromptTitle string
|
||
/// ShowDropDown bool
|
||
/// ShowErrorMessage bool
|
||
/// ShowInputMessage bool
|
||
/// Sqref string
|
||
/// Type string
|
||
/// Formula1 string
|
||
/// Formula2 string
|
||
///}
|
||
///返回: [err, info]
|
||
Function AddDataValidation(sheet, opt);
|
||
Begin
|
||
return xlsx_call("AddDataValidation", fh_, sheet, opt);
|
||
End;
|
||
|
||
///删除数据验证
|
||
///sheet: string,工作表名称
|
||
///sqref: string,数据区域,"A7:B8"
|
||
///返回: [err, info]
|
||
Function DeleteDataValidation(sheet, sqref);
|
||
Begin
|
||
return xlsx_call("DeleteDataValidation", fh_, sheet, sqref);
|
||
End;
|
||
|
||
///创建数据透视表
|
||
///opt: string,json串
|
||
/// type PivotTableField struct {
|
||
/// Compact bool
|
||
/// Data string
|
||
/// Name string
|
||
/// Outline bool
|
||
/// Subtotal string
|
||
/// DefaultSubtotal bool
|
||
///}
|
||
/// type PivotTableOption struct {
|
||
/// pivotTableSheetName string
|
||
/// DataRange string
|
||
/// PivotTableRange string
|
||
/// Rows array of PivotTableField
|
||
/// Columns array of PivotTableField
|
||
/// Data array of PivotTableField
|
||
/// Filter array of PivotTableField
|
||
/// RowGrandTotals bool
|
||
/// ColGrandTotals bool
|
||
/// ShowDrill bool
|
||
/// UseAutoFormatting bool
|
||
/// PageOverThenDown bool
|
||
/// MergeItem bool
|
||
/// CompactData bool
|
||
/// ShowError bool
|
||
/// ShowRowHeaders bool
|
||
/// ShowColHeaders bool
|
||
/// ShowRowStripes bool
|
||
/// ShowColStripes bool
|
||
/// ShowLastColumn bool
|
||
/// PivotTableStyleName string
|
||
///}
|
||
///返回: [err, info]
|
||
Function AddPivottable(opt);
|
||
Begin
|
||
return xlsx_call("AddPivottable", fh_, opt);
|
||
End;
|
||
|
||
///创建表格
|
||
///sheet: string,工作表名称
|
||
///hCell: string,左上角坐标 "A1"
|
||
///vCell: string,右下角坐标 "D5"
|
||
///format: string,json串
|
||
/// type formatTable struct {
|
||
/// TableName string
|
||
/// TableStyle string
|
||
/// ShowFirstColumn bool
|
||
/// ShowLastColumn bool
|
||
/// ShowRowStripes bool
|
||
/// ShowColumnStripes bool
|
||
///}
|
||
///返回: [err, info]
|
||
Function AddTable(sheet, hCell, vCell, format);
|
||
Begin
|
||
return xlsx_call("AddTable", fh_, sheet, hCell, vCell, format);
|
||
End;
|
||
|
||
///自动过滤器
|
||
///sheet: string,工作表名称
|
||
///sheet: string,工作表名称
|
||
///hCell: string,左上角坐标 "A1"
|
||
///vCell: string,右下角坐标 "D5"
|
||
///format: string,json串
|
||
/// type formatAutoFilter struct {
|
||
/// Column string
|
||
/// Expression string
|
||
/// FilterList array of {
|
||
/// Column string
|
||
/// Value array of int
|
||
/// }
|
||
///}
|
||
///返回: [err, info]
|
||
Function AutoFilter(sheet, hCell, vCell, format);
|
||
Begin
|
||
return xlsx_call("AutoFilter", fh_, sheet, hCell, vCell, format);
|
||
End;
|
||
|
||
///清除单元格缓存
|
||
///返回: [err, info]
|
||
Function UpdateLinkedValue();
|
||
Begin
|
||
return xlsx_call("UpdateLinkedValue", fh_);
|
||
End;
|
||
|
||
///单元格坐标切分
|
||
///cell: string,单元格坐标
|
||
///返回: [err, col:string, row:int],"AK47" -> return array(0, "AK", 47);
|
||
Function SplitCellName(cell);
|
||
Begin
|
||
return xlsx_call("SplitCellName", cell);
|
||
End;
|
||
|
||
///单元格坐标组合
|
||
///col: string
|
||
///row: int
|
||
///返回 [err, cell:string],参见SplitCellName
|
||
Function JoinCellName(sheet);
|
||
Begin
|
||
return xlsx_call("JoinCellName", col, row);
|
||
End;
|
||
|
||
///列名转索引
|
||
///name: string
|
||
///返回 [err, index:int],"AK" -> return array(0, 37);
|
||
Function ColumnNameToNumber(name);
|
||
Begin
|
||
return xlsx_call("ColumnNameToNumber", name);
|
||
End;
|
||
|
||
///索引转列名
|
||
///index: int
|
||
///返回 [err, name:string],37 -> return array(0, "AK");
|
||
Function ColumnNumberToName(index);
|
||
Begin
|
||
return xlsx_call("ColumnNumberToName", index);
|
||
End;
|
||
|
||
///单元格坐标转索引
|
||
///cell: string
|
||
///返回 [err, col:int, row: int] "A2" -> [1,2]
|
||
Function CellNameToCoordinates(cell);
|
||
Begin
|
||
return xlsx_call("CellNameToCoordinates", cell);
|
||
End;
|
||
|
||
///索引转单元格坐标
|
||
///col: int
|
||
///row: int
|
||
///abs: bool ,true返回"$A$1"格式,false返回"A1"格式
|
||
///返回 [err, cell:string] [1,2,true] -> "$A$2"
|
||
Function CoordinatesToCellName(col, row, abs);
|
||
Begin
|
||
return xlsx_call("CoordinatesToCellName", col, row, abs);
|
||
End;
|
||
|
||
///创建条件格式样式
|
||
///style: string,样式,参见NewStyle
|
||
///返回: [err, info]
|
||
Function NewConditionalStyle(style);
|
||
Begin
|
||
return xlsx_call("NewConditionalStyle", fh_, style);
|
||
End;
|
||
|
||
///设置条件格式
|
||
///sheet: string,工作表名称
|
||
///area: string,"D1:D10"
|
||
///format: string,json串
|
||
/// type formatConditional struct {
|
||
/// Type string
|
||
/// AboveAverage bool
|
||
/// Percent bool
|
||
/// Format int
|
||
/// Criteria string
|
||
/// Value string
|
||
/// Minimum string
|
||
/// Maximum string
|
||
/// MinType string
|
||
/// MidType string
|
||
/// MaxType string
|
||
/// MinValue string
|
||
/// MidValue string
|
||
/// MaxValue string
|
||
/// MinColor string
|
||
/// MidColor string
|
||
/// MaxColor string
|
||
/// MinLength string
|
||
/// MaxLength string
|
||
/// MultiRange string
|
||
/// BarColor string
|
||
///}
|
||
///返回: [err, info]
|
||
Function SetConditionalFormat(sheet, area, format);
|
||
Begin
|
||
return xlsx_call("SetConditionalFormat", fh_, sheet, area, format);
|
||
End;
|
||
|
||
///删除条件格式
|
||
///sheet: string,工作表名称
|
||
///area: string,"D1:D10"
|
||
///返回: [err, info]
|
||
Function UnSetConditionalFormat(sheet, area);
|
||
Begin
|
||
return xlsx_call("UnSetConditionalFormat", fh_, sheet, area);
|
||
End;
|
||
|
||
///设置窗格
|
||
///sheet: string,工作表名称
|
||
///panes: string,json串
|
||
/// type formatPanes struct {
|
||
/// Freeze bool
|
||
/// Split bool
|
||
/// XSplit int
|
||
/// YSplit int
|
||
/// TopLeftCell string
|
||
/// ActivePane string
|
||
/// Panes array of {
|
||
/// SQRef string
|
||
/// ActiveCell string
|
||
/// Pane string
|
||
/// }
|
||
///}
|
||
///返回: [err, info]
|
||
Function SetPanes(sheet, panes);
|
||
Begin
|
||
return xlsx_call("SetPanes", fh_, sheet, panes);
|
||
End;
|
||
|
||
///色值计算,通过给定的 RGB 格式色值与色调参数,计算出最终颜色。
|
||
///baseColor: string,RGB 格式色值
|
||
///tinit: double
|
||
///返回: [err, color:string],"FF#br#bg#bb"
|
||
Function ThemeColor(baseColor, tint);
|
||
Begin
|
||
return xlsx_call("ThemeColor", baseColor, tint);
|
||
End;
|
||
|
||
///RGB与HSL色彩空间色值转换
|
||
///r: int
|
||
///g: int
|
||
///b: int
|
||
///返回: [err, h:double, s:double, l:double]
|
||
Function RGBToHSL(r, g, b);
|
||
Begin
|
||
return xlsx_call("RGBToHSL", r, g, b);
|
||
End;
|
||
|
||
///HSL与RGB色彩空间色值转换
|
||
///h: double
|
||
///s: double
|
||
///l: double
|
||
///返回: [err, r:int, g:int, b:int]
|
||
Function HSLToRGB(sheet);
|
||
Begin
|
||
return xlsx_call("HSLToRGB", h, s, l);
|
||
End;
|
||
|
||
///嵌入 VBA 项目
|
||
///bin: string,包含函数和/或宏的vba文件
|
||
///返回: [err, info]
|
||
Function AddVbaProject(bin);
|
||
Begin
|
||
return xlsx_call("AddVbaProject", fh_, bin);
|
||
End;
|
||
|
||
///获取总行数
|
||
///sheet: string,工作表名称
|
||
///返回: [err, TotalRows:int]
|
||
Function TotalRows(sheet);
|
||
Begin
|
||
return xlsx_call("TotalRows", fh_, sheet);
|
||
End;
|
||
|
||
///获取总列数
|
||
///sheet: string,工作表名称
|
||
///返回: [err, TotalCols:int]
|
||
Function TotalCols(sheet);
|
||
Begin
|
||
return xlsx_call("TotalCols", fh_, sheet);
|
||
End;
|
||
|
||
///判断单元格数据类型是Unset
|
||
///dataype: int
|
||
///返回: [err, result:bool]
|
||
Function IfUnset(datatye);
|
||
Begin
|
||
if datatype=10 then
|
||
return ture;
|
||
return false;
|
||
End;
|
||
|
||
///判断单元格数据类型是Int
|
||
///dataype: int
|
||
///返回: [err, result:bool]
|
||
Function IfInt(datatye);
|
||
Begin
|
||
if datatype=0 then
|
||
return ture;
|
||
return false;
|
||
End;
|
||
|
||
///判断单元格数据类型是Int64
|
||
///dataype: int
|
||
///返回: [err, result:bool]
|
||
Function IfInt64(datatye);
|
||
Begin
|
||
if datatype=20 then
|
||
return ture;
|
||
return false;
|
||
End;
|
||
|
||
///判断单元格数据类型是Double
|
||
///dataype: int
|
||
///返回: [err, result:bool]
|
||
Function IfNumber(datatye);
|
||
Begin
|
||
if datatype=1 then
|
||
return ture;
|
||
return false;
|
||
End;
|
||
|
||
///判断单元格数据类型是String
|
||
///dataype: int
|
||
///返回: [err, result:bool]
|
||
Function IfString(datatye);
|
||
Begin
|
||
if datatype=2 then
|
||
return ture;
|
||
return false;
|
||
End;
|
||
|
||
///判断单元格数据类型是Date
|
||
///dataype: int
|
||
///返回: [err, result:bool]
|
||
Function IfDate(datatye);
|
||
Begin
|
||
if datatype=3 then
|
||
return ture;
|
||
return false;
|
||
End;
|
||
|
||
///判断单元格数据类型是Error
|
||
///dataype: int
|
||
///返回: [err, result:bool]
|
||
Function IfError(datatye);
|
||
Begin
|
||
if datatype=-1 then
|
||
return ture;
|
||
return false;
|
||
End;
|
||
|
||
///插入数据表
|
||
///sheet: string,工作表名称
|
||
///axis: string,左上角坐标,如: "A4"
|
||
///data: table,数据表
|
||
///IncludeHeader: bool 是否包括表头
|
||
///IncludeIndex: bool
|
||
///返回: [err, info]
|
||
Function InsertTable(sheet, axis, data, IncludeHeader, IncludeIndex);
|
||
Begin
|
||
if not ifarray(data) or length(data)=0 then
|
||
return array(-1, "Invalid Data.");
|
||
if FieldCount(data)=0 then Begin //数据是一维数组
|
||
return SetSheetRow(sheet, axis, data);
|
||
End;
|
||
[err, colNum, rowNum] := CellNameToCoordinates(axis);
|
||
if err then
|
||
return array(err, colNum);
|
||
if IncludeHeader then Begin
|
||
[err, info] := SetSheetRow(sheet, axis, FieldNames(data));
|
||
if err then
|
||
return array(err, info);
|
||
rowNum ++;
|
||
End;
|
||
if IncludeIndex then Begin
|
||
for i:=0 to length(data)-1 do Begin
|
||
[err, cell] := CoordinatesToCellName(colNum, rowNum + i);
|
||
if err then
|
||
return array(err, cell);
|
||
SetCellValue(sheet, cell, i+1);
|
||
End;
|
||
colNum ++;
|
||
End;
|
||
for i:=0 to length(data)-1 do Begin
|
||
[err, cell] := CoordinatesToCellName(colNum, rowNum + i);
|
||
if err then
|
||
return array(err, cell);
|
||
t := sselect * from data where thisrowindex = i End;
|
||
//PrintLn("cell={},data={}->{}",cell, data[i],t);
|
||
[err, info] := SetSheetRow(sheet, cell, t);
|
||
if err then
|
||
return array(err, info);
|
||
End;
|
||
return array(0, "OK");
|
||
End;
|
||
|
||
///读取数据表
|
||
///sheet: string,工作表名称
|
||
///c1: string,左上角坐标,如: "A4"
|
||
///c2: string,右下角坐标,如: "B8",为空获取从c1开始的整张表
|
||
///IncludeHeader: bool 是否包括表头
|
||
///IncludeIndex: bool
|
||
///返回: [err, data:table]
|
||
Function GetTable(sheet, c1, c2, IncludeHeader, IncludeIndex);
|
||
Begin
|
||
r := array();
|
||
fields := array();
|
||
[err, colcount] := TotalCols(sheet);
|
||
if err then
|
||
return array(err, colcount);
|
||
[err, col1, row1] := CellNameToCoordinates(c1);
|
||
if err then
|
||
return array(err, col1);
|
||
if c2="" then Begin
|
||
col2 := colcount;
|
||
[err, row2] := TotalRows(sheet);
|
||
if err then
|
||
return array(err, row2);
|
||
End else Begin
|
||
[err, col2, row2] := CellNameToCoordinates(c2);
|
||
if err then
|
||
return array(err, col2);
|
||
End;
|
||
if col2 > colcount then
|
||
col2 := colcount;
|
||
if IncludeHeader then Begin
|
||
for i:=col1 to col2 do Begin
|
||
[err, cell] := CoordinatesToCellName(i, row1);
|
||
if err then
|
||
return array(err, cell);
|
||
[err, v, datatype] := GetCellValue(sheet, cell);
|
||
if err then
|
||
return array(err, v);
|
||
fields[length(fields)] := v;
|
||
End;
|
||
row1 ++;
|
||
End;
|
||
//echo tostn(array(col1,col2,row1,row2));
|
||
for i:=row1 to row2 do Begin
|
||
if IncludeIndex and IncludeHeader then Begin
|
||
r[cnt]['Index'] := i - row1 + 1;
|
||
End
|
||
else if IncludeIndex then Begin
|
||
r[cnt][0] := i - row1 + 1;
|
||
End;
|
||
for j:=col1 to col2 do Begin
|
||
[err, cell] := CoordinatesToCellName(col1, i);
|
||
if err then
|
||
return array(err, cell);
|
||
[err, v, datatype] := GetCellValue(sheet, cell);
|
||
//echo cell, "->", tostn(array(v, datatype)),"\n";
|
||
if err then
|
||
return array(err, v);
|
||
try
|
||
case datatype of
|
||
0: v := strtoint(v);
|
||
20: v := strtoint(v);
|
||
1,3,10: v := strtofloat(v);
|
||
//-1,2://string,Err
|
||
End;
|
||
except
|
||
End;
|
||
if IncludeHeader then Begin
|
||
r[cnt][ fields[j - col1] ] := v;
|
||
End
|
||
else Begin
|
||
r[cnt][ j - col1 + ifthen(IncludeIndex,1,0)] := v;
|
||
End;
|
||
End;
|
||
cnt++;
|
||
End;
|
||
return array(0, r);
|
||
End;
|
||
End; |