149 lines
5.2 KiB
Plaintext
Executable File
149 lines
5.2 KiB
Plaintext
Executable File
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; |