1169 lines
39 KiB
Plaintext
1169 lines
39 KiB
Plaintext
///Version:V1.03
|
||
///Create by Tinysoft.
|
||
///自动生成 TSDocxFile 帮助文件
|
||
mtic;
|
||
//SetProfiler(7);
|
||
docx := new TSDocxFile();
|
||
[err, errmsg] := docx.NewFile();
|
||
if err then
|
||
return println( 'Create NewFile Fail:{}.', errmsg);
|
||
|
||
//多级项目编号
|
||
sysparams['numId'] := docx.NumberingObject().NumberId('multilevel', 'decimal');
|
||
|
||
///Test 0: 文档标题
|
||
paragraphTitle := _0_AddTitle(docx);
|
||
|
||
///Test 1: 文档说明
|
||
_1_HelpInfo(docx);
|
||
|
||
///Test 2: 文档API
|
||
_2_DocumentApi(docx);
|
||
|
||
///Test 3: TParagraph对象
|
||
_3_Paragraph(docx);
|
||
|
||
///Test 4: TTable对象
|
||
_4_Table(docx);
|
||
|
||
///Test 5: TPicture对象
|
||
_5_Picture(docx);
|
||
|
||
///Test 6: TComments对象
|
||
_6_Comments(docx);
|
||
|
||
///Test 7: TRevision对象
|
||
_7_Revision(docx);
|
||
|
||
///文档属性
|
||
_8_CoreProperties(docx);
|
||
|
||
///章节、页脚、页眉
|
||
_9_TDocSection(docx);
|
||
|
||
///文本框
|
||
_10_TTextBox(docx);
|
||
|
||
///TRange
|
||
_11_TRange(docx);
|
||
|
||
///TDocxStyles
|
||
_12_TDocxStyles(docx);
|
||
|
||
///TNumbering
|
||
_13_TNumbering(docx);
|
||
|
||
///TDocxChart
|
||
_14_TDocxChart(docx);
|
||
|
||
///TOfficeApi
|
||
_15_TOfficeApi(docx);
|
||
|
||
///ExecInnerTSL
|
||
_16_Template(docx);
|
||
|
||
///附注
|
||
_Annotation(docx);
|
||
|
||
///Faq
|
||
_Faq(docx);
|
||
|
||
///目录
|
||
docx.AddTableContent(paragraphTitle, 1, 3);
|
||
|
||
v := docx.SaveAs('', TOfficeApi().CurCodePageToGBK('DocxFile使用帮助.docx'));
|
||
println('Test Over!\n Save {}: {},time={}秒', file, v, mtoc);
|
||
|
||
//info := GetProfilerInfo(true);
|
||
//exportfile(ftstream(),'','\\temp\\ProfilerInfo.stm',info);
|
||
|
||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||
///子函数
|
||
///Test 1: 文档标题
|
||
Function _0_AddTitle(docx);
|
||
Begin
|
||
_PrintMsg('AddTitle');
|
||
p := _AddTitle(docx, '天软DOCX文档操作接口帮助文档', 0);//添加文档标题
|
||
p.Font.Size := 48;
|
||
p.Apply();
|
||
for i:=0 to 16 do
|
||
docx.AddLineBreak(-1);//换行符
|
||
|
||
r := array(('文档编号','TS-XXXXXX-XXX'),('文档版本','Version 1.0'),('修订日期',datetimetostr(Now())),('保密级别',''));
|
||
tbl := docx.CreateTable(r);
|
||
tbl.Format.Indent := 500;
|
||
tbl.format.IndentType := 'dxa';
|
||
//设置列宽
|
||
tbl.ColumnWidth(1, 2000);
|
||
tbl.ColumnWidth(2, 6000);
|
||
tbl := docx.InsertTable(tbl, -1);
|
||
for i:=1 to 4 do Begin
|
||
//第1列底纹设置
|
||
cell := tbl.Cell(i, 1);
|
||
cell.Format.Shading.Val := 'clear';
|
||
cell.Format.Shading.Color := 'auto';
|
||
cell.Format.Shading.Fill := 'D9D9D9';
|
||
cell.Apply();
|
||
//第2列,据中对齐
|
||
c2 := tbl.Cell(i, 2);
|
||
c2.Format.vAlign := 'center';
|
||
c2.pFormat.Alignment := 'center';
|
||
c2.Apply();
|
||
End;
|
||
tbl.Apply();
|
||
p := docx.AddPageBreak(-1);//换页符
|
||
|
||
println(' >>OK\n');
|
||
return p;
|
||
End;
|
||
|
||
///Test 1: 前言
|
||
Function _1_HelpInfo(docx);
|
||
Begin
|
||
paragraph := sysparams['Test'];
|
||
_PrintMsg('前言');
|
||
_AddTitle(docx, '前言', 1); //第一段标题
|
||
|
||
//添加段落
|
||
preface := TOfficeObj('TParagraph');
|
||
preface.Run.SetText( '本文档由word_help.tsl脚本,调用本文档中描述的接口自动生成!' );
|
||
preface.Format.FirstLineIndent := 220; //指定段落第一行缩进的相对差异的值
|
||
preface.Format.LeftIndent := 440;//段落左边距
|
||
preface.Font.Name := '宋体';
|
||
preface.Font.Color := 'FF0000';
|
||
preface.Font.Bold := true;
|
||
preface.Font.Size := 32;
|
||
p1 := docx.AddParagraph(preface, -1, nil);
|
||
|
||
println(' >>OK\n');
|
||
End;
|
||
|
||
///Test 2: 文档API
|
||
Function _2_DocumentApi(docx);
|
||
Begin
|
||
paragraph := sysparams['Test'];
|
||
_PrintMsg('Document Api');
|
||
_AddTitle(docx, '文档接口(TSDocFile)', 1); //第二段标题
|
||
|
||
_AddTitle(docx, 'TSDocFile方法', 2);
|
||
conf := _LoadClassInfo(docx.GetPath() + '\\funcext\\TSOffice\\TSDocxFile.tsf', 'TSDocxFile');
|
||
_AddFunctionHelpInfo(docx, paragraph $ '.1.', conf, 3);
|
||
|
||
println(' >>OK\n');
|
||
End;
|
||
|
||
///Test 3: TParagraph对象
|
||
Function _3_Paragraph(docx);
|
||
Begin
|
||
paragraph := sysparams['Test'];
|
||
_PrintMsg('TParagraph对象');
|
||
_AddTitle(docx, 'TParagraph对象(段落)', 1); //第三段标题
|
||
|
||
///TParagraph属性
|
||
_AddTitle(docx, 'TParagraph属性(段落属性TwpPr对象、字体属性TwrPr对象)', 2); //第二级标题
|
||
attrs := array(('类别':'缺省w:r元素', '接口':'Run', '说明':'TRun对象'),
|
||
('类别':'段落属性', '接口':'Format', '说明':'TwpPr对象'),
|
||
('类别':'字体属性', '接口':'Font', '说明':'TwrPr对象'));
|
||
_AddClassHelpTable(docx, attrs);//添加表格:TParagraph属性
|
||
|
||
///TParagraph方法
|
||
_AddTitle(docx, 'TParagraph方法', 2);
|
||
conf := _LoadClassInfo(docx.GetPath() + '\\funcext\\TSOffice\\TOfficeObj.tsf', 'TParagraph');
|
||
conf union= _LoadClassInfo(docx.GetPath() + '\\funcext\\TSOffice\\TOfficeObj.tsf', 'DocObject');
|
||
_AddFunctionHelpInfo(docx, '' $ paragraph $ '.2.', conf, 3);
|
||
|
||
///TRun方法
|
||
_AddTitle(docx, 'TRun方法(段落中w:r元素)', 2);
|
||
conf := _LoadClassInfo(docx.GetPath() + '\\funcext\\TSOffice\\TOfficeObj.tsf', 'TRun');
|
||
conf union= _LoadClassInfo(docx.GetPath() + '\\funcext\\TSOffice\\TOfficeObj.tsf', 'DocObject');
|
||
_AddFunctionHelpInfo(docx, '' $ paragraph $ '.3.', conf, 3);
|
||
|
||
///TTabStops对象
|
||
_AddTitle(docx, 'TTabStops对象', 2);
|
||
conf := _LoadClassInfo(docx.GetPath() + '\\funcext\\TSOffice\\TOfficeObj.tsf', 'TTabStops');
|
||
_AddFunctionHelpInfo(docx, '' $ paragraph $ '.4.', conf, 3);
|
||
|
||
///TabStop属性
|
||
_AddTitle(docx, 'TTabStop属性', 2); //第二级标题
|
||
attrs := array();
|
||
formatObj := new TOfficeObj('TTabStop');
|
||
_LoadObjectAttributes(formatObj, attrs, 'TTabStop属性', '');
|
||
_AddClassHelpTable(docx, attrs);
|
||
|
||
println(' >>OK\n');
|
||
End;
|
||
|
||
///Test 4: TTable对象
|
||
Function _4_Table(docx);
|
||
Begin
|
||
paragraph := sysparams['Test'];
|
||
_PrintMsg('TTable对象');
|
||
_AddTitle(docx, 'TTable对象(表格)', 1); //第四段标题
|
||
|
||
///TTable对象
|
||
_AddTitle(docx, 'TTable对象属性', 2); //第二级标题
|
||
tbl := new TOfficeObj('TTable');
|
||
attrs := array(('类别':'单元格属性', '接口':'Paragraph', '说明':'TParagrap对象:设置单元格段落格式、字体格式'));
|
||
_LoadObjectAttributes(tbl.Format, attrs, '表格样式', 'Format');
|
||
_LoadObjectAttributes(tbl.FormatEx, attrs, '浮动表设置', 'FormatEx');
|
||
_AddClassHelpTable(docx, attrs);//添加表格:TTable属性
|
||
|
||
///TTable方法
|
||
_AddTitle(docx, 'TTable方法', 2);
|
||
conf := _LoadClassInfo(docx.GetPath() + '\\funcext\\TSOffice\\TOfficeObj.tsf', 'TTable');
|
||
_AddFunctionHelpInfo(docx, '' $ paragraph $ '.2.', conf, 3);
|
||
|
||
///TCell对象
|
||
_AddTitle(docx, 'TCell对象属性', 2);
|
||
attrs := array();
|
||
formatObj := new TOfficeObj('TwTcPr');
|
||
_LoadObjectAttributes(formatObj, attrs, '单元格属性', 'Format');
|
||
_AddClassHelpTable(docx, attrs);//添加表格:TCell属性
|
||
|
||
///TCell方法
|
||
_AddTitle(docx, 'TCell方法', 2);
|
||
conf := _LoadClassInfo(docx.GetPath() + '\\funcext\\TSOffice\\TOfficeObj.tsf', 'TCell');
|
||
conf union= _LoadClassInfo(docx.GetPath() + '\\funcext\\TSOffice\\TOfficeObj.tsf', 'TDocumentBody');
|
||
conf union= _LoadClassInfo(docx.GetPath() + '\\funcext\\TSOffice\\TOfficeObj.tsf', 'DocObject');
|
||
_AddFunctionHelpInfo(docx, '' $ paragraph $ '.4.', conf, 3);
|
||
|
||
println(' >>OK\n');
|
||
End;
|
||
|
||
///Test 5: TPicture对象
|
||
Function _5_Picture(docx);
|
||
Begin
|
||
paragraph := sysparams['Test'];
|
||
_PrintMsg('TPicture对象');
|
||
_AddTitle(docx, 'TPicture对象(图像)', 1); //第五段标题
|
||
|
||
///TPicture对象属性
|
||
_AddTitle(docx, 'TPicture对象属性', 2);
|
||
attrs := array(('类别':'图片信息', '接口':'Image', '说明':'二进制内容'),
|
||
('类别':'图片信息', '接口':'Descr', '说明':'图像描述'),
|
||
('类别':'图片信息', '接口':'Width', '说明':'图像宽度(cm)'),
|
||
('类别':'图片信息', '接口':'Height', '说明':'图像高度(cm)')
|
||
);
|
||
//pPr := new TOfficeObj('TpicsPpr');
|
||
//_LoadObjectAttributes(pPr, attrs, '图像属性', 'Format');
|
||
_AddClassHelpTable(docx, attrs);//添加表格:TPicture对象
|
||
|
||
///TPicture方法
|
||
_AddTitle(docx, 'TPicture方法', 2);
|
||
conf := _LoadClassInfo(docx.GetPath() + '\\funcext\\TSOffice\\TOfficeObj.tsf', 'TPicture');
|
||
_AddFunctionHelpInfo(docx, '' $ paragraph $ '.2.', conf, 3);
|
||
|
||
///插入图像案例
|
||
_AddTitle(docx, '插入图像案例', 2);
|
||
picture := TOfficeObj('TPicture');
|
||
picture.Descr := '插入图像案例';
|
||
readfile(rwbinary(), '', docx.GetPath() + '\\funcext\\TSOffice\\template\\tinysoft.gif', 0, 1024*1024, data);
|
||
picture.Image := data;
|
||
p := docx.AddPicture(picture, -1);
|
||
//添加图像外边框
|
||
p.Format.Ln.SolidFill.SchemeClr.Val := 'accent1';
|
||
p.Apply();
|
||
|
||
println(' >>OK\n');
|
||
End;
|
||
|
||
///Test 6: TDocComments对象
|
||
Function _6_Comments(docx);
|
||
Begin
|
||
paragraph := sysparams['Test'];
|
||
_PrintMsg('TDocComments对象');
|
||
_AddTitle(docx, 'TDocComments对象(批注集合)', 1); //第六段标题
|
||
|
||
///TDocComments方法
|
||
_AddTitle(docx, 'TDocComments方法', 2);
|
||
conf := _LoadClassInfo(docx.GetPath() + '\\funcext\\TSOffice\\TOfficeObj.tsf', 'TDocComments');
|
||
_AddFunctionHelpInfo(docx, '' $ paragraph $ '.1.', conf, 3);
|
||
|
||
///TDocComment对象属性
|
||
_AddTitle(docx, 'TDocComment对象属性', 2);
|
||
attrs := array(
|
||
('类别':'属性', '接口':'sPos', '说明':'被标注文字在文档中的位置'),
|
||
('类别':'属性', '接口':'SelectLength', '说明':'选择文字的长度,汉字当一个字符,不计算换行符号')
|
||
);
|
||
pPr := new TOfficeObj('TDocComment');
|
||
_LoadObjectAttributes(pPr, attrs, '属性', 'Format');
|
||
_AddClassHelpTable(docx, attrs);//添加表格:TDocComment对象
|
||
|
||
///TDocComment方法
|
||
_AddTitle(docx, 'TDocComment方法', 2);
|
||
conf := _LoadClassInfo(docx.GetPath() + '\\funcext\\TSOffice\\TOfficeObj.tsf', 'TDocComment');
|
||
_AddFunctionHelpInfo(docx, '' $ paragraph $ '.2.', conf, 3);
|
||
|
||
//插入批注案例
|
||
_AddTitle(docx, '插入批注案例', 2);
|
||
//添加测试段落文字
|
||
p1 := TOfficeObj('TParagraph');
|
||
p1.Format.FirstLineIndent := 220; //指定段落第一行缩进的相对差异的值
|
||
p1.Format.LeftIndent := 440;//段落左边距
|
||
p1.Run.SetText('本文档由天软科技制作。');
|
||
p1.Run.rPr.Name := '宋体';
|
||
p1.Run.rPr.Bold := true;
|
||
p1.Run.rPr.Size := 32;
|
||
p1.Run.rPr.Color := 'FF0000';
|
||
p2 := docx.AddParagraph(p1, -1, nil);
|
||
//插入批注
|
||
comment := docx.NewComment('Tinysoft', '深圳市天软科技开发有限公司');
|
||
comment.sPos := 4;
|
||
comment.SelectLength := 4;
|
||
p2.AddComment(comment);
|
||
//嵌套批注
|
||
comment := docx.NewComment('Tinysoft', '嵌套批注:Tinysoft');
|
||
comment.sPos := 4;
|
||
comment.SelectLength := 2;
|
||
p2.AddComment(comment);
|
||
//2层嵌套批注
|
||
comment := docx.NewComment('Tinysoft', '2层嵌套批注Tiny');
|
||
comment.sPos := 4;
|
||
comment.SelectLength := 1;
|
||
p2.AddComment(comment);
|
||
//2层嵌套批注
|
||
comment := docx.NewComment('Tinysoft', '2层嵌套批注Software');
|
||
comment.sPos := 5;
|
||
comment.SelectLength := 1;
|
||
p2.AddComment(comment);
|
||
|
||
//读取批注案例
|
||
_AddTitle(docx, '读取批注案例', 2);
|
||
r := array();
|
||
commentObjs := docx.Comments();
|
||
for i:=0 to commentObjs.Count()-1 do Begin
|
||
comment := commentObjs.Comment(i);
|
||
r[i]['批注ID'] := comment.CommentID;
|
||
r[i]['批注文字范围'] := comment.Text();
|
||
End;
|
||
tbl := docx.CreateTable(r, true, true);
|
||
tbl.Format.Indent := 500;
|
||
tbl.format.IndentType := 'dxa';
|
||
tbl := docx.InsertTable(tbl, -1);
|
||
|
||
//删除批注案例
|
||
_AddTitle(docx, '删除批注案例(执行docx.Comments().Comment(3).Delete();)', 2);
|
||
//删除批注
|
||
docx.Comments().Comment(3).Delete();
|
||
r := array();
|
||
commentObjs := docx.Comments();
|
||
for i:=0 to commentObjs.Count()-1 do Begin
|
||
comment := commentObjs.Comment(i);
|
||
r[i]['批注ID'] := comment.CommentID;
|
||
r[i]['批注文字范围'] := comment.Text();
|
||
End;
|
||
tbl := docx.CreateTable(r, true, true);
|
||
tbl.Format.Indent := 500;
|
||
tbl.format.IndentType := 'dxa';
|
||
tbl := docx.InsertTable(tbl, -1);
|
||
|
||
println(' >>OK\n');
|
||
End;
|
||
|
||
///Test 7: TRevision对象
|
||
Function _7_Revision(docx);
|
||
Begin
|
||
paragraph := sysparams['Test'];
|
||
_PrintMsg('TRevision对象');
|
||
_AddTitle(docx, 'TRevision对象(修订)', 1); //第七段标题
|
||
|
||
///TRevision对象
|
||
_AddTitle(docx, 'TRevision属性', 2);
|
||
attrs := array(
|
||
('类别':'属性', '接口':'sPos', '说明':'被标注文字在文档中的位置'),
|
||
('类别':'属性', '接口':'SelectLength', '说明':'选择文字的长度,汉字当一个字符,不计算换行符号')
|
||
);
|
||
formatObj := new TOfficeObj('TRevision');
|
||
_LoadObjectAttributes(formatObj, attrs, '属性', '');
|
||
_AddClassHelpTable(docx, attrs);//添加表格:TRevision属性
|
||
|
||
///TRevision方法
|
||
_AddTitle(docx, 'TRevision方法', 2);
|
||
conf := _LoadClassInfo(docx.GetPath() + '\\funcext\\TSOffice\\TOfficeObj.tsf', 'TRevision');
|
||
_AddFunctionHelpInfo(docx, '' $ paragraph $ '.2.', conf, 3);
|
||
|
||
//插入修订案例
|
||
_AddTitle(docx, '插入修订案例', 2);
|
||
//添加测试段落文字
|
||
p1 := TOfficeObj('TParagraph');
|
||
p1.Format.FirstLineIndent := 220; //指定段落第一行缩进的相对差异的值
|
||
p1.Format.LeftIndent := 440;//段落左边距
|
||
p1.Run.SetText( '插入案例。' );
|
||
p1.Run.rPr.Name := '宋体';
|
||
p1.Run.rPr.Bold := true;
|
||
p1.Run.rPr.Size := 32;
|
||
p1.Run.rPr.Color := 'FF0000';
|
||
pAddRevision := docx.AddParagraph(p1, -1, nil);
|
||
//插入修订
|
||
revision := TOfficeObj('TRevision');
|
||
revision.Author := '修订者';
|
||
revision.sPos := 2;
|
||
revision.InsText := '修订';
|
||
pAddRevision.AddRevision(revision);
|
||
|
||
//删除修订案例
|
||
_AddTitle(docx, '删除修订案例', 2);
|
||
//添加测试段落文字
|
||
p1 := TOfficeObj('TParagraph');
|
||
p1.Format.FirstLineIndent := 220; //指定段落第一行缩进的相对差异的值
|
||
p1.Format.LeftIndent := 440;//段落左边距
|
||
p1.Run.SetText( '删除修订案例。' );
|
||
p1.Run.rPr.Name := '宋体';
|
||
p1.Run.rPr.Bold := true;
|
||
p1.Run.rPr.Size := 32;
|
||
p1.Run.rPr.Color := 'FF0000';
|
||
pDelRevision := docx.AddParagraph(p1, -1, nil);
|
||
//删除修订
|
||
revision := TOfficeObj('TRevision');
|
||
revision.Author := '修订者';
|
||
revision.sPos := 4;
|
||
revision.SelectLength := 2;
|
||
pDelRevision.DelRevision(revision);
|
||
|
||
//读取修订案例
|
||
_AddTitle(docx, '读取修订案例', 2);
|
||
revisions := pAddRevision.Revisions();
|
||
revisions union= pDelRevision.Revisions();
|
||
r := array();
|
||
for i:=0 to length(revisions)-1 do Begin
|
||
r[i]['Act'] := revisions[i].Act();
|
||
r[i]['Text'] := revisions[i].Text();
|
||
//if i=1 then
|
||
// revisions[i].Accept(); //接受修订
|
||
// revisions[i].Reject(); //拒绝修订
|
||
End;
|
||
tbl := docx.CreateTable(r, true, true);
|
||
tbl.Format.Indent := 500;
|
||
tbl.format.IndentType := 'dxa';
|
||
tbl := docx.InsertTable(tbl, -1);
|
||
|
||
println(' >>OK\n');
|
||
End;
|
||
|
||
///文档属性
|
||
Function _8_CoreProperties(docx);
|
||
Begin
|
||
paragraph := sysparams['Test'];
|
||
_PrintMsg('TCoreProperties对象');
|
||
_AddTitle(docx, 'TCoreProperties对象(文档属性)', 1); //第八段标题
|
||
|
||
///TCoreProperties对象
|
||
_AddTitle(docx, 'TCoreProperties对象', 2);
|
||
attrs := array(
|
||
('类别':'属性', '接口':'Author', '说明':'读写属性:作者'),
|
||
('类别':'属性', '接口':'Category', '说明':'读写属性:此包内容的分类。示例值可能包括:简历、信函、财务预测、提案或技术演示。'),
|
||
('类别':'属性', '接口':'Description', '说明':'读写属性:文档描述'),
|
||
('类别':'属性', '接口':'Subject', '说明':'读写属性:文档主题'),
|
||
('类别':'属性', '接口':'Title', '说明':'读写属性:文档名称'),
|
||
('类别':'属性', '接口':'Version', '说明':'读写属性:自由格式版本字符串'),
|
||
('类别':'属性', '接口':'Rversion', '说明':'读写属性:此修订的编号,每次保存文档时按Word递增。'),
|
||
('类别':'属性', '接口':'KeyWords', '说明':'读写属性:可能用作本文档搜索词的描述性词或短短语'),
|
||
('类别':'属性', '接口':'Created', '说明':'读写属性:创建日期'),
|
||
('类别':'属性', '接口':'Modified', '说明':'读写属性:上次修改文档的时间'),
|
||
('类别':'属性', '接口':'LastModifiedBy', '说明':'读写属性:上次修改文档的人的姓名或其他标识符(如电子邮件地址)'),
|
||
);
|
||
_AddClassHelpTable(docx, attrs);//添加表格:TCoreProperties属性
|
||
|
||
println(' >>OK\n');
|
||
End;
|
||
|
||
///章节、页脚、页眉
|
||
Function _9_TDocSection(docx);
|
||
Begin
|
||
paragraph := sysparams['Test'];
|
||
_PrintMsg('TDocSection对象');
|
||
_AddTitle(docx, 'TDocSection对象(章节)', 1); //第九段标题
|
||
|
||
///TDocSection对象
|
||
_AddTitle(docx, 'TDocSection对象(章节)', 2);
|
||
formatObj := new TOfficeObj('TDocSection');
|
||
_LoadObjectAttributes(formatObj, attrs, '属性', '');
|
||
_AddClassHelpTable(docx, attrs);//添加表格:TDocSection属性
|
||
|
||
///TDocSection方法
|
||
_AddTitle(docx, 'TDocSection方法', 2);
|
||
conf := _LoadClassInfo(docx.GetPath() + '\\funcext\\TSOffice\\TOfficeObj.tsf', 'TDocSection');
|
||
_AddFunctionHelpInfo(docx, '' $ paragraph $ '.2.', conf, 3);
|
||
|
||
///THeaderFooter方法
|
||
_AddTitle(docx, 'THeaderFooter方法', 2);
|
||
conf := _LoadClassInfo(docx.GetPath() + '\\funcext\\TSOffice\\TOfficeObj.tsf', 'TDocHeaderFooter');
|
||
conf union= _LoadClassInfo(docx.GetPath() + '\\funcext\\TSOffice\\TOfficeObj.tsf', 'TDocumentBody');
|
||
_AddFunctionHelpInfo(docx, '' $ paragraph $ '.3.', conf, 3);
|
||
|
||
///添加页眉、页脚案例
|
||
_AddTitle(docx, '添加页眉、页脚案例', 2);
|
||
help := TOfficeObj('TParagraph');
|
||
help.Run.SetText( '参考word_help.tsl脚本(TDocxFile::Sections, TDocSection::AddHeader, TDocSection::AddFooter)!' );
|
||
help.Format.FirstLineIndent := 220; //指定段落第一行缩进的相对差异的值
|
||
help.Format.LeftIndent := 440;//段落左边距
|
||
help.Font.Name := '宋体';
|
||
help.Font.Color := 'FF0000';
|
||
help.Font.Bold := true;
|
||
help.Font.Size := 30;
|
||
p1 := docx.AddParagraph(help, -1, nil);
|
||
|
||
section := docx.Sections(-1);//获取缺省章节
|
||
footer := section.AddFooter('');//添加缺省页脚
|
||
//页脚内容
|
||
p := TOfficeObj('TParagraph');
|
||
p.Run.SetText( '电 话:0755-83937039' );
|
||
p.AddRun('网 址:http://www.tinysoft.com.cn', true);
|
||
p.AddRun('公司地址:深圳市福田区莲花街道梅岭社区新闻路59号深茂商业中心19F', true);
|
||
p.Format.Bdr.Top.val := 'single';//页脚横线
|
||
p.Format.SpaceAfter := 0;
|
||
p.Font.Name := '宋体';
|
||
p.Font.Color := 'FF0000';
|
||
p.Font.Size := 16;
|
||
p2 := footer.AddParagraph(p, -1, nil);
|
||
p.Font.Size := 18;
|
||
pgno := footer.AddPageNumber('第 {0} 页,共 {1} 页', p.Font); //添加页码
|
||
pgno.Format.Alignment := 'center'; //据中对齐
|
||
pgno.Format.SpaceAfter := 0;
|
||
pgno.Apply();
|
||
|
||
//添加页眉
|
||
header := section.AddHeader('');//添加缺省页眉
|
||
p := TOfficeObj('TParagraph');
|
||
p.Run.SetText( '深圳市天软科技开发有限公司' );
|
||
p.Format.Alignment := 'right'; //据右对齐
|
||
//p.Format.Bdr.Bottom.val := 'single';//页眉横线
|
||
p.Font.Name := '宋体';
|
||
p.Font.Color := 'FF0000';
|
||
p.Font.Size := 16;
|
||
p1 := header.AddParagraph(p, -1, nil);
|
||
|
||
println(' >>OK\n');
|
||
End;
|
||
|
||
///文本框
|
||
Function _10_TTextBox(docx);
|
||
Begin
|
||
paragraph := sysparams['Test'];
|
||
_PrintMsg('TTextBox对象');
|
||
_AddTitle(docx, 'TTextBox对象(文本框)', 1); //第十段标题
|
||
|
||
///TTextBox方法
|
||
_AddTitle(docx, 'TTextBox方法', 2);
|
||
conf := _LoadClassInfo(docx.GetPath() + '\\funcext\\TSOffice\\TOfficeObj.tsf', 'TDocumentBody');
|
||
conf := select * from conf where leftstr(['funcname'],10) <> 'AddPicture' end;
|
||
_AddFunctionHelpInfo(docx, '' $ paragraph $ '.1.', conf, 3);
|
||
|
||
println(' >>OK\n');
|
||
End;
|
||
|
||
///TRange
|
||
Function _11_TRange(docx);
|
||
Begin
|
||
paragraph := sysparams['Test'];
|
||
_PrintMsg('TRange对象');
|
||
_AddTitle(docx, 'TRange对象', 1); //第11段标题
|
||
|
||
///TRange对象
|
||
_AddTitle(docx, 'TRange对象', 2);
|
||
attrs := array(
|
||
('类别':'属性', '接口':'Font', '说明':'字体属性,参考段落字体属性'),
|
||
('类别':'属性', '接口':'Text', '说明':'读写属性:文字内容')
|
||
);
|
||
_AddClassHelpTable(docx, attrs);//添加表格:TRange属性
|
||
|
||
///TRange方法
|
||
_AddTitle(docx, 'TRange方法', 2);
|
||
conf := _LoadClassInfo(docx.GetPath() + '\\funcext\\TSOffice\\TOfficeObj.tsf', 'TRange');
|
||
_AddFunctionHelpInfo(docx, '' $ paragraph $ '.2.', conf, 3);
|
||
|
||
//修改字体属性案例
|
||
_AddTitle(docx, '字体属性设置案例', 2);
|
||
//添加测试段落文字
|
||
p1 := TOfficeObj('TParagraph');
|
||
p1.Format.FirstLineIndent := 220; //指定段落第一行缩进的相对差异的值
|
||
p1.Format.LeftIndent := 440;//段落左边距
|
||
p1.Run.SetText( '深圳市天软公司' );
|
||
p1.Run.rPr.Name := '宋体';
|
||
pTest := docx.AddParagraph(p1, -1, nil);
|
||
//修改部分文字字体
|
||
range := pTest.Range(3,2);
|
||
range.Font.Size := 32;
|
||
range.Font.Color := 'FF0000';
|
||
range.Font.Bold := true;
|
||
range.Apply();
|
||
//添加文字1
|
||
range1 := pTest.AddText(5, '科技开发有限');
|
||
range1.Font.Size := 28;
|
||
range1.Font.Color := '00FF00';
|
||
range1.Font.Bold := true;
|
||
range1.Apply();
|
||
//添加文字2
|
||
range2 := pTest.AddText(0, '广东省');
|
||
range2.Font.Size := 28;
|
||
range2.Font.Color := '0000FF';
|
||
range2.Font.Bold := true;
|
||
range2.Apply();
|
||
//r := pTest.Range(2,10);
|
||
//r.Text := 'Tinysoft';
|
||
|
||
r := pTest.AddText(-1, ':www.tinysoft.com.cn');//段落后追加
|
||
r.Font.Size := 20;
|
||
r.Font.Color := '0000FF';
|
||
r.Font.Bold := true;
|
||
r.Apply();
|
||
|
||
println(' >>OK\n');
|
||
End;
|
||
|
||
///TDocxStyles
|
||
Function _12_TDocxStyles(docx);
|
||
Begin
|
||
paragraph := sysparams['Test'];
|
||
_PrintMsg('TDocxStyles对象');
|
||
_AddTitle(docx, 'TDocxStyles对象', 1); //第12段标题
|
||
|
||
///TDocxStyles方法
|
||
_AddTitle(docx, 'TDocxStyles方法', 2);
|
||
conf := _LoadClassInfo(docx.GetPath() + '\\funcext\\TSOffice\\document\\TDocxStyles.tsf', 'TDocxStyles');
|
||
_AddFunctionHelpInfo(docx, '' $ paragraph $ '.1.', conf, 3);
|
||
|
||
_AddTitle(docx, '样式(TDocxStyle)', 2); //第二级标题
|
||
attrs := array();
|
||
formatObj := new TOfficeObj('TDocxStyle');
|
||
_LoadObjectAttributes(formatObj, attrs, '样式', '');
|
||
_AddClassHelpTable(docx, attrs);
|
||
|
||
println(' >>OK\n');
|
||
End;
|
||
|
||
///TNumbering
|
||
Function _13_TNumbering(docx);
|
||
Begin
|
||
paragraph := sysparams['Test'];
|
||
_PrintMsg('TNumbering对象');
|
||
_AddTitle(docx, 'TNumbering对象', 1); //第13段标题
|
||
|
||
///TNumbering方法
|
||
_AddTitle(docx, 'TNumbering方法', 2);
|
||
conf := _LoadClassInfo(docx.GetPath() + '\\funcext\\TSOffice\\document\\TNumbering.tsf', 'TNumbering');
|
||
_AddFunctionHelpInfo(docx, '' $ paragraph $ '.1.', conf, 3);
|
||
|
||
///TNumStyle对象
|
||
_AddTitle(docx, 'TNumStyle属性', 2);
|
||
formatObj := new TOfficeObj('TNumStyle');
|
||
_LoadObjectAttributes(formatObj, attrs, '属性', '');
|
||
_AddClassHelpTable(docx, attrs);//添加表格:TNumStyle属性
|
||
|
||
//缺省项目符号
|
||
_AddTitle(docx, '缺省项目符号', 2);
|
||
for i:=0 to 6 do Begin
|
||
p := TOfficeObj('TParagraph');
|
||
p.Format.numPr.Level := 0;//项目编号
|
||
p.Format.numPr.numId := docx.NumberingObject().NumberId('bullet', i); //项目编号
|
||
p.Font.Size := 28;
|
||
p.Font.Color := 'FF0000';
|
||
p.Font.Bold := true;
|
||
p.Format.LeftIndent := 700;//段落左边距
|
||
p.Run.SetText( 'NumberId("bullet", ' $ i $ ')' );
|
||
docx.AddParagraph(p, -1, nil);
|
||
End;
|
||
|
||
println(' >>OK\n');
|
||
End;
|
||
|
||
///TDocxChart
|
||
Function _14_TDocxChart(docx);
|
||
Begin
|
||
paragraph := sysparams['Test'];
|
||
_PrintMsg('TChart对象');
|
||
_AddTitle(docx, 'TChart对象', 1); //第14段标题
|
||
|
||
///TDocxChart方法
|
||
_AddTitle(docx, 'TChart方法', 2);
|
||
conf := _LoadClassInfo(docx.GetPath() + '\\funcext\\TSOffice\\TOfficeObj.tsf', 'TChart');
|
||
_AddFunctionHelpInfo(docx, '' $ paragraph $ '.1.', conf, 3);
|
||
|
||
///TChart对象
|
||
_AddTitle(docx, 'TChart属性', 2);
|
||
formatObj := new TOfficeObj('TChart');
|
||
_LoadObjectAttributes(formatObj, attrs, '属性', '');
|
||
_AddClassHelpTable(docx, attrs);//添加表格:TChart属性
|
||
|
||
data := array(
|
||
('年度':2019, '深圳':26927, '广州':23628, '佛山':10751, '东莞':9482, '惠州':4177, '其它':32706),
|
||
('年度':2020, '深圳':27670, '广州':25019, '佛山':10816, '东莞':9650, '惠州':4222, '其它':33383.92),
|
||
('年度':2021, '深圳':30665, '广州':28232, '佛山':12157, '东莞':10855, '惠州':4977, '其它':37483.7)
|
||
);
|
||
tmpData := nils(3,7);
|
||
tmpData[:,:] := data;
|
||
_AddTitle(docx, '案例一:广东省2019——2021年GDP(柱状图)', 2);
|
||
chart := TOfficeObj('TChart');
|
||
chart.Width := 15;
|
||
chart.Height := 9;
|
||
chart.Type := 'col';
|
||
chart.VaryColors := true;
|
||
chart.Name := 'GD-GDP-1';
|
||
chart.Title := '广东省2019——2021年GDP(单位:亿元)';
|
||
names := FieldNames(data)[1:];
|
||
for i:=0 to length(data)-1 do
|
||
chart.AddSeries('' $ data[i]['年度'], names, (tmpData[i])[1:]);
|
||
chart.ShowLegendKey := false;
|
||
chart.Legend.Position := 'bottom';
|
||
chart.ShowBubbleSize := true;
|
||
chart.ShowCatName := false;
|
||
chart.ShowPercent := true;
|
||
chart.ShowSerName := false;
|
||
chart.ShowVal := false;
|
||
chart.ShowBlanksAs := 'zero';
|
||
chart.DataTable := true;
|
||
docx.AddChart(chart, -1);
|
||
|
||
_AddTitle(docx, '案例二:广东省2019——2021年GDP(折线图)', 2);
|
||
chart.Name := 'GD-GDP-2';
|
||
chart.Type := 'line';
|
||
chart.ShowBubbleSize := false;
|
||
chart.ShowPercent := false;
|
||
chart.DataTable := false;
|
||
chart.ClearSeries();
|
||
for i:=0 to length(names)-1 do begin
|
||
k := names[i];
|
||
chart.AddSeries(names[i], array('2019','2020','2021'), sselect [k] from data end);
|
||
End;
|
||
docx.AddChart(chart, -1);
|
||
|
||
_AddTitle(docx, '案例三:广东省2021年GDP(饼状图)', 2);
|
||
chart.Name := 'GD-GDP-3';
|
||
chart.Title := '广东省2021年GDP(单位:亿元)';
|
||
chart.Type := 'pie';
|
||
chart.ShowCatName := true;
|
||
chart.ClearSeries();
|
||
chart.AddSeries('广东省', names, (tmpData[2])[1:]);
|
||
docx.AddChart(chart, -1);
|
||
|
||
charts := array(("Type":"area","图表类型":"标准二维面积图"),
|
||
("Type":"areastacked","图表类型":"二维堆积面积图"),
|
||
("Type":"areapercentstacked","图表类型":"二维百分比堆积面积图"),
|
||
("Type":"area3d","图表类型":"标准三维面积图"),
|
||
("Type":"area3dstacked","图表类型":"三维堆积面积图"),
|
||
("Type":"area3dpercentstacked","图表类型":"三维百分比堆积面积图"),
|
||
("Type":"bar","图表类型":"二维簇状条形图"),
|
||
("Type":"barstacked","图表类型":"二维堆积条形图"),
|
||
("Type":"barpercentstacked","图表类型":"二维百分比堆积条形图"),
|
||
("Type":"bar3dclustered","图表类型":"三维簇状条形图"),
|
||
("Type":"bar3dstacked","图表类型":"三维堆积条形图"),
|
||
("Type":"bar3dpercentstacked","图表类型":"三维百分比堆积条形图"),
|
||
("Type":"bar3dconeclustered","图表类型":"三维簇状水平圆锥图"),
|
||
("Type":"bar3dconestacked","图表类型":"三维堆积水平圆锥图"),
|
||
("Type":"bar3dconepercentstacked","图表类型":"三维堆积百分比水平圆锥图"),
|
||
("Type":"bar3dpyramidclustered","图表类型":"三维簇状水平棱锥图"),
|
||
("Type":"bar3dpyramidstacked","图表类型":"三维堆积水平棱锥图"),
|
||
("Type":"bar3dpyramidpercentstacked","图表类型":"三维堆积百分比水平棱锥图"),
|
||
("Type":"bar3dcylinderclustered","图表类型":"三维簇状水平圆柱图"),
|
||
("Type":"bar3dcylinderstacked","图表类型":"三维堆积水平圆柱图"),
|
||
("Type":"bar3dcylinderpercentstacked","图表类型":"三维堆积百分比水平圆柱图"),
|
||
("Type":"col","图表类型":"二维簇状柱形图"),
|
||
("Type":"colstacked","图表类型":"二维堆积柱形图"),
|
||
("Type":"colpercentstacked","图表类型":"二维百分比堆积柱形图"),
|
||
("Type":"col3d","图表类型":"三维簇状柱形图"),
|
||
("Type":"col3dclustered","图表类型":"三维柱形图"),
|
||
("Type":"col3dstacked","图表类型":"三维堆积柱形图"),
|
||
("Type":"col3dpercentstacked","图表类型":"三维百分比堆积柱形图"),
|
||
("Type":"col3dcone","图表类型":"三维圆锥图"),
|
||
("Type":"col3dconeclustered","图表类型":"三维簇状圆锥图"),
|
||
("Type":"col3dconestacked","图表类型":"三维堆积圆锥图"),
|
||
("Type":"col3dconepercentstacked","图表类型":"三维百分比堆积圆锥图"),
|
||
("Type":"col3dpyramid","图表类型":"三维棱锥图"),
|
||
("Type":"col3dpyramidclustered","图表类型":"三维簇状棱锥图"),
|
||
("Type":"col3dpyramidstacked","图表类型":"三维堆积棱锥图"),
|
||
("Type":"col3dpyramidpercentstacked","图表类型":"三维百分比堆积棱锥图"),
|
||
("Type":"col3dcylinder","图表类型":"三维圆柱图"),
|
||
("Type":"col3dcylinderclustered","图表类型":"三维簇状圆柱图"),
|
||
("Type":"col3dcylinderstacked","图表类型":"三维堆积圆柱图"),
|
||
("Type":"col3dcylinderpercentstacked","图表类型":"三维百分比堆积圆柱图"),
|
||
("Type":"bubble","图表类型":"气泡图"),
|
||
("Type":"bubble3d","图表类型":"3D气泡图"),
|
||
("Type":"doughnut","图表类型":"圆环图"),
|
||
("Type":"line","图表类型":"折线图"),
|
||
("Type":"pie3d","图表类型":"三维饼图"),
|
||
("Type":"pie","图表类型":"饼图"),
|
||
("Type":"radar","图表类型":"雷达图"),
|
||
("Type":"scatter","图表类型":"散点图"),
|
||
("Type":"surface3d","图表类型":"三维曲面图"),
|
||
("Type":"wireframesurface3d","图表类型":"三维曲面图(框架图)"),
|
||
("Type":"contour","图表类型":"曲面图"),
|
||
("Type":"wireframecontour","图表类型":"曲面图(俯视框架图)"));
|
||
_AddTitle(docx, '系统支持的图表类型', 2);
|
||
tbl := docx.CreateTable(charts, true, true);
|
||
tbl.Format.Indent := 500;
|
||
tbl.format.IndentType := 'dxa';
|
||
//设置列宽
|
||
tbl.ColumnWidth(1, 2000);
|
||
tbl.ColumnWidth(2, 6000);
|
||
tbl.ColumnWidth(3, 8000);
|
||
tbl := docx.InsertTable(tbl, -1);
|
||
|
||
println(' >>OK\n');
|
||
End;
|
||
|
||
///TOfficeApi
|
||
Function _15_TOfficeApi(docx);
|
||
Begin
|
||
paragraph := sysparams['Test'];
|
||
_PrintMsg('TOfficeApi接口');
|
||
_AddTitle(docx, 'TOfficeApi', 1);
|
||
|
||
_AddTitle(docx, 'TOfficeApi接口', 2);
|
||
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, '报告模板(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));
|
||
p := docx.AddHeading(subject, -1, level);//标题
|
||
if level then Begin
|
||
p.Format.FirstLineChars := 0;
|
||
p.Format.LeftChars := 0;
|
||
p.Format.Hanging := leftIndent[level][0];
|
||
p.Format.LeftIndent := leftIndent[level][1];//段落左边距
|
||
End
|
||
else //标题
|
||
p.Format.Alignment := 'center'; //据中对齐
|
||
//p.Font.Name := '宋体';
|
||
p.Font.rFont.hint := 'eastAsia';
|
||
p.Font.Bold := true;
|
||
if level then Begin
|
||
p.Format.numPr.Level := level - 1; //项目级别
|
||
p.Format.numPr.numId := sysparams['numId']; //项目编号
|
||
End;
|
||
p.Apply();
|
||
return p;
|
||
End;
|
||
|
||
///添加函数帮助信息
|
||
Function _AddFunctionHelpInfo(docx, head, conf, level);
|
||
Begin
|
||
ind := 1;
|
||
hash := array();
|
||
for i:=0 to length(conf)-1 do Begin
|
||
if not ifString(conf[i]['comment']) or conf[i]['comment'] = '' then continue;
|
||
arr := str2array(conf[i]['funcname'], '(');
|
||
k := lowercase(arr[0]);
|
||
if hash[k]=1 and not (k in array('create')) then continue;
|
||
hash[k] := 1;
|
||
subject := head $ ind++ $ ' ' $ conf[i]['funcname'];
|
||
_AddTitle(docx, conf[i]['funcname'], level);
|
||
|
||
//添加函数声明段落
|
||
pFun := TOfficeObj('TParagraph');
|
||
pFun.Format.Hanging := 660; //悬挂缩进
|
||
pFun.Format.LeftIndent := 1760;//段落左边距
|
||
pFun.Font.Name := '宋体';
|
||
println(' Subject:{}', subject);
|
||
pFun.Run.SetText( 'Function ' + conf[i]['funcname'] );
|
||
p1 := docx.AddParagraph(pFun, -1, nil);//函数方法
|
||
//设置首行字体颜色、黑体
|
||
firstRun := p1.GetRun(0);
|
||
firstRun.Font.Color := 'FF0000';
|
||
firstRun.Font.Bold := true;
|
||
firstRun.Apply();
|
||
|
||
//添加函数帮助信息段落
|
||
arr := str2array(conf[i]['comment'], '\n');
|
||
for j:=0 to length(arr)-1 do Begin
|
||
pFun.Run.SetText('///' + arr[j]);
|
||
p2 := docx.AddParagraph(pFun, -1, nil);
|
||
End;
|
||
|
||
End;
|
||
End;
|
||
|
||
///从对象中加载属性
|
||
Function _LoadObjectAttributes(obj, r, itemType, api);
|
||
Begin
|
||
if not ifArray(r) then r := array();
|
||
attrs := obj.GetAttrs();
|
||
ind := length(r);
|
||
for i:=0 to length(attrs)-1 do Begin
|
||
if attrs[i, 3] = 'disable' then continue;
|
||
r[ind]['类别'] := itemType;
|
||
r[ind]['接口'] := ifthen(api='','',api + '.') + attrs[i, 0];
|
||
r[ind]['说明'] := attrs[i, 3];
|
||
ind++;
|
||
End;
|
||
|
||
children := obj.GetChildren();
|
||
for i:=0 to length(children)-1 do Begin
|
||
descText := children[i]['desc'];
|
||
if descText = 'disable' then continue;
|
||
if ifObj(children[i]['obj']) then Begin
|
||
if descText = '' then Begin
|
||
_LoadObjectAttributes(children[i]['obj'], r, itemType, ifthen(api='','',api + '.') $ children[i]['field']);
|
||
ind := length(r);
|
||
continue;
|
||
End
|
||
else Begin
|
||
if not ifArray(sysParams['objs']) then
|
||
sysParams['objs'] := array();
|
||
cnt := length(sysParams['objs']);
|
||
sysParams['objs'][cnt] := array('name':children[i]['field'], 'obj':children[i]['obj'], 'desc':children[i]['desc'], 'class':children[i]['class']);
|
||
descText := descText $ '(' $ children[i]['class'] $ '对象)';
|
||
End;
|
||
End
|
||
r[ind]['类别'] := itemType;
|
||
r[ind]['接口'] := ifthen(api='','',api + '.') + children[i]['field'];
|
||
r[ind]['说明'] := descText;
|
||
ind++;
|
||
End;
|
||
End;
|
||
|
||
///添加对象属性表格
|
||
Function _AddClassHelpTable(docx, data);
|
||
Begin
|
||
//设置边框属性
|
||
tbl := docx.CreateTable(data, true, true);
|
||
tbl.Format.Borders.Top.Size := 24;
|
||
tbl.Format.Borders.Left.Size := 24;
|
||
tbl.Format.Borders.Bottom.Size := 24;
|
||
tbl.Format.Borders.Right.Size := 24;
|
||
tbl.Format.Borders.Top.Val := 'thinThickThinMediumGap';
|
||
tbl.Format.Borders.Left.Val := 'thinThickThinMediumGap';
|
||
tbl.Format.Borders.Bottom.Val := 'thinThickThinMediumGap';
|
||
tbl.Format.Borders.Right.Val := 'thinThickThinMediumGap';
|
||
tbl.Format.Borders.InsideH.Val := 'single';
|
||
tbl.Format.Borders.InsideV.Val := 'single';
|
||
tbl.Format.Borders.Top.color := 'D0D0D0';
|
||
tbl.Format.Borders.Left.color := 'D0D0D0';
|
||
tbl.Format.Borders.Bottom.color := 'D0D0D0';
|
||
tbl.Format.Borders.Right.color := 'D0D0D0';
|
||
tbl.Format.Borders.Top.themeColor := 'accent3';
|
||
tbl.Format.Borders.Left.themeColor := 'accent3';
|
||
tbl.Format.Borders.Bottom.themeColor := 'accent3';
|
||
tbl.Format.Borders.Right.themeColor := 'accent3';
|
||
tbl.Format.Borders.Top.themeTint := '99';
|
||
tbl.Format.Borders.Left.themeTint := '99';
|
||
tbl.Format.Borders.Bottom.themeTint := '99';
|
||
tbl.Format.Borders.Right.themeTint := '99';
|
||
|
||
//设置列宽
|
||
tbl.ColumnWidth(1, 600);
|
||
tbl.ColumnWidth(2, 2100);
|
||
tbl.ColumnWidth(3, 2100);
|
||
tbl.ColumnWidth(4, 6000);
|
||
|
||
//设置表格左边距
|
||
tbl.Format.Indent := 500;
|
||
tbl.format.IndentType := 'dxa';
|
||
//tbl.TblPr.Style := 1;
|
||
tbl := docx.InsertTable(tbl, -1);
|
||
|
||
//设置表头底纹
|
||
rows := tbl.Rows();
|
||
cols := tbl.Cols();
|
||
for i:=1 to cols do Begin
|
||
cell := tbl.Cell(1, i);
|
||
cell.Format.Shading.ThemeFillTint := 32;
|
||
cell.Format.Shading.ThemeFill := 'accent5';
|
||
cell.Format.Shading.Fill := 'DBEEF3';
|
||
cell.Apply();
|
||
End;
|
||
|
||
//设置第1列底纹
|
||
for i:=1 to rows do Begin
|
||
cell := tbl.Cell(i, 1);
|
||
cell.Format.Shading.ThemeFillTint := 32;
|
||
cell.Format.Shading.ThemeFill := 'accent5';
|
||
cell.Format.Shading.Fill := 'DBEEF3';
|
||
cell.Apply();
|
||
End;
|
||
|
||
//合并单元格
|
||
fields := select distinct [1] as 'type' from data where thisrowindex > 0 end;
|
||
for i:=0 to length(fields)-1 do begin
|
||
key := fields[i]['type'];
|
||
r := select thisrowindex+1 as 'row' from data where [1] = key end;
|
||
begRow := r[0]['row'];
|
||
endRow := r[length(r)-1]['row'];
|
||
[err, begCell] := CoordinatesToCellName(2, begRow);
|
||
[err, endCell] := CoordinatesToCellName(2, endRow);
|
||
tbl.Merge(begCell, endCell, true);
|
||
|
||
//设置合并单元格据中对齐
|
||
cell := tbl.Cell(begRow, 2);
|
||
cell.Format.vAlign := 'center';
|
||
cell.Apply();
|
||
End;
|
||
End;
|
||
|
||
///打印信息
|
||
Function _PrintMsg(msg);
|
||
Begin
|
||
if ifNil(sysparams['Test']) then sysParams['Test'] := 0;
|
||
println('This is test {}: {}.',sysParams['Test'],msg);
|
||
sysParams['Test'] := sysParams['Test'] + 1;
|
||
End;
|
||
|
||
///从TSDocxFile.tsf文件加载API
|
||
function _LoadClassInfo(f, className);
|
||
Begin
|
||
_ReplaceFileName(f);
|
||
if istable(sysparams[f]) then Begin
|
||
return sysParams[f, className];
|
||
End;
|
||
[err,fh] := io_open(f);
|
||
if err then return array();
|
||
[err, data] := io_read(fh);
|
||
io_close(fh);
|
||
if err then return array();
|
||
sysparams[f] := array();
|
||
|
||
comment := '';
|
||
cName := '';
|
||
funcname := '';
|
||
t := array();
|
||
lines := str2array(string(data), '\n');
|
||
for i:=0 to length(lines)-1 do begin
|
||
line := lines[i];
|
||
if leftstr(line, 5) = 'Type ' then Begin
|
||
a := str2array(line, ' ');
|
||
cName := a[1];
|
||
continue;
|
||
End;
|
||
if lowercase(leftstr(line, 3)) = 'end' then Begin
|
||
if cName <> '' then Begin
|
||
sysParams[f, cName] := t;
|
||
End;
|
||
cName := '';
|
||
t := array();
|
||
continue;
|
||
End;
|
||
if cName = '' then continue;
|
||
str := ' End;';
|
||
if leftstr(line, length(str)) = str then Begin
|
||
comment := '';
|
||
name := '';
|
||
continue;
|
||
End;
|
||
func := ' Function ';
|
||
if leftstr(line, length(func)) = func then Begin
|
||
funcname := rightstr(line, length(line)-length(func));
|
||
if funcname <> '' then Begin
|
||
n := length(t);
|
||
t[n]['funcname'] := funcname;
|
||
t[n]['comment'] := comment;
|
||
t[n]['name'] := name;
|
||
End;
|
||
comment := '';
|
||
name := '';
|
||
continue;
|
||
End;
|
||
if ParseRegExpr('\/\/\/(.*)$',line,'',result,MPos,Mlen) and length(result) then Begin
|
||
str := result[0][1];
|
||
comment := comment + (comment = '' ? '' : '\n') + str;
|
||
if name='' then begin
|
||
name := str;
|
||
end;
|
||
End;
|
||
End;
|
||
return sysParams[f, className];
|
||
End;
|
||
|
||
///附注
|
||
Function _Annotation(docx);
|
||
Begin
|
||
r := sysParams['objs'];
|
||
if not istable(r) then return;
|
||
sysParams['objs'] := array();
|
||
paragraph := sysparams['Test'];
|
||
_PrintMsg('附注');
|
||
_AddTitle(docx, '附注一:内置对象', 1); //附注标题
|
||
|
||
ind := 1;
|
||
hash := array();
|
||
while i < length(r) do Begin
|
||
attrs := array();
|
||
_LoadObjectAttributes(r[i]['obj'], attrs, '属性', '');
|
||
classname := r[i]['class'];
|
||
if istable(attrs) and ifnil(hash[classname]) then Begin
|
||
_AddTitle(docx, classname $ '对象:' $ r[i]['desc'], 2);
|
||
attrs := array();
|
||
_LoadObjectAttributes(r[i]['obj'], attrs, '属性', '');
|
||
_AddClassHelpTable(docx, attrs);//添加表格
|
||
if istable(sysParams['objs']) then Begin
|
||
r union= sysParams['objs'];
|
||
sysParams['objs'] := array();
|
||
End;
|
||
hash[classname] := 1;
|
||
End;
|
||
i++;
|
||
End;
|
||
|
||
println(' >>OK\n');
|
||
End;
|
||
|
||
Function _Faq(docx);
|
||
Begin
|
||
paragraph := sysparams['Test'];
|
||
_PrintMsg('FAQ');
|
||
_AddTitle(docx, '附注二:FAQ', 1); //附注FAQ标题
|
||
|
||
[err,fh] := io_open( _ReplaceFileName(docx.GetPath() + '\\funcext\\TSOffice\\template\\faq.txt') );
|
||
if err then return t;
|
||
[err, data] := io_read(fh);
|
||
io_close(fh);
|
||
lines := str2array(string(data), '\n');
|
||
numId := docx.NumberingObject().NumberId('bullet', 1); //项目编号
|
||
for i:=0 to length(lines)-1 do Begin
|
||
title := flase;
|
||
str := lines[i];
|
||
p := TOfficeObj('TParagraph');
|
||
if str <> '' then Begin
|
||
if str[1] = '*' then Begin
|
||
title := true;
|
||
str := str[2:];
|
||
println(' FAQ: {}', str);
|
||
End;
|
||
p.Run.SetText( str );
|
||
End;
|
||
if title then Begin
|
||
p.Format.numPr.Level := 0;//项目编号
|
||
p.Format.numPr.numId := numId;
|
||
p.Font.Size := 28;
|
||
p.Font.Color := 'FF0000';
|
||
p.Font.Bold := true;
|
||
p.Format.LeftIndent := 500;//段落左边距
|
||
End
|
||
else Begin
|
||
p.Format.Hanging := 300; //悬挂缩进
|
||
p.Format.LeftIndent := 880;//段落左边距
|
||
End;
|
||
docx.AddParagraph(p, -1, nil);
|
||
End;
|
||
|
||
println(' >>OK\n');
|
||
End;
|
||
|
||
Function _ReplaceFileName(f);
|
||
Begin
|
||
if f[1] = '/' then
|
||
f := ReplaceStr(f, '\\', '/');
|
||
return f;
|
||
End; |