first commit

This commit is contained in:
hans 2022-01-20 12:11:36 +08:00
commit 951d4da7ec
12 changed files with 1977 additions and 0 deletions

1621
ExcelFile.tsf Executable file

File diff suppressed because it is too large Load Diff

BIN
ExcelFile使用帮助.xlsx Executable file

Binary file not shown.

BIN
Linux-aarch64/libTsXlsx.so Executable file

Binary file not shown.

BIN
Linux-aarch64/libtsxlsx_plugin.so Executable file

Binary file not shown.

BIN
Linux-x86_64/libTSSVRAPI.so Executable file

Binary file not shown.

BIN
Linux-x86_64/libTsXlsx.so Executable file

Binary file not shown.

BIN
Linux-x86_64/libtsxlsx_plugin.so Executable file

Binary file not shown.

9
README.md Executable file
View File

@ -0,0 +1,9 @@
1、ExcelFile.tsf 类接口tsl64\funcext\ExcelFile.tsf
2、ExcelFile使用帮助.xlsx
3、插件库Windows-X64、Linux-aarch64、Linux-x86_64
4、demo1: test.tsl
5、demo2: create_excelfile_help.tsl 自动生成《ExcelFile使用帮助.xlsx》文件。

BIN
Windows-X64/TSXlsx_plugin.dll Executable file

Binary file not shown.

BIN
Windows-X64/tsxlsx.dll Executable file

Binary file not shown.

149
create_excelfile_help.tsl Executable file
View File

@ -0,0 +1,149 @@
funcs := LoadClassInfo("ExcelFile.tsf");
file := CreateObject("ExcelFile");
[err, errinfo] := file.NewFile();
if err then
return println("errorno={},errinfo={}", err, errinfo);
[err, errinfo] := file.SetSheetName("Sheet1","ExcelFile");
if err then
return println("errorno={},errinfo={}", err, errinfo);
[err, errinfo] := file.NewSheet("Functions");
if err then
return println("errorno={},errinfo={}", err, errinfo);
[err, errinfo] := file.SetCellRichText("ExcelFile", "A1", '[{"Font":{"bold":true,"italic":false,"underline":"none","family":"华文彩云","size":48,"strike":false,"color":"A020F0"},"Text":"ExcelFile类"},{"Font":{"bold":true,"italic":false,"underline":"none","family":"华文行楷","size":36,"strike":false,"color":"FF0000"},"Text":"使用帮助"}]');
if err then
return println("errorno={},errinfo={}", err, errinfo);
//合并单元格
[err, errinfo] := file.MergeCell("ExcelFile", "A1", "C1");
if err then
return println("errorno={},errinfo={}", err, errinfo);
//创建样式
[err, style] := file.NewStyle('{"Border":[{"Type": "left", "Color": "FF0000", "Style": 6},
{"Type": "top", "Color": "FF0000", "Style": 6},
{"Type": "bottom", "Color": "FF0000", "Style": 6},
{"Type": "right", "Color": "FF0000", "Style": 6}],
"Fill":{"Type": "gradient", "Color": ["#FFFFFF", "#E0EBF5"], "Shading": 1},
"Alignment":{"Horizontal":"center","Vertical":"center"}
}');
if err then
return println("errorno={},errinfo={}", err, style);
//设置样式
[err, errinfo] := file.SetCellStyle("ExcelFile", "A1", "C1", style);
if err then
return println("errorno={},errinfo={}", err, errinfo);
file.SetCellValue("ExcelFile", "A3", "索引");
file.SetCellValue("ExcelFile", "B3", "函数名称");
file.SetCellValue("ExcelFile", "C3", "功能");
file.SetColWidth("ExcelFile","A", "A", 6);
file.SetColWidth("ExcelFile","B", "B", 42);
file.SetColWidth("ExcelFile","C", "C", 100);
file.SetCellStyle("ExcelFile","A3","C3",style);
file.SetColWidth("Functions","A", "A", 150);
//创建样式2
[err, style2] := file.NewStyle('{"Font":{"Color": "A020F0", "Bold": true, "Size": 12, "Family": "Microsoft YaHei"},
"Fill":{"Type": "pattern", "Color":["#EFEFEF"], "Pattern":1},
"Alignment":{"WrapText":true}
}');
if err then
return println("errorno={},errinfo={}", err, style2);
[err, style3] := file.NewStyle('{"Font":{"Color": "1f7f3b", "Size": 9, "Family": "Microsoft YaHei"},
"Fill":{"Type": "pattern", "Color":["#EFEFEF"], "Pattern":1},
"Alignment":{"WrapText":true}
}');
if err then
return println("errorno={},errinfo={}", err, style3);
//设置超链接下划线
[err, style4] := file.NewStyle('{"Font":{"Color":"A020F0", "Underline": "single"}}');//设置字体、格式
if err then
return println("NewStyle:errorno={},errinfo={}", err, style);
row := 1;
for i:=0 to length(funcs)-1 do begin
[err, cell0] := file.CoordinatesToCellName(1, i+4);
[err, cell1] := file.CoordinatesToCellName(2, i+4);
[err2, cell2] := file.CoordinatesToCellName(3, i+4);
file.SetCellValue("ExcelFile",cell0,i + 1);
file.SetCellValue("ExcelFile",cell1,funcs[i]['funcname']);
file.SetCellValue("ExcelFile",cell2,funcs[i]['name']);
str := funcs[i]['name'] + "\nFunction " + funcs[i]['funcname'] + funcs[i]['comment'];
arr := str2array(str,"\n");
[err, c1] := file.CoordinatesToCellName(1, row);
[err, c3] := file.CoordinatesToCellName(1, row+length(arr)-1);
file.SetCellStyle("Functions",c1,c3,style3);
file.SetCellStyle("Functions",c1,c1,style2);
for j:=0 to length(arr)-1 do begin
[err, c] := file.CoordinatesToCellName(1, row++);
file.SetCellValue("Functions",c,arr[j]);
end;
row++;
//设置超链接
[err, errinfo] := file.SetCellHyperLink("ExcelFile", cell1, "Functions!"$c1, "Location");
if err then
return println("SetCellHyperLink:errorno={},errinfo={}", err, errinfo);
[err, errinfo] := file.SetCellStyle("ExcelFile", cell1, cell1, style4);
if err then
return println("SetCellStyle:errorno={},errinfo={}", err, errinfo);
End;
[err, errinfo] := file.SaveAs("", "ExcelFile使用帮助.xlsx");
if err then
return println("errorno={},errinfo={}", err, errinfo);
println("Create ExcelFile使用帮助.xlsx File.");
function LoadClassInfo(f);
Begin
t := array();
[err,fh] := io_open(f);
if err then return t;
[err, data] := io_read(fh);
io_close(fh);
if err then return t;
lines := str2array(string(data), "\n");
for i:=0 to length(lines)-1 do begin
line := lines[i];
str := " End;";
if leftstr(line, length(str)) = str then Begin
if funcname <> "" and leftstr(funcname,7) <> "Create(" and leftstr(funcname,8) <> "Destory(" then Begin
n := length(t);
t[n]['funcname'] := funcname;
t[n]['comment'] := comment;
t[n]['name'] := name;
End;
funcname := "";
comment := "";
name := "";
begF := 0;
endF := 1;
continue;
End;
func := " Function ";
if leftstr(line, length(func)) = func then Begin
funcname := rightstr(line, length(line)-length(func));
begF := 1;
continue;
End;
if endF=0 or begF then continue;
if ParseRegExpr("\/\/\/(.*)$",line,"",result,MPos,Mlen) and length(result) then Begin
str := result[0][1];
if name="" then begin
name := str;
continue;
end;
comment := comment + "\n " + str;
End;
End;
return t;
End;

198
test.tsl Executable file
View File

@ -0,0 +1,198 @@
file := CreateObject("ExcelFile");//创建ExcelFile对象
[err, errinfo] := file.NewFile();//新建Excel文件文件格式默认为GBK
if err then
return println("NewFile: errorno={},errinfo={}", err, errinfo);
testing := 1;
PrintLn( "Test {} [创建ExcelFile] Ok...", testing++);
//富文本
[err, errinfo] := file.SetCellRichText("Sheet1", "A1", '[{"Font":{"bold":true,"italic":false,"underline":"none","family":"华文行楷","size":26,"strike":false,"color":"FF0000"},"Text":"深圳市"},{"Font":{"bold":true,"italic":false,"underline":"none","family":"华文行楷","size":48,"strike":false,"color":"A020F0"},"Text":"天软"},{"Font":{"bold":true,"italic":false,"underline":"none","family":"华文行楷","size":26,"strike":false,"color":"FF0000"},"Text":"科技开发有限公司"}]');
if err then
return println("SetCellRichText:errorno={},errinfo={}", err, errinfo);
PrintLn( "Test {} [富文本] Ok...", testing++);
//[err, txt] := file.GetCellRichText("Sheet1", "A1");
//合并单元格
[err, errinfo] := file.MergeCell("Sheet1", "A1", "J1");
if err then
return println("MergeCell:errorno={},errinfo={}", err, errinfo);
PrintLn( "Test {} [合并单元格] Ok...", testing++);
//创建样式
[err, style] := file.NewStyle('{"Border":[{"Type": "left", "Color": "FF0000", "Style": 6},
{"Type": "top", "Color": "FF0000", "Style": 6},
{"Type": "bottom", "Color": "FF0000", "Style": 6},
{"Type": "right", "Color": "FF0000", "Style": 6}],
"Fill":{"Type": "gradient", "Color": ["#FFFFFF", "#E0EBF5"], "Shading": 1},
"Alignment":{"Horizontal":"center","Vertical":"center"}
}');
if err then
return println("NewStyle:errorno={},errinfo={}", err, style);
PrintLn( "Test {} [创建样式] Ok...", testing++);
//设置样式
[err, errinfo] := file.SetCellStyle("Sheet1", "A1", "J1", style);
if err then
return println("SetCellStyle:errorno={},errinfo={}", err, errinfo);
PrintLn( "Test {} [设置样式] Ok...", testing++);
//设置单元格值
[err, errinfo] := file.SetCellValue("Sheet1","A3","http://www.tinysoft.com.cn");
if err then
return println("SetCellValue:errorno={},errinfo={}", err, errinfo);
PrintLn( "Test {} [设置单元格值] Ok...", testing++);
//设置超链接
[err, errinfo] := file.SetCellHyperLink("Sheet1", "A3", "http://www.tinysoft.com.cn", "External");
if err then
return println("SetCellHyperLink:errorno={},errinfo={}", err, errinfo);
PrintLn( "Test {} [设置超链接] Ok...", testing++);
//设置超链接下划线
[err, style] := file.NewStyle('{"Font":{"Color":"A020F0", "Underline": "single"}, "Alignment":{"Horizontal":"center","Vertical":"center"}}');//设置字体、格式
if err then
return println("NewStyle:errorno={},errinfo={}", err, style);
[err, errinfo] := file.SetCellStyle("Sheet1", "A3", "A3", style);
if err then
return println("SetCellStyle:errorno={},errinfo={}", err, errinfo);
PrintLn( "Test {} [设置超链接下划线] Ok...", testing++);
//合并单元格
[err, errinfo] := file.MergeCell("Sheet1", "A3", "J3");
if err then
return println("MergeCell:errorno={},errinfo={}", err, errinfo);
PrintLn( "Test {} [合并单元格] Ok...", testing++);
//插入数据表
data := array(("Name":"Small","Apple":2,"Orange":3,"Pear":3),
("Name":"Normal","Apple":5,"Orange":2,"Pear":4),
("Name":"Large","Apple":6,"Orange":7,"Pear":8));
[err, errinfo] := file.InsertTable("Sheet1","A5",data, true);
if err then
return println("InsertTable:errorno={},errinfo={}", err, errinfo);
PrintLn( "Test {} [插入数据表] Ok...", testing++);
//获取数据表
[err, r] := file.GetTable("Sheet1","B6","C7");
if err then
return println("GetTable:errorno={},errinfo={}", err, r);
PrintLn( "Test {} [获取数据表] Ok...{}", testing++, r);
//插入柱状图
opts := '{
"type": "col",
"series": [
{
"name": "Sheet1!$A$6",
"categories": "Sheet1!$B$5:$D$5",
"values": "Sheet1!$B$6:$D$6"
},
{
"name": "Sheet1!$A$7",
"categories": "Sheet1!$B$5:$D$5",
"values": "Sheet1!$B$7:$D$7"
},
{
"name": "Sheet1!$A$8",
"categories": "Sheet1!$B$5:$D$5",
"values": "Sheet1!$B$8:$D$8"
}],
"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": "Fruit 2D Column Chart"
},
"plotarea":
{
"show_bubble_size": true,
"show_cat_name": false,
"show_leader_lines": false,
"show_percent": true,
"show_series_name": true,
"show_val": true
},
"show_blanks_as": "zero"
}';
[err, r] := file.AddChart("Sheet1","A10",opts);
if err then
return println("AddChart:errorno={},errinfo={}", err, r);
PrintLn( "Test {} [插入柱状图] Ok...{}", testing++, r);
//插入三维饼图
opts := '{
"type": "pie3D",
"series": [
{
"name": "Sheet1!$A$6",
"categories": "Sheet1!$B$5:$D$5",
"values": "Sheet1!$B$6:$D$6"
}],
"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": "bottom",
"show_legend_key": false
},
"title":
{
"name": "Fruit 3D Pie Chart"
},
"plotarea":
{
"show_bubble_size": true,
"show_cat_name": false,
"show_leader_lines": false,
"show_percent": true,
"show_series_name": false,
"show_val": false
},
"show_blanks_as": "zero"
}';
[err, r] := file.AddChart("Sheet1","I10",opts);
if err then
return println("AddChart:errorno={},errinfo={}", err, r);
PrintLn( "Test {} [插入三维饼图] Ok...{}", testing++, r);
//插入表格
[err, r] := file.AddTable("Sheet1", "L2", "P6", '{
"table_name": "table",
"table_style": "TableStyleMedium2",
"show_first_column": true,
"show_last_column": true,
"show_row_stripes": false,
"show_column_stripes": true
}');
if err then
return println("AddTable:errorno={},errinfo={}", err, r);
PrintLn( "Test {} [插入表格] Ok...{}", testing++, r);
//save文件
[err, errinfo] := file.SaveAs("", "test.xlsx");
if err then
return println("SaveAs: errorno={},errinfo={}", err, errinfo);
PrintLn( "Test {} [SaveAs] Ok...", testing++);
PrintLn( "Test All Ok!" );