release 1.0
This commit is contained in:
@@ -0,0 +1,726 @@
|
||||
path := ExtractFileDir(ExtractFileDir(PluginPath()));
|
||||
{$IFNDEF Win32}
|
||||
path := path + '\\funcext\\TSOffice\\TSExcelFile.tsf';
|
||||
{$ELSE}
|
||||
path := path + '/funcext/TSOffice/TSExcelFile.tsf';
|
||||
{$ENDIF}
|
||||
funcs := LoadClassInfo(path);
|
||||
|
||||
testing := 1;
|
||||
file := new TSExcelFile();
|
||||
[err, errinfo] := file.NewFile();
|
||||
if err then
|
||||
return PrintError("NewFile", err, errinfo);
|
||||
PrintSuccess("NewFile", testing++);
|
||||
|
||||
[err, errinfo] := file.SetSheetName('Sheet1', 'ExcelFile');
|
||||
if err then
|
||||
return PrintError("SetSheetName", err, errinfo);
|
||||
PrintSuccess("SetSheetName", testing++);
|
||||
|
||||
[err, errinfo] := file.NewSheet("Functions");
|
||||
if err then
|
||||
return PrintError("NewSheet", err, errinfo);
|
||||
PrintSuccess("NewSheet", testing++);
|
||||
|
||||
file.SetDefaultSheet('ExcelFile');
|
||||
|
||||
richtext := TOfficeObj('TRichText');
|
||||
txt1 := richtext.AddText('TSExcelFile类 ');
|
||||
txt1.Font.Size := 35;
|
||||
txt1.Font.Color := "FF0000";
|
||||
txt1.Font.Bold := 1;
|
||||
txt1.Font.Name := "华文彩云";
|
||||
txt2 := richtext.AddText('帮助文档');
|
||||
txt2.Font.Size := 30;
|
||||
txt2.Font.Name := "微软雅黑";
|
||||
txt2.Font.Bold := 1;
|
||||
txt2.Font.Italic := 1;
|
||||
txt2.Font.Color := "FFC0CB";
|
||||
|
||||
file.SetCellRichText('ExcelFile', 'A1', richtext);
|
||||
PrintSuccess("SetCellRichText", testing++);
|
||||
[err, richText] := file.GetCellRichText('ExcelFile', 'A1');
|
||||
if err then
|
||||
return PrintError("GetCellRichText", err, errinfo);
|
||||
PrintSuccess("GetCellRichText", testing++);
|
||||
|
||||
file.MergeCell('ExcelFile', 'A1', 'C1');
|
||||
PrintSuccess("MergeCell", testing++);
|
||||
|
||||
|
||||
style := TOfficeObj('TStyle');
|
||||
style.Border.Left.LineStyle := "double";
|
||||
style.Border.Left.Color := "FF0000";
|
||||
style.Border.Right.LineStyle := "double";
|
||||
style.Border.Right.Color := "FF0000";
|
||||
style.Border.Bottom.LineStyle := "double";
|
||||
style.Border.Bottom.Color := "FF0000";
|
||||
style.Border.Top.LineStyle := "double";
|
||||
style.Border.Top.Color := "FF0000";
|
||||
style.Alignment.Horizontal := "center";
|
||||
style.Alignment.Vertical := "center";
|
||||
style.Fill.Gradient.Shading := 3;
|
||||
style.Fill.Gradient.Color1 := "FFFFFF";
|
||||
style.Fill.Gradient.Color2 := "E0EBF5";
|
||||
|
||||
styleId := file.NewStyle(style);
|
||||
PrintSuccess("NewStyle", testing++);
|
||||
|
||||
file.SetCellStyle("ExcelFile", 'A1', 'C1', styleId);
|
||||
|
||||
file.SetCellValue("ExcelFile", "A3", "索引");
|
||||
file.SetCellValue("ExcelFile", "B3", "函数名称");
|
||||
file.SetCellValue("ExcelFile", "C3", "功能");
|
||||
file.SetColWidth("ExcelFile", "A", "A", 6);
|
||||
file.SetColWidth("ExcelFile", "B", "B", 55);
|
||||
file.SetColWidth("ExcelFile", "C", "C", 100);
|
||||
file.SetCellStyle("ExcelFile", "A3", "C3", styleId);
|
||||
|
||||
|
||||
style2 := TOfficeObj("TStyle");
|
||||
style2.Font.Color := "A020F0";
|
||||
style2.Font.Bold := true;
|
||||
style2.Font.Size := 12;
|
||||
style2.Font.Name := "Microsoft YaHei";
|
||||
style2.Fill.Pattern.PatternType := "solid";
|
||||
style2.Fill.Pattern.ForegroundColor := "EFEFEF";
|
||||
style2.Alignment.WrapText := true;
|
||||
styleId2 := file.NewStyle(style2);
|
||||
|
||||
style3 := TOfficeObj("TStyle");
|
||||
style3.Font.Color := "1F7F3B";
|
||||
style3.Font.Size := 9;
|
||||
style3.Font.Name := "Microsoft YaHei";
|
||||
style3.Fill.Pattern.PatternType := "solid";
|
||||
style3.Fill.Pattern.ForegroundColor := "FFFAFA";
|
||||
style3.Alignment.WrapText := true;
|
||||
styleId3 := file.NewStyle(style3);
|
||||
|
||||
style4 := TOfficeObj("TStyle");
|
||||
style4.Font.Color := "A020F0";
|
||||
style4.Font.UnderLine := "single";
|
||||
styleId4 := file.NewStyle(style4);
|
||||
|
||||
hash := AddTOfficeObj(file);
|
||||
|
||||
row := 1;
|
||||
for i:=0 to length(funcs)-1 do
|
||||
Begin
|
||||
[err0, cell0] := file.CoordinatesToCellName(1, i+4);
|
||||
[err1, 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, c2] := file.CoordinatesToCellName(1, row + length(arr) - 1);
|
||||
file.SetCellStyle("Functions", c1, c1, styleId2);
|
||||
file.SetCellStyle("Functions", c1, c2, styleId3);
|
||||
|
||||
for j:=0 to length(arr)-1 do
|
||||
Begin
|
||||
[err, c] := file.CoordinatesToCellName(1, row++);
|
||||
file.SetCellValue("Functions", c, arr[j]);
|
||||
End
|
||||
row++;
|
||||
|
||||
hyperlink := TOfficeObj('THyperLink');
|
||||
hyperlink.LinkType := "Location";
|
||||
hyperlink.LinkUrl := "Functions!" $ c1;
|
||||
|
||||
file.SetCellHyperLink("ExcelFile", cell1, hyperlink);
|
||||
file.SetCellStyle("ExcelFile", cell1, cell1, styleId4);
|
||||
|
||||
End
|
||||
|
||||
file.SetColWidth('Functions', 'A', 'A', 120);
|
||||
PrintSuccess('SetColWidth', testing++);
|
||||
|
||||
saveName := utf8toansi("d:\\temp\\ExcelFile使用帮助.xlsx");
|
||||
[err, errinfo] := file.SaveAs('', saveName);
|
||||
if err then
|
||||
return PrintError("SaveAs", err, errinfo);
|
||||
PrintSuccess("SaveAs", testing++);
|
||||
|
||||
|
||||
|
||||
// ============================================================
|
||||
Function PrintError(msg, errno, errinfo);
|
||||
Begin
|
||||
return println("{} : errorno = {}, errorinfo = {}!", msg, errno, errinfo);
|
||||
End
|
||||
|
||||
Function PrintSuccess(msg, time);
|
||||
Begin
|
||||
println("Test {} [{} success]", time, msg);
|
||||
End
|
||||
|
||||
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];
|
||||
if AnsiContainsText(line, 'private') then break;
|
||||
str := " End;";
|
||||
if leftstr(line, length(str)) = str then Begin
|
||||
//if funcname <> "" and leftstr(funcname,7) <> "Create(" and leftstr(funcname,8) <> "Destory(" then Begin
|
||||
if flag and funcname <> "" 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;
|
||||
flag := 0;
|
||||
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
|
||||
flag := 1;
|
||||
str := result[0][1];
|
||||
if name="" then begin
|
||||
name := str;
|
||||
continue;
|
||||
end;
|
||||
comment := comment + "\n " + str;
|
||||
End;
|
||||
End;
|
||||
return t;
|
||||
End;
|
||||
|
||||
Function AddTOfficeObj(excel);
|
||||
Begin
|
||||
hash := array();
|
||||
sheet_name := "TOfficeObj说明";
|
||||
excel.NewSheet(sheet_name);
|
||||
excel.SetColWidth(sheet_name, 'A', 'A', 32);
|
||||
excel.SetColWidth(sheet_name, 'B', 'B', 25);
|
||||
excel.SetColWidth(sheet_name, 'C', 'C', 30);
|
||||
excel.SetColWidth(sheet_name, 'D', 'D', 35);
|
||||
|
||||
style := TOfficeObj('TStyle');
|
||||
style.Alignment.Horizontal := "center";
|
||||
style.Alignment.WrapText := True;
|
||||
style.Font.Name := "Microsoft YaHei";
|
||||
style.Font.Color := "E10D4F";
|
||||
style.Font.Size := 14;
|
||||
style.Font.Bold := True;
|
||||
style.Font.UnderLine := 'singleAccounting';
|
||||
style.Fill.Gradient.Shading := 16;
|
||||
style.Fill.Gradient.Color1 := 'A3ECFB';
|
||||
style.Fill.Gradient.Color2 := '626AD8';
|
||||
styleid1 := excel.NewStyle(style);
|
||||
|
||||
style := TOfficeObj('TStyle');
|
||||
style.Font.Name := "Microsoft YaHei";
|
||||
style.Font.ThemeColor := "8";
|
||||
style.Font.Size := 10;
|
||||
style.Font.Bold := True;
|
||||
style.Alignment.WrapText := True;
|
||||
style.Fill.Pattern.PatternType := 'lightGrid';
|
||||
style.Fill.Pattern.ForegroundThemeColor := 4;
|
||||
style.Fill.Pattern.ForegroundThemeColorTint := 0.8;
|
||||
style.Fill.Pattern.BackgroundThemeColor := 9;
|
||||
style.Fill.Pattern.BackgroundThemeColorTint := 0.8;
|
||||
styleid2 := excel.NewStyle(style);
|
||||
|
||||
style := TOfficeObj('TStyle');
|
||||
style.Font.Name := "Consolas";
|
||||
style.Font.ThemeColor := "1";
|
||||
style.Font.Size := 10;
|
||||
style.Alignment.WrapText := True;
|
||||
style.Alignment.Horizontal := 'left';
|
||||
style.Alignment.Vertical := 'center';
|
||||
style.Fill.Pattern.PatternType := "solid";
|
||||
style.Fill.Pattern.ForegroundThemeColor := 6;
|
||||
style.Fill.Pattern.ForegroundThemeColorTint := 0.8;
|
||||
style.Fill.Pattern.BackgroundThemeColor := 0;
|
||||
styleid3 := excel.NewStyle(style);
|
||||
|
||||
style := TOfficeObj("TStyle");
|
||||
style.Font.Color := "";
|
||||
style.Font.Size := 9;
|
||||
style.Font.Name := "Microsoft YaHei";
|
||||
style.Fill.Pattern.PatternType := "solid";
|
||||
style.Fill.Pattern.ForegroundColor := "FFFAFA";
|
||||
style.Alignment.WrapText := true;
|
||||
style.Border.Left.LineStyle := "dotted";
|
||||
style.Border.Right.LineStyle := "dotted";
|
||||
style.Border.Top.LineStyle := "dotted";
|
||||
style.Border.Bottom.LineStyle := "dotted";
|
||||
styleId4 := excel.NewStyle(style);
|
||||
|
||||
style := TOfficeObj("TStyle");
|
||||
style.Font.Color := "000000";
|
||||
style.Font.Size := 12;
|
||||
style.Font.Name := "Consolas";
|
||||
style.Font.Bold := True;
|
||||
style.Alignment.WrapText := true;
|
||||
style.Alignment.Vertical := "top";
|
||||
styleId5 := excel.NewStyle(style);
|
||||
style.Font.Bold := False;
|
||||
style.Font.Size := 11;
|
||||
style.Font.Color := "757575";
|
||||
styleId6 := excel.NewStyle(style);
|
||||
|
||||
style := TOfficeObj("TStyle");
|
||||
style.Font.Size := 11;
|
||||
style.Font.Name := "Microsoft YaHei";
|
||||
style.Font.Color := "000000";
|
||||
style.Alignment.WrapText := True;
|
||||
style.Alignment.Vertical := "top";
|
||||
styleId7 := excel.NewStyle(style);
|
||||
|
||||
style := TOfficeObj("TStyle");
|
||||
style.Font.Size := 11;
|
||||
style.Font.Name := "幼圆";
|
||||
style.Font.Color := "502447";
|
||||
style.Font.Bold := True;
|
||||
style.Fill.Pattern.PatternType := "solid";
|
||||
style.Fill.Pattern.ForegroundThemeColor := 9;
|
||||
style.Fill.Pattern.ForegroundThemeColorTint := 0.6;
|
||||
style.Fill.Pattern.BackgroundThemeColor := 0;
|
||||
styleId8 := excel.NewStyle(style);
|
||||
|
||||
col := 1;
|
||||
row := 1;
|
||||
merge_span := 3;
|
||||
obj_info := getObjInfo();
|
||||
for i:=0 to length(obj_info)-1 do
|
||||
begin
|
||||
name := obj_info[i]['ObjName'];
|
||||
[err, cell_1] := excel.CoordinatesToCellName(col, row);
|
||||
[err, cell_2] := excel.CoordinatesToCellName(col+merge_span, row);
|
||||
hash[name] := cell_1;
|
||||
excel.SetCellValue(sheet_name, cell_1, name);
|
||||
excel.MergeCell(sheet_name, cell_1, cell_2);
|
||||
excel.SetCellStyle(sheet_name, cell_1, cell_2, styleid1);
|
||||
row++;
|
||||
|
||||
desc_arr := obj_info[i]['Desc'];
|
||||
for j:=0 to length(desc_arr)-1 do
|
||||
begin
|
||||
[err, cell1] := excel.CoordinatesToCellName(col, row);
|
||||
[err, cell2] := excel.CoordinatesToCellName(col+merge_span, row);
|
||||
excel.MergeCell(sheet_name, cell1, cell2);
|
||||
[err, cell_3] := excel.CoordinatesToCellName(col, row);
|
||||
height := length(desc_arr[j]) < 120 ? 15 : length(desc_arr[j])/120*15;
|
||||
excel.SetRowHeight(sheet_name, row, height);
|
||||
excel.SetCellValue(sheet_name, cell_3, desc_arr[j]);
|
||||
row++;
|
||||
end
|
||||
[err, cell3] := excel.CoordinatesToCellName(col, row - 1);
|
||||
excel.SetCellStyle(sheet_name, cell1, cell3, styleid2);
|
||||
|
||||
count := 1;
|
||||
attr_arr := obj_info[i]['AttrInfo'];
|
||||
if not istable(attr_arr) then attr_arr := array();
|
||||
for k:=0 to length(attr_arr)-1 do
|
||||
begin
|
||||
if k = 0 then
|
||||
begin
|
||||
[err, cell1] := excel.CoordinatesToCellName(col, row);
|
||||
[err, cell2] := excel.CoordinatesToCellName(col+3, row);
|
||||
excel.SetSheetRow(sheet_name, cell1, array("属性", "类型", "说明", "取值"));
|
||||
excel.SetCellStyle(sheet_name, cell1, cell2, styleId8);
|
||||
row++;
|
||||
end
|
||||
if attr_arr[k]['attrName'] then
|
||||
begin
|
||||
insert_col := col;
|
||||
[err, cell_2] := excel.CoordinatesToCellName(insert_col, row);
|
||||
excel.SetCellValue(sheet_name, cell_2, attr_arr[k]['attrName']);
|
||||
excel.SetCellStyle(sheet_name, cell_2, cell_2, styleid5);
|
||||
insert_col++;
|
||||
|
||||
[err, cell_2] := excel.CoordinatesToCellName(insert_col, row);
|
||||
excel.SetCellValue(sheet_name, cell_2, attr_arr[k]['type']);
|
||||
excel.SetCellStyle(sheet_name, cell_2, cell_2, styleId6);
|
||||
insert_col++;
|
||||
|
||||
[err, cell_2] := excel.CoordinatesToCellName(insert_col, row);
|
||||
desc_str := attr_arr[k]['desc'];
|
||||
if desc_str and ParseRegExpr("{(.*?)}", desc_str, "", result, mpos, mlen) then
|
||||
begin
|
||||
richText := TOfficeObj('TRichText');
|
||||
position := 1;
|
||||
for index := 0 to length(result)-1 do
|
||||
begin
|
||||
s1 := "";
|
||||
endposition := mpos[index][0];
|
||||
if endposition > 1 then
|
||||
begin
|
||||
s1 := desc_str[position: endposition-1];
|
||||
t1 := richText.AddText(s1);
|
||||
end
|
||||
s2 := result[index][1];
|
||||
position += length(s1) + mlen[index][0];
|
||||
t2 := richText.AddText(s2);
|
||||
t2.Font.Bold := True;
|
||||
end
|
||||
if position - 1 < length(desc_str) then t3 := richText.AddText(desc_str[position:]);
|
||||
excel.SetCellRichText(sheet_name, cell_2, richText);
|
||||
excel.SetCellStyle(sheet_name, cell_2, cell_2, styleId7);
|
||||
end
|
||||
insert_col++;
|
||||
|
||||
value_arr := attr_arr[k]['value'];
|
||||
if istable(value_arr) then
|
||||
begin
|
||||
value_str := array2str(value_arr, "\r\n");
|
||||
[err, cell_2] := excel.CoordinatesToCellName(insert_col, row);
|
||||
excel.SetCellValue(sheet_name, cell_2, value_str);
|
||||
excel.SetCellStyle(sheet_name, cell_2, cell_2, styleId4);
|
||||
end
|
||||
end
|
||||
else if attr_arr[k]['desc'] then
|
||||
begin
|
||||
[err, cell1] := excel.CoordinatesToCellName(col, row);
|
||||
[err, cell2] := excel.CoordinatesToCellName(col+merge_span, row);
|
||||
excel.MergeCell(sheet_name, cell1, cell2);
|
||||
desc_str := attr_arr[k]['desc'];
|
||||
if ParseRegExpr("{(.*?)}", desc_str, "", result, mpos, mlen) then
|
||||
begin
|
||||
richText := TOfficeObj('TRichText');
|
||||
position := 1;
|
||||
for index := 0 to length(result)-1 do
|
||||
begin
|
||||
s1 := "";
|
||||
endposition := mpos[index][0];
|
||||
if endposition > 1 then
|
||||
begin
|
||||
s1 := desc_str[position: endposition-1];
|
||||
t1 := richText.AddText(s1);
|
||||
end
|
||||
s2 := result[index][1];
|
||||
position += length(s1) + mlen[index][0];
|
||||
t2 := richText.AddText(s2);
|
||||
t2.Font.Bold := True;
|
||||
end
|
||||
if position - 1 <= length(desc_str) then t3 := richText.AddText(desc_str[position:]);
|
||||
excel.SetCellRichText(sheet_name, cell1, richText);
|
||||
end
|
||||
end
|
||||
|
||||
row++;
|
||||
end
|
||||
|
||||
demo_str := trim(obj_info[i]['Demo']);
|
||||
if demo_str <> '' then
|
||||
begin
|
||||
demo_arr := str2array(demo_str);
|
||||
for demo_index := 0 to length(demo_arr)-2 do
|
||||
begin
|
||||
[err, cell_name] := excel.CoordinatesToCellName(col, row);
|
||||
[err, cell2] := excel.CoordinatesToCellName(col, row);
|
||||
[err, cell_name2] := excel.CoordinatesToCellName(col + merge_span, row);
|
||||
excel.SetCellValue(sheet_name, cell_name, demo_arr[demo_index]);
|
||||
excel.MergeCell(sheet_name, cell_name, cell_name2);
|
||||
excel.SetCellStyle(sheet_name, cell_name, cell2, styleid3);
|
||||
row++;
|
||||
end
|
||||
end
|
||||
|
||||
row ++;
|
||||
end
|
||||
|
||||
return hash;
|
||||
|
||||
End
|
||||
|
||||
Function getObjInfo();
|
||||
Begin
|
||||
richTextDemo := "
|
||||
richText := TOfficeObj('TRichText');
|
||||
text1 := richText.AddText('Hello');
|
||||
text1.Font.Size := 35;
|
||||
text1.Font.Color := 'FF0000';
|
||||
text2 := richText.AddText('World');
|
||||
text2.Font.Size := 35;
|
||||
text2.Font.Bold := true;
|
||||
";
|
||||
styleDemo := "
|
||||
style := TOfficeObj('TStyle');
|
||||
style.Font.Color := 'A020F0';
|
||||
style.Font.Size := 22;
|
||||
style.Font.Name := '黑体';
|
||||
style.Font.Bold := True;
|
||||
style.Font.Charset := '134';
|
||||
style.Font.Script := 'subscript';
|
||||
style.Font.Underline := 'double';
|
||||
style.Font.Strikethrough := True;
|
||||
style.Font.Italic := True;
|
||||
style.Alignment.Horizontal := 'center';
|
||||
style.Alignment.Vertical := 'justify';
|
||||
style.Alignment.WrapText := True;
|
||||
style.Alignment.ReadingOrder := 2;
|
||||
style.Border.Left.LineStyle := 'thin';
|
||||
style.Border.Left.Color := 'A020F0';
|
||||
style.Border.Right.LineStyle := 'thin';
|
||||
style.Border.Right.Color := 'FF0000';
|
||||
style.Border.Bottom.LineStyle := 'mediumDashed';
|
||||
style.Border.Bottom.Color := 'FF0000';
|
||||
style.Border.Top.LineStyle := 'mediumDashed';
|
||||
style.Border.Top.Color := 'FF0000';
|
||||
style.Border.DiagonalDown := True;
|
||||
style.Border.DiagonalUp := True;
|
||||
style.Border.Diagonal.LineStyle := 'double';
|
||||
style.Border.Diagonal.Color := 'A020F0';
|
||||
style.NumberFormat.FormatCode := '#,##0.000_ ';
|
||||
//style.Fill.Pattern.PatternType := 'solid';
|
||||
//style.Fill.Pattern.ForegroundColor := 'FF6699FF';
|
||||
//style.Fill.Pattern.BackgroundColor := 'FFFF0000';
|
||||
style.Fill.Gradient.ThemeColor1 := 0;
|
||||
style.Fill.Gradient.ThemeColor2 := 4;
|
||||
style.Fill.Gradient.Shading := 1;
|
||||
style.Protection.Hide := 1;
|
||||
style.Protection.Lock := 1;
|
||||
";
|
||||
|
||||
return array(
|
||||
('ObjName': 'TRichText',
|
||||
'Desc': ('富文本在使用时需要先用AddText方法添加一段文本,再对本段文本的字体样式(TFont)进行设置'),
|
||||
'Demo': richTextDemo
|
||||
),
|
||||
('ObjName': 'TStyle',
|
||||
'Desc': ('TStyle有以下属性: '),
|
||||
'AttrInfo': (
|
||||
('attrName': 'NumberFormat', 'type': 'class - TNumFmts', 'desc': '数字样式', 'value': array()),
|
||||
('attrName': 'Alignment', 'type': 'class - TAlignmenth', 'desc': '对齐样式', 'value': array()),
|
||||
('attrName': 'Font', 'type': 'class - TFont', 'desc': '字体样式', 'value': array()),
|
||||
('attrName': 'Border', 'type': 'class - TBorder', 'desc': '边框样式', 'value': array()),
|
||||
('attrName': 'Fill', 'type': 'class - TFills', 'desc': '填充样式', 'value': array()),
|
||||
('attrName': 'Protection', 'type': 'class - TProtection', 'desc': '保护样式', 'value': array()),
|
||||
),
|
||||
'Demo': styleDemo,
|
||||
),
|
||||
('ObjName': 'TNumFmts',
|
||||
'Desc': ('TNumFmts有以下属性: '),
|
||||
'AttrInfo': (
|
||||
('attrName': 'FormatCode', 'type': 'string', 'desc': '', 'value': array()),
|
||||
),
|
||||
'Demo': '',
|
||||
),
|
||||
('ObjName': 'TAlignment',
|
||||
'Desc': ('TAlignment有以下属性: '),
|
||||
'AttrInfo': (
|
||||
('attrName': 'Horizontal', 'type': 'string', 'desc': '水平对齐', 'value': array('nil(默认): 靠右', '"center": 居中', '"left": 靠左', '"fill": 填充', '"justify": 两端对齐', '"distributed": 两端对齐', '"centerContinuous": 跨列居中')),
|
||||
('attrName': 'Vertical', 'type': 'string', 'desc': '垂直对齐', 'value': array('nil(默认): 靠下', '"center": 居中', '"top": 靠上', '"justify": 两端对齐', 'distributed: 分散对齐')),
|
||||
('attrName': 'WrapText', 'type': 'boolean', 'desc': '是否自动换行,默认FALSE', 'value': array()),
|
||||
('attrName': 'ReadingOrder', 'type': 'int', 'desc': '文字方向', 'value': array('nil(默认): 根据内容', '1: 总是从左到右', '2: 总是从右到左')),
|
||||
),
|
||||
'Demo': '',
|
||||
),
|
||||
('ObjName': 'TFont',
|
||||
'Desc': ('TFont有以下属性: '),
|
||||
'AttrInfo': (
|
||||
('attrName': 'Name', 'type': 'string', 'desc': '字体名称', 'value': array()),
|
||||
('attrName': 'Size', 'type': 'double', 'desc': '字体大小', 'value': array()),
|
||||
('attrName': 'Bold', 'type': 'boolean', 'desc': '是否加粗,默认FALSE', 'value': array()),
|
||||
('attrName': 'Italic', 'type': 'boolean', 'desc': '是否倾斜,默认FALSE', 'value': array()),
|
||||
('attrName': 'Charset', 'type': 'string', 'desc': '字符集', 'value': array()),
|
||||
('attrName': 'Strikethrough', 'type': 'boolean', 'desc': '是否启用删除线,默认FALSE', 'value': array()),
|
||||
('attrName': 'Script', 'type': 'string', 'desc': '上下标', 'value': array('"subscript": 下标', '"superscript": 上标')),
|
||||
('attrName': '', 'type': 'double', 'desc': '{颜色}:{Color}和{ThemeColor}只能设置一种', 'value': array()),
|
||||
('attrName': 'Color', 'type': 'string', 'desc': 'RGB颜色,如"A020F0"', 'value': array()),
|
||||
('attrName': 'ThemeColor', 'type': 'int', 'desc': '主题颜色', 'value': array()),
|
||||
('attrName': 'Underline', 'type': 'string', 'desc': '下划线', 'value': array('"double": 双下划线', '"singleAccounting": 会计单下划线', '"doubleAccounting": 会计双下划线')),
|
||||
),
|
||||
'Demo': '',
|
||||
),
|
||||
('ObjName': 'TBorders',
|
||||
'Desc': ('TBorders有以下属性: '),
|
||||
'AttrInfo': (
|
||||
('attrName': 'Left', 'type': 'class - TBorder', 'desc': '左边框', 'value': array()),
|
||||
('attrName': 'Right', 'type': 'class - TBorder', 'desc': '右边框', 'value': array()),
|
||||
('attrName': 'Top', 'type': 'class - TBorder', 'desc': '上边框', 'value': array()),
|
||||
('attrName': 'Bottom', 'type': 'class - TBorder', 'desc': '下边框', 'value': array()),
|
||||
('attrName': 'DiagonalUp', 'type': 'boolean', 'desc': '左下-右上 对角线', 'value': array()),
|
||||
('attrName': 'DiagonalDown', 'type': 'boolean', 'desc': '左上-右下 对角线', 'value': array()),
|
||||
('attrName': 'Diagonal', 'type': 'class - TBorder', 'desc': '对角线,设置 {DiagonalUp}或{DiagonalDown}时有效', 'value': array()),
|
||||
),
|
||||
'Demo': '',
|
||||
),
|
||||
('ObjName': 'TBorder',
|
||||
'Desc': ('TBorder有以下属性: '),
|
||||
'AttrInfo': (
|
||||
('attrName': 'LineStyle', 'type': 'string', 'desc': '线型', 'value': array('"hair"', '"dotted"', '"dashDotDot"', '"dashDot"', '"dashed"', '"thin"', '"slantDashDot"', '"mediumDashedDotDot"', '"mediumDashedDot"', '"mediumDashed"', '"medium"', '"thick"', '"double"')),
|
||||
('attrName': '', 'type': '', 'desc': '{颜色}:{Color}和{ThemeColor}只能设置一个', 'value': array()),
|
||||
('attrName': 'Color', 'type': 'string', 'desc': 'RGB颜色', 'value': array()),
|
||||
('attrName': 'ThemeColor', 'type': 'int', 'desc': '主题颜色', 'value': array()),
|
||||
),
|
||||
'Demo': '',
|
||||
),
|
||||
('ObjName': 'TFills',
|
||||
'Desc': ('TFills有以下属性: '),
|
||||
'AttrInfo': (
|
||||
('attrName': '', 'type': '', 'desc': '填充方式{Pattern}和{Gradient}只能设置一种', 'value': array()),
|
||||
('attrName': 'Pattern', 'type': 'class - TPattern', 'desc': '图案填充', 'value': array()),
|
||||
('attrName': 'Gradient', 'type': 'class - TGradient', 'desc': '颜色渐变填充', 'value': array()),
|
||||
),
|
||||
'Demo': '',
|
||||
),
|
||||
('ObjName': 'TPattern',
|
||||
'Desc': ('TPattern有以下属性: '),
|
||||
'AttrInfo': (
|
||||
('attrName': 'PatternType', 'type': 'string', 'desc': '图案样式', 'value': array()),
|
||||
('attrName': '', 'type': '', 'desc': '{颜色}:前景色,{ForegroundColor}和{ForegroundThemeColor}只能设置一种', 'value': array()),
|
||||
('attrName': 'ForegroundColor', 'type': 'string', 'desc': 'RGB颜色', 'value': array()),
|
||||
('attrName': 'ForegroundThemeColor', 'type': 'int', 'desc': '主题颜色', 'value': array()),
|
||||
('attrName': 'ForegroundThemeColorTint', 'type': 'int', 'desc': '主题颜色的色调', 'value': array()),
|
||||
('attrName': '', 'type': '', 'desc': '{颜色}:背景色,{BackgroundColor}和{BackgroundThemeColor}只能设置一种', 'value': array()),
|
||||
('attrName': 'BackgroundColor', 'type': 'string', 'desc': 'RGB颜色', 'value': array()),
|
||||
('attrName': 'BackgroundThemeColor', 'type': 'int', 'desc': '主题颜色', 'value': array()),
|
||||
('attrName': 'BackgroundThemeColorTint', 'type': 'int', 'desc': '主题颜色的色调', 'value': array()),
|
||||
),
|
||||
'Demo': '',
|
||||
),
|
||||
('ObjName': 'TGradient',
|
||||
'Desc': ('TGradient有以下属性: '),
|
||||
'AttrInfo': (
|
||||
('attrName': '', 'type': '', 'desc': '{颜色1}:渐变的第一种颜色,{Color1}和{ThemeColor1}只能设置一种', 'value': array()),
|
||||
('attrName': 'Color1', 'type': 'string', 'desc': 'RGB颜色', 'value': array()),
|
||||
('attrName': 'ThemeColor1', 'type': 'int', 'desc': '主题颜色', 'value': array()),
|
||||
('attrName': '', 'type': '', 'desc': '{颜色2}:渐变的第一种颜色,{Color2}和{ThemeColor2}只能设置一种', 'value': array()),
|
||||
('attrName': 'Color2', 'type': 'string', 'desc': 'RGB颜色', 'value': array()),
|
||||
('attrName': 'ThemeColor2', 'type': 'int', 'desc': '主题颜色', 'value': array()),
|
||||
('attrName': 'Shading', 'type': 'int', 'desc': '底纹样式', 'value': array('0: 水平渐变,颜色1从上到下渐变到颜色2', '1: 水平渐变,颜色2从上到下渐变到颜色1',
|
||||
'2: 水平渐变,三层颜色,颜色1从上渐变到中间颜色2,再从颜色2渐变到底部颜色1',
|
||||
'3: 垂直渐变,颜色1从左到右渐变到颜色2',
|
||||
'4: 垂直渐变,颜色2从右到左渐变到颜色1',
|
||||
'5: 垂直渐变,三层颜色,颜色1从左渐变到中间颜色2,再从颜色2渐变到右边颜色1',
|
||||
'6: 斜上渐变,颜色1左上渐变到右下颜色2',
|
||||
'7: 斜上渐变,颜色2左上渐变到右下颜色1',
|
||||
'8: 斜上渐变,三层颜色,颜色1从左上渐变到对角线颜色2,再从颜色2渐变到右下颜色1',
|
||||
'9: 斜下渐变,颜色1右上渐变到左下颜色2',
|
||||
'10: 斜下渐变,颜色2左上渐变到右下颜色1',
|
||||
'11: 斜下渐变,三层颜色,颜色1从左上渐变到对角线颜色2,再从颜色2渐变到右下颜色1',
|
||||
'12: 角部辐射渐变,颜色1左上角辐射渐变到右下角2',
|
||||
'13: 角部辐射渐变,颜色1右上角辐射渐变到左下角颜色2',
|
||||
'14: 角部辐射渐变,颜色1左下角辐射渐变到右上角2',
|
||||
'15: 角部辐射渐变,颜色1右下角辐射渐变到左上角颜色2',
|
||||
'16: 中心辐射渐变,颜色1从中心向四周辐射到颜色2',
|
||||
)),
|
||||
),
|
||||
'Demo': '',
|
||||
),
|
||||
('ObjName': 'TProtection',
|
||||
'Desc': ('TProtection有以下属性: '),
|
||||
'AttrInfo': (
|
||||
('attrName': 'Lock', 'type': 'boolean', 'desc': '是否锁定,默认FALSE', 'value': array()),
|
||||
('attrName': 'Hide', 'type': 'boolean', 'desc': '是否隐藏,默认FALSE', 'value': array()),
|
||||
),
|
||||
'Demo': '',
|
||||
),
|
||||
('ObjName': 'THeaderFooter',
|
||||
'Desc': ('THeaderFooter有以下属性: '),
|
||||
'AttrInfo': (
|
||||
('attrName': 'DifferentOddEven', 'type': 'boolean', 'desc': '是否分别设定奇数和偶数页页眉和页脚,若为FALSE(默认)时,仅需设置{OddHeader}和{OddFooter}', 'value': array()),
|
||||
('attrName': 'DifferentFirst', 'type': 'boolean', 'desc': '是否单独设定首页页眉页脚', 'value': array()),
|
||||
('attrName': 'ScaleWithDoc', 'type': 'boolean', 'desc': '是否随文档一起缩放', 'value': array()),
|
||||
('attrName': 'AlignWithMargin', 'type': 'boolean', 'desc': '是否与页边距对齐', 'value': array()),
|
||||
('attrName': 'OddHeader', 'type': 'string', 'desc': '奇数页页眉控制符', 'value': array()),
|
||||
('attrName': 'OddFooter', 'type': 'string', 'desc': '奇数页页脚控制符', 'value': array()),
|
||||
('attrName': 'EvenHeader', 'type': 'string', 'desc': '偶数页页眉控制符,仅{DifferentOddEven} = TRUE 时有效', 'value': array()),
|
||||
('attrName': 'EvenFooter', 'type': 'string', 'desc': '偶数页页脚控制符,仅{DifferentOddEven} = TRUE 时有效', 'value': array()),
|
||||
('attrName': 'FirstHeader', 'type': 'string', 'desc': '首页页眉控制符,仅{DifferentFirst} = TRUE 时有效', 'value': array()),
|
||||
('attrName': 'FirstFooter', 'type': 'string', 'desc': '首页页脚控制符,仅{DifferentFirst} = TRUE 时有效', 'value': array()),
|
||||
),
|
||||
'Demo': '',
|
||||
),
|
||||
('ObjName': 'TMargins',
|
||||
'Desc': ('TMargins有以下属性: '),
|
||||
'AttrInfo': (
|
||||
('attrName': 'Left', 'type': 'double', 'desc': '左页边距', 'value': array()),
|
||||
('attrName': 'Right', 'type': 'double', 'desc': '右页边距', 'value': array()),
|
||||
('attrName': 'Top', 'type': 'double', 'desc': '上页边距', 'value': array()),
|
||||
('attrName': 'Bottom', 'type': 'double', 'desc': '下页边距', 'value': array()),
|
||||
('attrName': 'Header', 'type': 'double', 'desc': '页眉页边距', 'value': array()),
|
||||
('attrName': 'Footer', 'type': 'double', 'desc': '页脚页边距', 'value': array()),
|
||||
),
|
||||
'Demo': '',
|
||||
),
|
||||
('ObjName': 'TPageLayout',
|
||||
'Desc': ('TPageLayout有以下属性: '),
|
||||
'AttrInfo': (
|
||||
('attrName': 'PaperSize', 'type': 'int', 'desc': '纸张大小', 'value': array()),
|
||||
('attrName': '', 'type': '', 'desc': '{Scale}和{FitToWidth},{FitToHeight}只能设置一种', 'value': array()),
|
||||
('attrName': 'Scale', 'type': 'int', 'desc': '缩放比例(%)', 'value': array()),
|
||||
('attrName': 'FitToWidth', 'type': 'int', 'desc': '页宽', 'value': array()),
|
||||
('attrName': 'FitToHeight', 'type': 'int', 'desc': '页高', 'value': array()),
|
||||
('attrName': 'FirstPageNumber', 'type': 'int', 'desc': '起始页码', 'value': array()),
|
||||
('attrName': 'Orientation', 'type': 'string', 'desc': '纸张方向', 'value': array('"landscape": 横向', '"portrait": 纵向')),
|
||||
('attrName': 'PageOrder', 'type': 'string', 'desc': '打印顺序', 'value': array('nil(默认): 先列后行', '"overThenDown": 先行后列')),
|
||||
('attrName': 'BlackAndWhite', 'type': 'boolean', 'desc': '单色打印', 'value': array()),
|
||||
('attrName': 'Draft', 'type': 'boolean', 'desc': '是否开启草稿质量', 'value': array()),
|
||||
('attrName': 'CellComments', 'type': 'string', 'desc': '注释', 'value': array('nil(默认): 无', '"atEnd": 工作表末尾', '"asDisplayed": 如同工作表中的显示')),
|
||||
('attrName': 'CellError', 'type': 'string', 'desc': '错误单元格打印为', 'value': array('nil(默认): 显示值', '"blank": 空白', '"dash": "--"', "NA": "#N/A")),
|
||||
),
|
||||
'Demo': '',
|
||||
),
|
||||
('ObjName': 'TAppProperty',
|
||||
'Desc': ('TAppProperty有以下属性: '),
|
||||
'AttrInfo': (
|
||||
('attrName': 'Application', 'type': 'string', 'desc': '应用程序', 'value': array()),
|
||||
('attrName': 'DocSecurity', 'type': 'boolean', 'desc': '', 'value': array()),
|
||||
('attrName': 'ScaleCrop', 'type': 'string', 'desc': '', 'value': array('"false"(默认)', '"true"')),
|
||||
('attrName': 'Manager', 'type': 'string', 'desc': '主管', 'value': array()),
|
||||
('attrName': 'LinksUpToDate', 'type': 'string', 'desc': '', 'value': array('"false"(默认)', '"true"')),
|
||||
('attrName': 'SharedDoc', 'type': 'string', 'desc': '', 'value': array('"false"(默认)', '"true"')),
|
||||
('attrName': 'HyperlinkBase', 'type': 'string', 'desc': '超链接基础', 'value': array()),
|
||||
('attrName': 'HyperlinksChanged', 'type': 'string', 'desc': '', 'value': array('"false"(默认)', '"true"')),
|
||||
('attrName': 'AppVersion', 'type': 'string', 'desc': '应用程序版本', 'value': array()),
|
||||
),
|
||||
'Demo': '',
|
||||
),
|
||||
('ObjName': 'THyperLink',
|
||||
'Desc': ('THyperLink有以下属性: '),
|
||||
'AttrInfo': (
|
||||
('attrName': 'LinkType', 'type': 'string', 'desc': '超链接类型', 'value': array('"External": 外部超链接', '"Location"': 内部超链接)),
|
||||
('attrName': 'LinkUrl', 'type': 'string', 'desc': '超链接地址', 'value': array()),
|
||||
('attrName': 'Tooltip', 'type': 'string', 'desc': '超链接悬浮提示内容', 'value': array()),
|
||||
('attrName': 'Display', 'type': 'string', 'desc': '单元格显示的内容', 'value': array()),
|
||||
),
|
||||
'Demo': '',
|
||||
),
|
||||
('ObjName': 'TPicture',
|
||||
'Desc': ('TPicture有以下属性: '),
|
||||
'AttrInfo': (
|
||||
('attrName': 'Image', 'type': 'binary', 'desc': '图片的二进制数据', 'value': array()),
|
||||
('attrName': 'Descr', 'type': 'binary', 'desc': '图片描述', 'value': array()),
|
||||
),
|
||||
'Demo': '',
|
||||
),
|
||||
('ObjName': 'TPictureFormat',
|
||||
'Desc': ('TPictureFormat有以下属性: '),
|
||||
'AttrInfo': (
|
||||
('attrName': 'BegColOff', 'type': 'int', 'desc': '开始列偏移', 'value': array()),
|
||||
('attrName': 'BegRowOff', 'type': 'int', 'desc': '开始行偏移', 'value': array()),
|
||||
('attrName': 'EndColOff', 'type': 'int', 'desc': '结束列偏移', 'value': array()),
|
||||
('attrName': 'EndRowOff', 'type': 'int', 'desc': '结束行偏移', 'value': array()),
|
||||
),
|
||||
'Demo': '',
|
||||
),
|
||||
);
|
||||
End
|
||||
@@ -0,0 +1,82 @@
|
||||
excel := new TSExcelFile();
|
||||
_test_addchart(excel);
|
||||
//_test_getcharts(excel);
|
||||
|
||||
|
||||
Function _test_getcharts(excel);
|
||||
Begin
|
||||
f := 'F:\\temp\\test.xlsx';
|
||||
[err, errmsg] := excel.OpenFile('', f);
|
||||
if err then return
|
||||
echo 'Open Fail:', errmsg, '\n';
|
||||
[err, charts] := excel.GetCharts('Sheet1');
|
||||
for i:=0 to length(charts)-1 do Begin
|
||||
println('ChartName={}, Title={}, Series={}',charts[i].Chart.Name, charts[i].Chart.Title, charts[i].Chart.Series);
|
||||
End;
|
||||
charts[1].RemoveSeries(1);
|
||||
[err, errmsg] := excel.SaveAs('', 'f:\\temp\\ch.xlsx');
|
||||
println('SaveAs->{}',err);
|
||||
//charts[i].RemoveSeries(i);
|
||||
//charts[i].AddSeries(Name, Categories, Values);
|
||||
//charts[i].UpdateSeries(i, Name, Categories, Values);
|
||||
//charts[i].UpdateTitle(i, title);
|
||||
End;
|
||||
|
||||
Function _test_addchart(excel);
|
||||
Begin
|
||||
//f := 'F:\\temp\\test.xlsx';
|
||||
[err, errmsg] := excel.NewFile();
|
||||
//[err, errmsg] := excel.OpenFile('', f);
|
||||
if err then return
|
||||
echo 'Open Fail:', errmsg, '\n';
|
||||
//插入数据表
|
||||
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));
|
||||
chart := TOfficeObj('TChart');
|
||||
chart.Type := 'col';
|
||||
chart.VaryColors := true;
|
||||
chart.BegColOff := 80000;
|
||||
chart.BegRowOff := 80000;
|
||||
chart.Name := 'test chart 1';
|
||||
chart.Title := 'Hans Chart';
|
||||
|
||||
chart.AddSeries('Sheet1!$A$6', 'Sheet1!$B$5:$D$5', 'Sheet1!$B$6:$D$6');
|
||||
chart.AddSeries('Sheet1!$A$7', 'Sheet1!$B$5:$D$5', 'Sheet1!$B$7:$D$7');
|
||||
chart.AddSeries('Sheet1!$A$8', 'Sheet1!$B$5:$D$5', 'Sheet1!$B$8:$D$8');
|
||||
|
||||
chart.ShowLegendKey := false;
|
||||
chart.Legend.Position := 'left';
|
||||
|
||||
chart.ShowBubbleSize := true;
|
||||
chart.ShowCatName := false;
|
||||
chart.ShowLeaderLines := false;
|
||||
chart.ShowPercent := true;
|
||||
chart.ShowSerName := true;
|
||||
chart.ShowVal := true;
|
||||
chart.ShowBlanksAs := 'zero';
|
||||
|
||||
|
||||
[err, errinfo] := excel.InsertTable("Sheet1","A5",data, true);
|
||||
chart1 := excel.AddChart('Sheet1', 'A11:G30', chart);
|
||||
println('AddChart1={}', chart1);
|
||||
|
||||
|
||||
chart.Type := 'pie3D';
|
||||
chart.VaryColors := true;
|
||||
chart.BegColOff := 0;
|
||||
chart.BegRowOff := 0;
|
||||
chart.Name := 'test chart 2';
|
||||
chart.Title := 'Hans Chart 2';
|
||||
chart.Legend.Position := 'bottom';
|
||||
chart.Series := array(('Name':"Sheet3!$A$6", 'Categories':"Sheet3!$B$5:$D$5", 'Values':"Sheet3!$B$6:$D$6"));
|
||||
chart.ShowSerName := false;
|
||||
chart.ShowVal := false;
|
||||
excel.NewSheet('Sheet3');
|
||||
[err, errinfo] := excel.InsertTable("Sheet3","A5",data, true);
|
||||
chart2 := excel.AddChart('Sheet3', 'I11:P30', chart);
|
||||
println('AddChart2={}', chart2);
|
||||
|
||||
[err, errmsg] := excel.SaveAs('', 'f:\\temp\\ch.xlsx');
|
||||
println('SaveAs->{}',err);
|
||||
End;
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
docx := new TSDocxFile();
|
||||
//_test_readParagraphs(docx);
|
||||
_test_newfile(docx);
|
||||
//_test_addtable(docx);
|
||||
//_test_Properties(docx);
|
||||
//_test_picture(docx);
|
||||
|
||||
|
||||
Function _test_picture(docx);
|
||||
Begin
|
||||
[err, errmsg] := docx.NewFile();
|
||||
if err then
|
||||
return echo 'Open Fail:', errmsg, '\n';
|
||||
|
||||
picture := TOfficeObj('TPicture');
|
||||
picture.Descr := 'Hans Tan\'s Picture test';
|
||||
readfile(rwbinary(), '', 'F:\\temp\\VS2010Ultim\\Setup\\banner.bmp', 0, 1024*1024, data);
|
||||
picture.Image := data;
|
||||
p := docx.AddPicture(picture, -1);
|
||||
|
||||
v := docx.SaveAs('', 'f:\\temp\\p.docx');
|
||||
println('Save={}', v);
|
||||
End;
|
||||
|
||||
|
||||
Function _test_Properties(docx);
|
||||
Begin
|
||||
f := 'F:\\temp\\test.docx';
|
||||
[err, errmsg] := docx.OpenFile('', f);
|
||||
if err then return
|
||||
echo 'Open Fail:', errmsg, '\n';
|
||||
|
||||
core := docx.Properties();
|
||||
core.Author := 'Hans Tan';
|
||||
core.Modified := now();
|
||||
|
||||
docx.SaveAs('', 'f:\\temp\\core.docx');
|
||||
End;
|
||||
|
||||
|
||||
Function _test_addtable(docx);
|
||||
Begin
|
||||
[err, errmsg] := docx.NewFile();
|
||||
if err then return
|
||||
echo 'Open Fail:', errmsg, '\n';
|
||||
|
||||
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));
|
||||
tbl := docx.CreateTable(data, true, true);
|
||||
//tbl.TblPr.Style := 1;
|
||||
|
||||
tbl := docx.InsertTable(tbl, -1);
|
||||
|
||||
v := docx.SaveAs('', 'f:\\temp\\t.docx');
|
||||
println('Save={}', v);
|
||||
End;
|
||||
|
||||
Function _test_newfile(docx);
|
||||
Begin
|
||||
[err, errmsg] := docx.NewFile();
|
||||
if err then return
|
||||
echo 'Open Fail:', errmsg, '\n';
|
||||
|
||||
paragraph := TOfficeObj('TParagraph');
|
||||
paragraph.Run.Text := 'This is the 1 Line.';
|
||||
p := docx.AddParagraph(paragraph, -1);
|
||||
p := docx.AddLineBreak(p);
|
||||
p := docx.AddLineBreak(p);
|
||||
paragraph.Run.Text := 'This is the 2 Line.';
|
||||
p := docx.AddParagraph(paragraph, -1);
|
||||
p := docx.AddPageBreak(p);
|
||||
|
||||
paragraph.Run.Text := 'This is the 3 Line.';
|
||||
p := docx.AddParagraph(paragraph, -1);
|
||||
p := docx.AddColumnBreak(p);
|
||||
paragraph.Run.Text := '';
|
||||
p := docx.AddParagraph(paragraph, -1);
|
||||
p.SetText('This is the 4 Line\nline5\nline6\nline7.');
|
||||
|
||||
v := docx.SaveAs('', 'f:\\temp\\new.docx');
|
||||
println('Save={}', v);
|
||||
|
||||
End;
|
||||
|
||||
Function _test_readParagraphs(docx);
|
||||
Begin
|
||||
f := 'F:\\temp\\test.docx';
|
||||
[err, errmsg] := docx.OpenFile('', f);
|
||||
if err then return
|
||||
echo 'Open Fail:', errmsg, '\n';
|
||||
|
||||
paragraph := TOfficeObj('TParagraph');
|
||||
paragraph.Run.Text := 'New paragraph';
|
||||
v := docx.AddParagraph(paragraph, 0);
|
||||
paragraphs := docx.Paragraphs();
|
||||
println("AddParagraph={}", v);
|
||||
paragraphs[9].SetText('1、修改文字;
|
||||
2、第2段;
|
||||
3、第3段;
|
||||
4、第4段。');
|
||||
|
||||
paragraphs := docx.Paragraphs();
|
||||
for i:=0 to length(paragraphs)-1 do Begin
|
||||
println('Name={}, Text={}', paragraphs[i].Name(), paragraphs[i].Text());
|
||||
End;
|
||||
|
||||
tcnt := docx.TablesCount();
|
||||
println('\n\nTableCount={}',tcnt);
|
||||
for i := 0 to tcnt-1 do Begin
|
||||
table := docx.GetTable(i);
|
||||
for j := 0 to table.Rows()-1 do Begin
|
||||
for k := 0 to table.Cols()-1 do Begin
|
||||
cell := table.Cell(j, k);
|
||||
if ifObj(cell) then Begin
|
||||
println('row={}, col={}, text={}', j, k, cell.Text());
|
||||
continue;
|
||||
End;
|
||||
println('row={}, col={}, Cell=nil', j, k);
|
||||
End;
|
||||
End;
|
||||
End;
|
||||
|
||||
println('all text={}, textArray={}', docx.Text(), docx.TextArray());
|
||||
|
||||
docx.SaveAs('', 'f:\\temp\\p.docx');
|
||||
End;
|
||||
@@ -0,0 +1,503 @@
|
||||
testCount := 0;
|
||||
sheetName := "hello";
|
||||
sheetName2 := "world";
|
||||
|
||||
// OpenFile
|
||||
excel := new TSExcelFile();
|
||||
[err, errmsg] := excel.OpenFile('', 'd:\\temp\\raw.xlsx');
|
||||
PrintInfo("OpenFile", err, errmsg);
|
||||
|
||||
// Save
|
||||
[err, errmsg] := excel.Save();
|
||||
PrintInfo("Save", err, errmsg);
|
||||
|
||||
excel := new TSExcelFile();
|
||||
|
||||
// NewFile
|
||||
[err, errmsg] := excel.NewFile();
|
||||
PrintInfo("NewFile", err, errmsg);
|
||||
|
||||
// SaveAs
|
||||
// [err, errmsg] := excel.SaveAs('', 'd:\\temp\\test.xlsx');
|
||||
// PrintInfo("SaveAs", err, errmsg);
|
||||
|
||||
// FileName
|
||||
name := excel.FileName();
|
||||
println("[success] name = {}", name);
|
||||
|
||||
// GetSheet
|
||||
sheets := excel.GetSheets();
|
||||
println("[success] sheets = {}", sheets);
|
||||
|
||||
// GetSheetsCount
|
||||
sheetCount := excel.GetSheetsCount();
|
||||
println("[success] GetSheetsCount = {}", sheetCount);
|
||||
|
||||
// SetSheetName
|
||||
[err, errmsg] := excel.SetSheetName("sheet1", sheetName);
|
||||
PrintInfo("SetSheetName", err, errmsg);
|
||||
|
||||
// GetSheetName
|
||||
sheetName := excel.GetSheetName(0);
|
||||
println("[success] GetSheetName = {}", sheetName);
|
||||
|
||||
// NewSheet
|
||||
[err, errmsg] := excel.NewSheet(sheetName2);
|
||||
PrintInfo("NewSheet", err, errmsg);
|
||||
|
||||
// DeleteSheet
|
||||
[err, errmsg] := excel.NewSheet("test1");
|
||||
//[err, errmsg] := excel.DeleteSheet("test1");
|
||||
//PrintInfo("DeleteSheet", err, errmsg);
|
||||
|
||||
// TotalCols
|
||||
totalCols := excel.TotalCols(sheetName);
|
||||
println("[success] TotalCols = {}", totalCols);
|
||||
|
||||
// TotalRows
|
||||
totalRows := excel.TotalRows(sheetName);
|
||||
println("[success] TotalRows = {}", totalRows);
|
||||
|
||||
// SetCellValue
|
||||
flag := excel.SetCellValue(sheetName, "A1", 100);
|
||||
println("[success] SetCellValue = ", flag);
|
||||
|
||||
// GetCellValue
|
||||
[err, errmsg] := excel.GetCellValue(sheetName, "A1");
|
||||
PrintInfo("GetCellValue", err, errmsg);
|
||||
|
||||
// SetCellRichText
|
||||
richText := TOfficeObj('TRichtext');
|
||||
text1 := richText.AddText('Hello');
|
||||
text1.Font.Size := 35;
|
||||
text1.Font.Color := "FFF000";
|
||||
text2 := richText.AddText(" World");
|
||||
text2.Font.Size := 25;
|
||||
text2.Font.Bold := true;
|
||||
excel.SetCellRichText(sheetName, "A2", richText);
|
||||
text2.Text := "python";
|
||||
excel.SetCellRichText(sheetName, "A3", richText);
|
||||
println("[success] SetCellRichText");
|
||||
|
||||
// GetCellRichText
|
||||
arr := excel.GetCellRichText(sheetName, "A3");
|
||||
println("[success] GetCellRichText = {}", arr);
|
||||
|
||||
// ClearCell
|
||||
excel.ClearCell(sheetName, "A1");
|
||||
//excel.ClearCell(sheetName);
|
||||
println("[success] ClearCell");
|
||||
|
||||
// SetCellFormula
|
||||
excel.SetCellFormula(sheetName, "A2", "=100*50");
|
||||
println("[success] SetCellFormula");
|
||||
|
||||
// GetCellFormula
|
||||
[err, errmsg] := excel.GetCellFormula(sheetName, "A2");
|
||||
PrintInfo("GetCellFormula", err, errmsg);
|
||||
|
||||
// SetSheetRow
|
||||
excel.SetSheetRow(sheetName, "C3", array(1, 2, 3, 4, "a", "b"));
|
||||
println("[success] SetSheetRow");
|
||||
|
||||
// InsertTable
|
||||
table := array((1, 2, "你好"), (4, 5, "b"));
|
||||
//table2 := array(("title1" :1, "title2": 2), ("title1": 3, "title2": 4));
|
||||
[err, errmsg] := excel.InsertTable(sheetName, "A5", table);
|
||||
PrintInfo("InsertTable", err, errmsg);
|
||||
|
||||
// GetTable
|
||||
table := excel.GetTable(sheetName, "A5", "B7");
|
||||
println("[success] GetTable = {}", table);
|
||||
|
||||
// InsertCol
|
||||
excel.InsertCol(sheetName, "B");
|
||||
excel.InsertCol(sheetName, "B");
|
||||
println("[success] InsertCol");
|
||||
|
||||
// InsertRow
|
||||
excel.InsertRow(sheetName, 3);
|
||||
excel.InsertRow(sheetName, 3);
|
||||
println("[success] InsertRow");
|
||||
|
||||
// RemoveCol
|
||||
excel.RemoveCol(sheetName, "B");
|
||||
println("[success] RemoveCol");
|
||||
|
||||
// RemoveRow
|
||||
excel.RemoveRow(sheetName, 3);
|
||||
println("[success] RemoveRow");
|
||||
|
||||
// SetRowHeight
|
||||
excel.SetRowHeight(sheetName, 1, 30);
|
||||
excel.SetRowHeight(sheetName, 15, 30);
|
||||
println("[success] SetRowHeight");
|
||||
|
||||
// GetRowHeight
|
||||
height := excel.GetRowHeight(sheetName, 2);
|
||||
println("[success] GetRowHeight = {}", height);
|
||||
height := excel.GetRowHeight(sheetName, 15);
|
||||
println("[success] GetRowHeight = {}", height);
|
||||
|
||||
// SetColWidth
|
||||
excel.SetColWidth(sheetName, "A", "D", 20);
|
||||
println("[success] SetColWidth");
|
||||
|
||||
// GetColWidth
|
||||
width := excel.GetColWidth(sheetName, "A");
|
||||
println("[success] GetColWidth = {}", width);
|
||||
width := excel.GetColWidth(sheetName, "E");
|
||||
println("[success] GetColWidth = {}", width);
|
||||
|
||||
// SetSheetDefaultColWidth
|
||||
excel.SetSheetDefaultColWidth(sheetName, 15);
|
||||
println("[success] SetSheetDefaultColWidth");
|
||||
|
||||
// GetSheetDefaultColWidth
|
||||
width := excel.GetSheetDefaultColWidth(sheetName);
|
||||
println("[success] GetSheetDefaultColWidth = {}", width);
|
||||
|
||||
// AddComment
|
||||
excel.AddComment(sheetName, "A1", "csh", "heiheihei");
|
||||
println("[success] AddComment");
|
||||
|
||||
// AddChart
|
||||
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));
|
||||
chart := TOfficeObj('TChart');
|
||||
chart.Type := 'col';
|
||||
chart.VaryColors := true;
|
||||
chart.BegColOff := 20000;
|
||||
chart.BegRowOff := 20000;
|
||||
chart.Name := 'test chart 1';
|
||||
chart.Title := 'Hans Chart';
|
||||
|
||||
chart.AddSeries('Sheet1!$A$6', 'Sheet1!$B$5:$D$5', 'Sheet1!$B$6:$D$6');
|
||||
chart.AddSeries('Sheet1!$A$7', 'Sheet1!$B$5:$D$5', 'Sheet1!$B$7:$D$7');
|
||||
chart.AddSeries('Sheet1!$A$8', 'Sheet1!$B$5:$D$5', 'Sheet1!$B$8:$D$8');
|
||||
|
||||
chart.ShowLegendKey := false;
|
||||
chart.Legend.Position := 'left';
|
||||
|
||||
chart.ShowBubbleSize := true;
|
||||
chart.ShowCatName := false;
|
||||
chart.ShowLeaderLines := false;
|
||||
chart.ShowPercent := true;
|
||||
chart.ShowSerName := true;
|
||||
chart.ShowVal := true;
|
||||
chart.ShowBlanksAs := 'zero';
|
||||
|
||||
excel.NewSheet('Sheet1');
|
||||
[err, errinfo] := excel.InsertTable("Sheet1","A5",data, true);
|
||||
chart1 := excel.AddChart('Sheet1', 'A11:G30', chart);
|
||||
println("[success] AddChart");
|
||||
[err, errmsg] := excel.saveas("", "d:\\temp\\test.xlsx");
|
||||
println("saveas : {}", err);
|
||||
|
||||
// GetCharts
|
||||
[err, charts] := excel.GetCharts('Sheet1');
|
||||
for i:=0 to length(charts)-1 do Begin
|
||||
println('ChartName={}, Title={}, Series={}',charts[i].Chart.Name, charts[i].Chart.Title, charts[i].Chart.Series);
|
||||
End;
|
||||
|
||||
// SplitCellName
|
||||
[err, col, row] := excel.SplitCellName("AK47");
|
||||
if not err then println("[success] {} = col : {}, row = {}", "SplitCellName", col, row);
|
||||
|
||||
// JoinCellName
|
||||
[err, errmsg] := excel.JoinCellName("AK", 47);
|
||||
PrintInfo("JoinCellName", err, errmsg);
|
||||
|
||||
// ColumnNameToNumber
|
||||
[err, errmsg] := excel.ColumnNameToNumber("AK");
|
||||
PrintInfo("ColumnNameToNumber", err, errmsg);
|
||||
|
||||
// ColumnNumberToName
|
||||
[err, errmsg] := excel.ColumnNumberToName(37);
|
||||
PrintInfo("ColumnNumberToName", err, errmsg);
|
||||
|
||||
// CellNameToCoordinates
|
||||
[err, col, row] := excel.CellNameToCoordinates("A2");
|
||||
if not err then println("[success] {} = col : {}, row = {}", "CellNameToCoordinates", col, row);
|
||||
|
||||
// RGBToHSL
|
||||
[err, h, s, l] := excel.RGBToHSL(255, 15, 33);
|
||||
if not err then println("[success] {} = {}, {}, {}", "RGBToHSL", h, s, l);
|
||||
|
||||
// HSLToRGB
|
||||
[err, r, g, b] := excel.HSLToRGB(h, s, l);
|
||||
if not err then println("[success] {} = {}, {}, {}", "HSLToRGB", h, s, l);
|
||||
|
||||
// NewStyle
|
||||
style := TOfficeObj('TStyle');
|
||||
style.Font.Color := "A020F0";
|
||||
style.Font.Size := 22;
|
||||
style.Font.Name := "黑体";
|
||||
style.Font.Bold := True;
|
||||
style.Font.Charset := "134";
|
||||
style.Font.Script := "subscript";
|
||||
style.Font.Underline := "double";
|
||||
style.Font.Strikethrough := True;
|
||||
style.Font.Italic := True;
|
||||
style.Alignment.Horizontal := "center";
|
||||
style.Alignment.Vertical := "justify";
|
||||
style.Alignment.WrapText := True;
|
||||
style.Alignment.ReadingOrder := 2;
|
||||
style.Border.Left.LineStyle := "thin";
|
||||
style.Border.Left.Color := "A020F0";
|
||||
style.Border.Right.LineStyle := "thin";
|
||||
style.Border.Right.Color := "FF0000";
|
||||
style.Border.Bottom.LineStyle := "mediumDashed";
|
||||
style.Border.Bottom.Color := "FF0000";
|
||||
style.Border.Top.LineStyle := "mediumDashed";
|
||||
style.Border.Top.Color := "FF0000";
|
||||
style.Border.DiagonalDown := True;
|
||||
style.Border.DiagonalUp := True;
|
||||
style.Border.Diagonal.LineStyle := "double";
|
||||
style.Border.Diagonal.Color := "A020F0";
|
||||
style.NumberFormat.FormatCode := "#,##0.000_ ";
|
||||
//style.Fill.Pattern.PatternType := "solid";
|
||||
//style.Fill.Pattern.ForegroundColor := "FF6699FF";
|
||||
//style.Fill.Pattern.BackgroundColor := "FFFF0000";
|
||||
style.Fill.Gradient.ThemeColor1 := 0;
|
||||
style.Fill.Gradient.ThemeColor2 := 4;
|
||||
style.Fill.Gradient.Shading := 1;
|
||||
style.Protection.Hide := 1;
|
||||
style.Protection.Lock := 1;
|
||||
|
||||
styleid1 := excel.NewStyle(style);
|
||||
println("[success] NewStyle = {}", styleid1);
|
||||
|
||||
// SetCellStyle
|
||||
excel.SetCellStyle(sheetName, "A1", "A2", styleid1);
|
||||
println("[success] SetCellStyle");
|
||||
|
||||
styleid := excel.GetCellStyle(sheetName, "A1");
|
||||
println("[success] GetCellStyle = {}", styleid);
|
||||
styleid := excel.GetCellStyle(sheetName, "D4");
|
||||
println("[success] GetCellStyle = {}", styleid);
|
||||
|
||||
// SetSheetHeaderFooter
|
||||
headerFooter := TOfficeObj("THeaderFooter");
|
||||
headerFooter.DifferentOddEven := true;
|
||||
headerFooter.DifferentFirst := true;
|
||||
headerFooter.ScaleWithDoc := False;
|
||||
headerFooter.AlignWithMargin := False;
|
||||
headerFooter.OddHeader := "&L123&456&789";
|
||||
headerFooter.OddFooter := "&Ldef&Rhij";
|
||||
headerFooter.EvenHeader := "&L123&R456";
|
||||
headerFooter.EvenFooter := "&L456&R789";
|
||||
headerFooter.FirstHeader := "&L++";
|
||||
headerFooter.FirstFooter := "&R--";
|
||||
excel.SetSheetHeaderFooter(sheetName, headerFooter);
|
||||
println("[success] SetSheetHeaderFooter");
|
||||
|
||||
// SetSheetVisible
|
||||
excel.SetSheetVisible(sheetName, True);
|
||||
println("[success] SetSheetVisible");
|
||||
|
||||
// GetSheetVisible
|
||||
visible := excel.GetSheetVisible(sheetName);
|
||||
println("[success] GetSheetVisible = {}", visible);
|
||||
|
||||
// SetRowVisible
|
||||
excel.SetRowVisible(sheetName, 2, false);
|
||||
println("[success] SetRowVisible");
|
||||
|
||||
// GetRowVisble
|
||||
[err, errmsg] := excel.GetRowVisble(sheetName, 2);
|
||||
PrintInfo("GetRowVisble 2", err, errmsg);
|
||||
[err, errmsg] := excel.GetRowVisble(sheetName, 3);
|
||||
PrintInfo("GetRowVisble 3", err, errmsg);
|
||||
|
||||
// SetColVisible
|
||||
excel.SetColVisible(sheetName, "A", false);
|
||||
println("[success] SetRowVisible");
|
||||
|
||||
// GetColVisble
|
||||
[err, errmsg] := excel.GetColVisble(sheetName, "A");
|
||||
PrintInfo("GetColVisible", err, errmsg);
|
||||
|
||||
// SetPageMargins
|
||||
margins := TOfficeObj('TMargins');
|
||||
margins.Top := 0.5;
|
||||
margins.Bottom := 0.6;
|
||||
margins.Left := 0.7;
|
||||
margins.Right := 0.8;
|
||||
margins.Header := 0.9;
|
||||
margins.Footer := 1.0;
|
||||
excel.SetPageMargins(sheetName2, margins);
|
||||
println("[success] SetPageMargins");
|
||||
|
||||
// GetPageMargins
|
||||
margins := excel.GetPageMargins(sheetName2);
|
||||
println("[success] GetPageMargins top = {}, bottom = {}, left = {}, right = {}, header = {}, footer = {}",
|
||||
margins.Value('Top'), margins.Value('Bottom'), margins.Value('Left'), margins.Value('Right'),
|
||||
margins.Value('Header'), margins.Value('Footer'));
|
||||
|
||||
// MergeCell
|
||||
excel.SetCellStyle(sheetName2, "A4", "A4", styleid1);
|
||||
excel.MergeCell(sheetName2, "A4", "C4");
|
||||
excel.MergeCell(sheetName2, "A5", "D7");
|
||||
println("[success] MergeCell");
|
||||
|
||||
// UnMergeCell
|
||||
excel.UnMergeCell(sheetName2, "A4", "C4");
|
||||
println("[success] UnMergeCell");
|
||||
|
||||
// TODO 未完全开发完毕
|
||||
// SetSheetViewOptions
|
||||
// GetSheetViewOptions
|
||||
|
||||
// SetPageLayout
|
||||
pageLayout := TOfficeObj('TPageLayout');
|
||||
pageLayout.FitToWidth := 10;
|
||||
pageLayout.FitToHeight := 10;
|
||||
pageLayout.FirstPageNumber := 5;
|
||||
pageLayout.Orientation := "portrait";
|
||||
pageLayout.BlackAndWhite := true;
|
||||
pageLayout.PaperSize := 11;
|
||||
pageLayout.PageOrder := "overThenDown";
|
||||
pageLayout.CellError := "blank";
|
||||
pageLayout.CellComments := "asDisplayed";
|
||||
excel.SetPageLayout(sheetName2, pageLayout);
|
||||
println("[success] SetPageLayout");
|
||||
|
||||
// GetPageLayout
|
||||
pageLayout := excel.GetPageLayout(sheetName2);
|
||||
println("[success] GetPageLayout FitToWidth = {}, PaperSize = {}", pageLayout.Value('FitToWidth'), pageLayout.Value('PaperSize'));
|
||||
|
||||
// SetDefaultSheet
|
||||
excel.SetDefaultSheet(sheetName2);
|
||||
println("[success] SetDefaultSheet");
|
||||
|
||||
// GetDefaultSheet
|
||||
sheet := excel.GetDefaultSheet();
|
||||
println("[success] GetDefaultSheet = {}", sheet);
|
||||
|
||||
// SetCellHyperLink
|
||||
link := TOfficeObj('THyperLink');
|
||||
link.LinkType := "Location";
|
||||
link.LinkUrl := sheetName $ "!A1";
|
||||
excel.SetCellHyperLink(sheetName2, 'A1', link);
|
||||
link := TOfficeObj('THyperLink');
|
||||
link.LinkType := "External";
|
||||
link.LinkUrl := "https://www.baidu.com";
|
||||
link.Tooltip := "超链接悬浮提示";
|
||||
excel.SetCellValue(sheetName2, 'A2', '超链接');
|
||||
excel.SetCellHyperLink(sheetName2, 'A2', link);
|
||||
println("[success] SetCellHyperLink");
|
||||
|
||||
// GetCellHyperLink
|
||||
hyperlink := excel.GetCellHyperLink(sheetName2, 'A2');
|
||||
println("[success] GetCellHyperLink LinkType = {}, LinkUrl = {}, Tooltip = {}", hyperlink.Value('LinkType'), hyperlink.Value('LinkUrl'), hyperlink.Value('Tooltip'));
|
||||
|
||||
// SetSheetBackground
|
||||
ret := readfile(rwBinary(), "", "C:\\Users\\csh05\\Pictures\\Saved Pictures\\1.jpg", 0, 1024000, data);
|
||||
if not ret then return echo "readfile error!";
|
||||
picture := TOfficeObj('TPicture');
|
||||
picture.Image := data;
|
||||
excel.SetSheetBackground(sheetName, picture);
|
||||
println("[success] SetSheetBackground");
|
||||
|
||||
// AddPicture
|
||||
format := TOfficeObj('TPictureFormat');
|
||||
format.BegColOff := 20000;
|
||||
format.EndColOff := 20000;
|
||||
excel.AddPicture(sheetName, 'A11', 'F33', picture, format);
|
||||
excel.AddPicture(sheetName2, 'A8', 'D16', picture, format);
|
||||
println("[success] AddPicture");
|
||||
|
||||
// DeletePicture
|
||||
excel.DeletePicture(sheetName2, 'A1', 'D17');
|
||||
println("[success] DeletePicture");
|
||||
|
||||
// TODO 可能有问题
|
||||
// AddTable
|
||||
table2 := array(("title1" :1, "title2": 2), ("title1": 3, "title2": 4));
|
||||
excel.InsertTable(sheetName2, "A9", table2, true);
|
||||
tablestyle := TOfficeObj('TTableStyle');
|
||||
tablestyle.TableName := "测试表";
|
||||
tablestyle.TableStyle := "TableStyleMedium2";
|
||||
tablestyle.ShowFirstColumn := True;
|
||||
tablestyle.ShowLastColumn := True;
|
||||
tablestyle.ShowRowStripes := True;
|
||||
tablestyle.ShowColumnStripes := True;
|
||||
excel.AddTable(sheetName2, "A9", "B11", tablestyle, false);
|
||||
println("[success] AddTable");
|
||||
|
||||
// InsertPageBreak
|
||||
excel.InsertPageBreak(sheetName2, 10);
|
||||
excel.InsertPageBreak(sheetName2, 15);
|
||||
println("[success] InsertPageBreak");
|
||||
|
||||
// RemovePageBreak
|
||||
excel.RemovePageBreak(sheetName2, 15);
|
||||
println("[success] RemovePageBreak");
|
||||
|
||||
// AddShape
|
||||
shape_format := TOfficeObj('TShapeFormat');
|
||||
shape_format.BegColOff := 354252;
|
||||
shape_format.EndColOff := 7653;
|
||||
shape_format.BegRowOff := 55577;
|
||||
shape_format.EndRowOff := 66675;
|
||||
shape_type := "roundRect";
|
||||
|
||||
// SetCoreProps
|
||||
core := TOfficeObj('TCoreProperty');
|
||||
core.Title := "标题";
|
||||
core.Subject := "主题";
|
||||
core.Creator := "作者";
|
||||
excel.SetCoreProps(core);
|
||||
println("[success] SetCoreProps");
|
||||
|
||||
// GetCoreProps
|
||||
core := excel.GetCoreProps();
|
||||
println("[success] GetCoreProps Title = {}, subject = {}, Creator = {}", core.Value("Title"), core.Value("Subject"), core.Value("Creator"));
|
||||
|
||||
// SetAppProps
|
||||
appProps := TOfficeObj('TAppProperty');
|
||||
appProps.Application := "Microsoft TX";
|
||||
appProps.DocSecurity := false;
|
||||
appProps.ScaleCrop := "true";
|
||||
appProps.Company := "TS";
|
||||
appProps.LinksUpToDate := "true";
|
||||
appProps.HyperlinksChanged := "true";
|
||||
appProps.AppVersion := "1.000";
|
||||
appProps.Manager := "这是主管";
|
||||
//appProps.HyperlinkBase := "这是超链接基础";
|
||||
excel.SetAppProps(appProps);
|
||||
println("[success] SetAppProps");
|
||||
|
||||
// GetAppProps
|
||||
app_props := excel.GetAppProps();
|
||||
println("[success] GetAppProps Manager = {}, Company = {}, Application = {}", app_props.Value('Manager'), app_props.Value('Company'), app_props.Value('Application'));
|
||||
|
||||
[err, errmsg] := excel.saveas("", "d:\\temp\\test.xlsx");
|
||||
println("saveas : {}", err);
|
||||
|
||||
Function _test_background(excel);
|
||||
Begin
|
||||
f := 'D:\\temp\\a.xlsx';
|
||||
[err, msg] := excel.OpenFile('', f);
|
||||
if err then return
|
||||
echo "Open Fail:", msg, '\n';
|
||||
|
||||
ret := readfile(rwBinary(), "", "C:\\Users\\csh05\\Pictures\\Saved Pictures\\1.png", 0, 102400, data);
|
||||
if ret then pictrue := new TSImage(data);
|
||||
else return echo "readfile error!";
|
||||
|
||||
excel.SetSheetBackground('Sheet1', pictrue);
|
||||
|
||||
[err, errmsg] := excel.SaveAs('', 'd:\\temp\\e.xlsx');
|
||||
println('SaveAs->{}',err);
|
||||
End
|
||||
|
||||
// ============================================================
|
||||
Function PrintInfo(msg, err, errinfo);
|
||||
Begin
|
||||
if err then debugreturn println("{} : errorno = {}, errorinfo = {}!", msg, err, errinfo);
|
||||
println("[success] {} = {}", msg, errinfo);
|
||||
End
|
||||
|
||||
+1114
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user