This commit is contained in:
csh
2023-01-12 16:05:44 +08:00
parent e2db550f99
commit ce521a6a69
18 changed files with 204 additions and 206 deletions
-127
View File
@@ -1,127 +0,0 @@
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;
+26 -3
View File
@@ -7,7 +7,7 @@ docx := new TSDocxFile();
[err, errmsg] := docx.NewFile();
if err then
return println( 'Create NewFile Fail:{}.', errmsg);
//多级项目编号
sysparams['numId'] := docx.NumberingObject().NumberId('multilevel', 'decimal');
@@ -59,6 +59,9 @@ _14_TDocxChart(docx);
///TOfficeApi
_15_TOfficeApi(docx);
///ExecInnerTSL
_16_Template(docx);
///附注
_Annotation(docx);
@@ -68,7 +71,7 @@ _Faq(docx);
///目录
docx.AddTableContent(paragraphTitle, 1, 3);
v := docx.SaveAs('', UTF8ToAnsi('DocxFile使用帮助.docx'));
v := docx.SaveAs('', TOfficeApi().CurCodePageToGBK('DocxFile使用帮助.docx'));
println('Test Over!\n Save {}: {},time={}秒', file, v, mtoc);
//info := GetProfilerInfo(true);
@@ -801,12 +804,32 @@ Begin
_AddTitle(docx, 'TOfficeApi', 1);
_AddTitle(docx, 'TOfficeApi接口', 2);
conf := _LoadClassInfo(docx.GetPath() + '\\funcext\\TSOffice\\TSUtils\\TOffice.tsf', 'TOffice');
conf := _LoadClassInfo(docx.GetPath() + '\\funcext\\TSOffice\\TSUtils\\TOfficeApi.tsf', 'TOffice');
_AddFunctionHelpInfo(docx, '' $ paragraph $ '.1.', conf, 3);
println(' >>OK\n');
End;
Function _16_Template(docx);
Begin
paragraph := sysparams['Test'];
_PrintMsg('报告模板(ExecInnerTSL');
_AddTitle(docx, 'ExecInnerTSL', 1);
//添加段落
p := TOfficeObj('TParagraph');
p.Run.SetText( '系统提供docx.ExecInnerTSL()接口,用户可以制作自定义的报告模板,参考文档:' + 'funcext\\TSOffice\\template\\template.docx。');
p.Format.FirstLineIndent := 220; //指定段落第一行缩进的相对差异的值
p.Format.LeftIndent := 440;//段落左边距
p.Font.Name := '宋体';
p.Font.Color := 'FF0000';
p.Font.Bold := true;
p.Font.Size := 29;
p1 := docx.AddParagraph(p, -1, nil);
println(' >>OK\n');
End;
Function _AddTitle(docx, subject, level);
Begin
leftIndent := array((0,0), (425,425), (453,850), (708,1508));