Compare commits

...

8 Commits

Author SHA1 Message Date
csh 2384ca42b5 Merge branch 'master' into word 2023-07-14 10:37:15 +08:00
csh 845c6bb554 v1.3.5 2023-07-14 10:33:49 +08:00
csh f34d03a50f v1.3.4 2023-07-11 15:11:36 +08:00
csh ff6d23090e v1.3.3-patch1 2023-07-04 14:40:50 +08:00
csh f46240850e v1.3.3 2023-07-04 14:16:27 +08:00
csh ce331f4417 v1.3.2 2023-06-26 11:08:48 +08:00
csh c706d2d8d0 v1.3.2 2023-06-20 18:17:39 +08:00
csh 0e21645b2a v1.3.1-patch1 2023-06-05 17:08:00 +08:00
13 changed files with 143 additions and 45 deletions

View File

@ -84,7 +84,7 @@ Function _0_AddTitle(docx);
Begin
_PrintMsg('AddTitle');
p := _AddTitle(docx, '天软DOCX文档操作接口帮助文档', 0);//添加文档标题
p.Font.Size := 48;
p.Font.Size := 24;
p.Apply();
for i:=0 to 16 do
docx.AddLineBreak(-1);//换行符
@ -132,7 +132,7 @@ Begin
preface.Font.Name := '宋体';
preface.Font.Color := 'FF0000';
preface.Font.Bold := true;
preface.Font.Size := 32;
preface.Font.Size := 16;
p1 := docx.AddParagraph(preface, -1, nil);
println(' >>OK\n');
@ -303,7 +303,7 @@ Begin
p1.Run.SetText('本文档由天软科技制作。');
p1.Run.rPr.Name := '宋体';
p1.Run.rPr.Bold := true;
p1.Run.rPr.Size := 32;
p1.Run.rPr.Size := 16;
p1.Run.rPr.Color := 'FF0000';
p2 := docx.AddParagraph(p1, -1, nil);
//插入批注
@ -391,7 +391,7 @@ Begin
p1.Run.SetText( '插入案例。' );
p1.Run.rPr.Name := '宋体';
p1.Run.rPr.Bold := true;
p1.Run.rPr.Size := 32;
p1.Run.rPr.Size := 16;
p1.Run.rPr.Color := 'FF0000';
pAddRevision := docx.AddParagraph(p1, -1, nil);
//插入修订
@ -410,7 +410,7 @@ Begin
p1.Run.SetText( '删除修订案例。' );
p1.Run.rPr.Name := '宋体';
p1.Run.rPr.Bold := true;
p1.Run.rPr.Size := 32;
p1.Run.rPr.Size := 16;
p1.Run.rPr.Color := 'FF0000';
pDelRevision := docx.AddParagraph(p1, -1, nil);
//删除修订
@ -500,7 +500,7 @@ Begin
help.Font.Name := '宋体';
help.Font.Color := 'FF0000';
help.Font.Bold := true;
help.Font.Size := 30;
help.Font.Size := 15;
p1 := docx.AddParagraph(help, -1, nil);
section := docx.Sections(-1);//获取缺省章节
@ -514,10 +514,10 @@ Begin
p.Format.SpaceAfter := 0;
p.Font.Name := '宋体';
p.Font.Color := 'FF0000';
p.Font.Size := 16;
p.Font.Size := 8;
p2 := footer.AddParagraph(p, -1, nil);
p.Font.Size := 18;
pgno := footer.AddPageNumber('第 {0} 页,共 {1} 页', p.Font); //添加页码
p.Font.Size := 8;
pgno := footer.AddPageNumber('第 {-3} 页,共 {1} 页', p.Font); //添加页码
pgno.Format.Alignment := 'center'; //据中对齐
pgno.Format.SpaceAfter := 0;
pgno.Apply();
@ -530,7 +530,7 @@ Begin
//p.Format.Bdr.Bottom.val := 'single';//页眉横线
p.Font.Name := '宋体';
p.Font.Color := 'FF0000';
p.Font.Size := 16;
p.Font.Size := 8;
p1 := header.AddParagraph(p, -1, nil);
println(' >>OK\n');
@ -583,19 +583,19 @@ Begin
pTest := docx.AddParagraph(p1, -1, nil);
//修改部分文字字体
range := pTest.Range(3,2);
range.Font.Size := 32;
range.Font.Size := 16;
range.Font.Color := 'FF0000';
range.Font.Bold := true;
range.Apply();
//添加文字1
range1 := pTest.AddText(5, '科技开发有限');
range1.Font.Size := 28;
range1.Font.Size := 14;
range1.Font.Color := '00FF00';
range1.Font.Bold := true;
range1.Apply();
//添加文字2
range2 := pTest.AddText(0, '广东省');
range2.Font.Size := 28;
range2.Font.Size := 14;
range2.Font.Color := '0000FF';
range2.Font.Bold := true;
range2.Apply();
@ -603,7 +603,7 @@ Begin
//r.Text := 'Tinysoft';
r := pTest.AddText(-1, ':www.tinysoft.com.cn');//段落后追加
r.Font.Size := 20;
r.Font.Size := 10;
r.Font.Color := '0000FF';
r.Font.Bold := true;
r.Apply();
@ -656,7 +656,7 @@ Begin
p := TOfficeObj('TParagraph');
p.Format.numPr.Level := 0;//项目编号
p.Format.numPr.numId := docx.NumberingObject().NumberId('bullet', i); //项目编号
p.Font.Size := 28;
p.Font.Size := 14;
p.Font.Color := 'FF0000';
p.Font.Bold := true;
p.Format.LeftIndent := 700;//段落左边距
@ -829,7 +829,7 @@ Begin
p.Font.Name := '宋体';
p.Font.Color := 'FF0000';
p.Font.Bold := true;
p.Font.Size := 29;
p.Font.Size := 15;
p1 := docx.AddParagraph(p, -1, nil);
println(' >>OK\n');
@ -940,10 +940,10 @@ 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.Size := 12;
tbl.Format.Borders.Left.Size := 12;
tbl.Format.Borders.Bottom.Size := 12;
tbl.Format.Borders.Right.Size := 12;
tbl.Format.Borders.Top.Val := 'thinThickThinMediumGap';
tbl.Format.Borders.Left.Val := 'thinThickThinMediumGap';
tbl.Format.Borders.Bottom.Val := 'thinThickThinMediumGap';
@ -1144,7 +1144,7 @@ Begin
if title then Begin
p.Format.numPr.Level := 0;//项目编号
p.Format.numPr.numId := numId;
p.Font.Size := 28;
p.Font.Size := 14;
p.Font.Color := 'FF0000';
p.Font.Bold := true;
p.Format.LeftIndent := 500;//段落左边距

Binary file not shown.

View File

@ -8,9 +8,12 @@ TSOffice 项目:纯 TSL 代码实现 excel、word 文件读写
对应文件夹的dll文件按如下要求
- `fmt_pubkrnl_plugin` 放入 tsl 安装根目录下 Plugin 文件夹
- `office_plugin` 放入 tsl 安装根目录下 Plugin 文件夹
可选:
- `fmt_pubkrnl_plugin` 放入 tsl 安装根目录下 Plugin 文件夹若需要执行Demo文件夹下的[ExcelHelp.tsl](./Demo/ExcelHelp.tsl)和[WordHelp.tsl](./Demo/WordHelp.tsl),需要部署改动态库
### Linux
根据架构选择aarch64或x86版本将对应文件夹内容进行部署

Binary file not shown.

View File

@ -1,4 +1,4 @@
// Version 1.3.0
// Version 1.3.5
Function TOfficeObj(n);
Begin
@ -5851,7 +5851,7 @@ type TwrPr=class(NodeInfo)
,("field":"Strike","name":"w:strike","obj":Strike,"attrEx":"","nodeType":"empty","attrName":"", "desc":"单个删除线", "class":"")
,("field":"dStrike","name":"w:dstrike","obj":dStrike,"attrEx":"w:val","nodeType":"","attrName":"", "desc":"两个删除线", "class":"")
,("field":"kern","name":"w:kern","obj":kern,"attrEx":"w:val","nodeType":"","attrName":"", "desc":"字体紧排", "class":"")
,("field":"Size","name":"w:sz","obj":Size,"attrEx":"w:val","nodeType":"","attrName":"", "desc":"字体大小", "class":"")
,("field":"Sz","name":"w:sz","obj":Sz,"attrEx":"w:val","nodeType":"","attrName":"", "desc":"字体大小", "class":"")
,("field":"szCs","name":"w:szCs","obj":szCs,"attrEx":"w:val","nodeType":"","attrName":"", "desc":"复杂脚本字体大小", "class":"")
,("field":"U","name":"w:u","obj":U,"attrEx":"w:val","nodeType":"","attrName":"", "desc":"下划线", "class":"")
,("field":"vertAlign","name":"w:vertAlign","obj":vertAlign,"attrEx":"w:val","nodeType":"","attrName":"", "desc":"对齐方式.", "class":"")
@ -5878,6 +5878,16 @@ type TwrPr=class(NodeInfo)
rFont.XMLhAnsi := nName;
rFont.XMLascii := nName;
End;
Property Size read readSize write writeSize;
Function writeSize(n);
Begin
Sz := n * 2;
End;
Function readSize();
Begin
return int(Sz / 2);
End;
//Attributes
@ -5891,7 +5901,7 @@ type TwrPr=class(NodeInfo)
Strike;
dStrike;
kern;
Size;
Sz;
szCs;
U;
vertAlign;
@ -12133,7 +12143,7 @@ private
cnt := length(data);
//[err, axis] := ColumnNumberToName(2 * ind + 2);
[err, axis] := ColumnNumberToName(ind + 2);
Val.NumRef.F := fmt('Sheet1!${}$2:${}${}',axis, axis, cnt+1);
Val.NumRef.F := format('Sheet1!$%s$2:$%s$%d', axis, axis, cnt+1);
Val.NumRef.NumCache.PtCount := cnt;
Val.NumRef.NumCache.formatCode := 'General';
for i:=0 to cnt-1 do Begin
@ -12162,8 +12172,7 @@ private
else if istable(Categories) then Begin //word 图表
cnt := length(Categories);
//[err, axis] := ColumnNumberToName(2 * ind + 1);
//cat.StrRef.F := fmt('Sheet1!${}$2:${}${}',axis, axis, cnt+1);
cat.StrRef.F := fmt('Sheet1!$A$2:$A${}', cnt+1);
cat.StrRef.F := format('Sheet1!$A$2:$A$%d', cnt+1);
cat.StrRef.StrCache.PtCount := cnt;
for i:=0 to cnt-1 do Begin
Tpt := TOfficeObj('Tpt');
@ -13280,6 +13289,19 @@ Type TDocumentBody = Class(DocObject)
return array(length(errArr), tslFuncCount, errArr);
End;
Function RunTslCode(code, err);
Begin
try
//println('run code=[{}]', code);
if code <> '' then
eval(&code);
except
err := ExceptObject.ErrInfo;
return false;
End;
return true;
End;
Function ExecInnerTSLImpl(docx);
Begin
tslFuncCount := 0;
@ -13413,13 +13435,14 @@ Type TDocumentBody = Class(DocObject)
TOfficeApi().Set('CodePage', 'gbk');
try
tslFuncCount ++;
println('run code=[{}]', code);
if code <> '' then
eval(&code);
str := eval(&code);
except
println('run code={},err={}', code, ExceptObject.ErrInfo);
errArr[ length(errArr) ] := array('code':code, 'err':ExceptObject.ErrInfo);
str := '';
End;
tslFuncCount ++;
tNode := curRun.node_.FirstChildElement('w:t');
if not ifObj(tNode) then Begin //没有在外部插入文字
tslBegParagraphNode.DeleteChild(curRunNode);

View File

@ -1,4 +1,4 @@
// Version 1.3.0
// Version 1.3.5
Type TSDocxFile = Class
///Version: V1.0 2022-09-20
@ -18,7 +18,17 @@ Type TSDocxFile = Class
Function Create(alias, fname); overload;
Begin
init();
OpenFile(alias, fname);
OpenFile(alias, fname, nil);
End;
///构造函数打开已经存在的docx文件
///alias: string文件目录别名
///fname: string文件名
///passwd: string密码
Function Create(alias, fname, passwd); overload;
Begin
init();
OpenFile(alias, fname, passwd);
End;
Function Destory();
@ -34,11 +44,12 @@ Type TSDocxFile = Class
///打开docx文件
///alias: string文件目录别名
///fname: string文件名
///[passwd]: string密码
///返回:[err, errmsg]
Function OpenFile(alias, fname);
Function OpenFile(alias, fname, passwd);
Begin
if not ifObj(zipfile_) then return array(-1, 'Create ZipFile object fail.');
[err, errmsg] := zipfile_.Open(alias, fname);
[err, errmsg] := zipfile_.Open(alias, fname, passwd);
if err=0 then Begin
document_ := new docxDocument(zipfile_);
End;
@ -56,6 +67,12 @@ Type TSDocxFile = Class
End;
return array(err, errmsg);
End;
///设置密码
Function SetPassword(passwd)
Begin
zipfile_.Password := passwd;
End;
///保存文件
///返回: [err, info]

View File

@ -1,4 +1,4 @@
// Version 1.3.0
// Version 1.3.5
Type TSExcelFile = Class
///Version: V1.0 2022-08-08
@ -18,7 +18,17 @@ Type TSExcelFile = Class
Function Create(alias, fname); overload;
Begin
init();
OpenFile(alias, fname);
OpenFile(alias, fname, nil);
End;
///构造函数打开已经存在的excel文件
///alias: string文件目录别名
///fname: string文件名
///passwd: string密码
Function Create(alias, fname, passwd); overload;
Begin
init();
OpenFile(alias, fname, passwd);
End;
//析构函数
@ -35,12 +45,13 @@ Type TSExcelFile = Class
///打开excel文件
///alias: string文件目录别名
///fname: string文件名
///[passwd]: string密码
///返回: [err, errmsg]
Function OpenFile(alias, fname);
Function OpenFile(alias, fname, passwd);
Begin
init();
if not ifObj(zipfile_) then return array(-1, 'Create ZipFile object fail.');
[err, errmsg] := zipfile_.Open(alias, fname);
[err, errmsg] := zipfile_.Open(alias, fname, passwd);
if err=0 then Begin
workbook_ := new xlsxWorkBook(zipfile_);
workbook_.Load();
@ -69,6 +80,12 @@ Type TSExcelFile = Class
return zipfile_.Save();
End;
///设置密码
Function SetPassword(passwd)
Begin
zipfile_.Password := passwd;
End;
///打开二进制内容
///data: 二进制数据
///返回: [err, errmsg]

View File

@ -0,0 +1,4 @@
Function TOfficeInit();
Begin
sysparams['TOffice sys api'] := nil;
End;

View File

@ -30,16 +30,16 @@ Type TDocxChart = Class(TSChart)
Function GetInnerXml();
Begin
ETU := 360045;//1cm单位
return fmt('<w:r>
return format('<w:r>
<w:drawing>
<wp:inline>
<wp:extent cx="{}" cy="{}"/>
<wp:extent cx="%d" cy="%d"/>
<wp:effectExtent l="0" t="0" r="19050" b="19050"/>
<wp:docPr id="{}" name="{}"/>
<wp:docPr id="%d" name="%s"/>
<wp:cNvGraphicFramePr />
<a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
<a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/chart">
<c:chart xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" r:id="rId{}"/>
<c:chart xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" r:id="rId%d"/>
</a:graphicData>
</a:graphic>
</wp:inline>

View File

@ -30,7 +30,7 @@ Type TSTag = Class
Begin
if not ifArray(map_) then Begin
map_ := array();
println('attribute={}',attribute_);
//println('attribute={}',attribute_);
arr := Str2Array(attribute_, ' ');
for i := 0 to length(arr)-1 do Begin
kv := Str2Array(arr[i], '=');

View File

@ -124,7 +124,7 @@ xmlns:v="urn:schemas-microsoft-com:vml">
if ifObj(node) then Begin
[err, col, row] := excel_.CellNameToCoordinates(cell);
clientData := TOfficeObj('TClientData');
clientData.Anchor := fmt('{},23,{},0,{},{},{},5',col, row, 1+col+lineCount, colCount+col-1, 1+row+lineCount);
clientData.Anchor := format('%d,23,%d,0,%d,%d,%d,5',col, row, 1+col+lineCount, colCount+col-1, 1+row+lineCount);
clientData.Row := row - 1;
ClientData.Column := col - 1;
node.UnMarshal(clientData.Marshal());

View File

@ -101,7 +101,7 @@ private
name := "列" $ col_index++;
excel_.WorkBook().SetCellValue(sheetName_, cell, name);
end
table_str += fmt('<tableColumn id="{}" name="{}" />', id++, name);
table_str += format('<tableColumn id="%d" name="%s" />', id, name);
end
table_str += "</tableColumns>";

View File

@ -1,5 +1,39 @@
# 更新日志
## 2023-7-14
### V1.3.5
#### word
段落字体大小设置调整对齐VBA设置
## 2023-7-11
### V1.3.4
修复加密Bug
## 2023-7-4
### V1.3.3
word/excel 新增加密方法`SetPassword`,升级`OpenFile(alias, fileName, Password)`
## 2023-6-26
### V1.3.2
修复.net使用rdo2执行失败问题使用rdo2时候需调用`TOfficeInit()`初始化
#### word
1. 修复word模板`template.docx`执行失败问题
## 2023-6-20
更新部署方式,不再依赖`fmt_pubkrnl_plugin.dll`,详情见[README](./README.md)
## 2023-4-26
### V1.3.1