Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
19b8614c93 | ||
|
|
3df8ce2be0 | ||
|
|
6b0f11cebb | ||
|
|
bbe0821f68 | ||
|
|
ea528f3094 | ||
|
|
95a00e7002 | ||
|
|
2b62e4e1a5 | ||
|
|
a2c3905cd0 | ||
|
|
ca03e53285 | ||
|
|
d57631a19a | ||
|
|
c05b646104 | ||
|
|
39b7549665 | ||
|
|
93533c41a0 | ||
|
|
0f07603d73 | ||
|
|
3c16ce510a | ||
|
|
3243db0e2d | ||
|
|
fdd2bd0fef | ||
|
|
2d423ca1fb | ||
|
|
0e35cc0463 | ||
|
|
c7b7971d9a | ||
|
|
066a8f6562 | ||
|
|
9e04cc2cff | ||
|
|
bb8d3591ac | ||
|
|
037cb41560 | ||
|
|
5469ca318d | ||
|
|
c3432d1812 | ||
|
|
53d83f91ae | ||
|
|
893a3a928b | ||
|
|
72554969bb | ||
|
|
fa8800e20d | ||
|
|
92257c380f | ||
|
|
fb22cf9b0a | ||
|
|
a3df0d5df9 | ||
|
|
b4ef4a531c | ||
|
|
f499526f04 | ||
|
|
c1a93bb16e | ||
|
|
03e101fa46 | ||
|
|
1231868aa7 | ||
|
|
6d6281229c | ||
|
|
522e52ed46 | ||
|
|
a774f57335 | ||
|
|
800f91870d | ||
|
|
e5d011e59b | ||
|
|
d588ac67d4 | ||
|
|
dc7d48c318 | ||
|
|
fcb2a8e7b3 | ||
|
|
91f3c5af49 | ||
|
|
c16566d2f1 | ||
|
|
3607dab833 | ||
|
|
9f660c09f6 | ||
|
|
1e9b8f3a12 | ||
|
|
b617f235fa | ||
|
|
ee7b7164ce | ||
|
|
aab0a498c6 | ||
|
|
5172a78e3e | ||
|
|
de0af521bc | ||
|
|
8cd87118d5 | ||
|
|
9c917cfb70 | ||
|
|
d72d88d68a | ||
|
|
5f1064794d | ||
|
|
493691b930 | ||
|
|
f3094c148c | ||
|
|
addc41144e | ||
|
|
8aa050461c |
@@ -0,0 +1,4 @@
|
|||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
*.cmd
|
||||||
|
script.ps1
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
[submodule "funcext/TSOffice/Extensions/OfficeVba"]
|
||||||
|
path = funcext/TSOffice/Extensions/OfficeVba
|
||||||
|
url = https://git.mytsl.cn/tinysoft/OfficeVba.git
|
||||||
@@ -73,7 +73,7 @@ content := docx.AddTableContent(paragraphTitle, 1, 3);
|
|||||||
docx.AddPageBreak(content.node_);
|
docx.AddPageBreak(content.node_);
|
||||||
|
|
||||||
|
|
||||||
v := docx.SaveAs('', TOfficeApi().CurCodePageToGBK('DocxFile使用帮助.docx'));
|
v := docx.SaveAs('', 'DocxFile使用帮助.docx');
|
||||||
println('Test Over!\n Save {}: {},time={}秒', file, v, mtoc);
|
println('Test Over!\n Save {}: {},time={}秒', file, v, mtoc);
|
||||||
|
|
||||||
//info := GetProfilerInfo(true);
|
//info := GetProfilerInfo(true);
|
||||||
@@ -1,28 +1,28 @@
|
|||||||
path := ExtractFileDir(ExtractFileDir(PluginPath()));
|
path := ExtractFileDir(ExtractFileDir(PluginPath()));
|
||||||
{$IFNDEF Win32}
|
{$IFNDEF Win32}
|
||||||
path := path + '\\funcext\\TSOffice\\TSExcelFile.tsf';
|
path := path + '/funcext/TSOffice/TSXlsxFile.tsf';
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
path := path + '/funcext/TSOffice/TSExcelFile.tsf';
|
path := path + '\\funcext\\TSOffice\\TSXlsxFile.tsf';
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
funcs := LoadClassInfo(path);
|
funcs := LoadClassInfo(path);
|
||||||
|
|
||||||
testing := 1;
|
testing := 1;
|
||||||
file := new TSExcelFile();
|
file := new TSXlsxFile();
|
||||||
[err, errinfo] := file.NewFile();
|
[err, errinfo] := file.NewFile();
|
||||||
if err then
|
if err then
|
||||||
return PrintError("NewFile", err, errinfo);
|
return PrintError("NewFile", err, errinfo);
|
||||||
PrintSuccess("NewFile", testing++);
|
PrintSuccess("NewFile", testing++);
|
||||||
|
|
||||||
file.SetSheetName('Sheet1', 'ExcelFile');
|
file.SetSheetName('Sheet1', 'XlsxFile');
|
||||||
PrintSuccess("SetSheetName", testing++);
|
PrintSuccess("SetSheetName", testing++);
|
||||||
|
|
||||||
file.NewSheet("Functions");
|
file.NewSheet("Functions");
|
||||||
PrintSuccess("NewSheet", testing++);
|
PrintSuccess("NewSheet", testing++);
|
||||||
|
|
||||||
file.SetDefaultSheet('ExcelFile');
|
file.SetDefaultSheet('TSXlsxFile');
|
||||||
|
|
||||||
richtext := TOfficeObj('TRichText');
|
richtext := TOfficeObj('TRichText');
|
||||||
txt1 := richtext.AddText('TSExcelFile类 ');
|
txt1 := richtext.AddText('TSXlsxFile类 ');
|
||||||
txt1.Font.Size := 35;
|
txt1.Font.Size := 35;
|
||||||
txt1.Font.Color := "FF0000";
|
txt1.Font.Color := "FF0000";
|
||||||
txt1.Font.Bold := 1;
|
txt1.Font.Bold := 1;
|
||||||
@@ -34,15 +34,16 @@ txt2.Font.Bold := 1;
|
|||||||
txt2.Font.Italic := 1;
|
txt2.Font.Italic := 1;
|
||||||
txt2.Font.Color := "FFC0CB";
|
txt2.Font.Color := "FFC0CB";
|
||||||
|
|
||||||
file.SetCellRichText('ExcelFile', 'A1', richtext);
|
file.SetCellRichText('XlsxFile', 'A1', richtext);
|
||||||
PrintSuccess("SetCellRichText", testing++);
|
PrintSuccess("SetCellRichText", testing++);
|
||||||
[err, richText] := file.GetCellRichText('ExcelFile', 'A1');
|
[err, richText] := file.GetCellRichText('XlsxFile', 'A1');
|
||||||
if err then
|
if err then
|
||||||
return PrintError("GetCellRichText", err, errinfo);
|
return PrintError("GetCellRichText", err, errinfo);
|
||||||
PrintSuccess("GetCellRichText", testing++);
|
PrintSuccess("GetCellRichText", testing++);
|
||||||
|
|
||||||
file.MergeCell('ExcelFile', 'A1', 'C1');
|
file.MergeCell('XlsxFile', 'A1', 'C1');
|
||||||
PrintSuccess("MergeCell", testing++);
|
PrintSuccess("MergeCell", testing++);
|
||||||
|
file.SetRowHeight('XlsxFile', 1, 60);
|
||||||
|
|
||||||
|
|
||||||
style := TOfficeObj('TStyle');
|
style := TOfficeObj('TStyle');
|
||||||
@@ -65,15 +66,15 @@ style.Fill.Gradient.Stop2.Color := "E0EBF5";
|
|||||||
styleId := file.NewStyle(style);
|
styleId := file.NewStyle(style);
|
||||||
PrintSuccess("NewStyle", testing++);
|
PrintSuccess("NewStyle", testing++);
|
||||||
|
|
||||||
file.SetCellStyle("ExcelFile", 'A1', 'C1', styleId);
|
file.SetCellStyle("XlsxFile", 'A1', 'C1', styleId);
|
||||||
|
|
||||||
file.SetCellValue("ExcelFile", "A3", "索引");
|
file.SetCellValue("XlsxFile", "A3", "索引");
|
||||||
file.SetCellValue("ExcelFile", "B3", "函数名称");
|
file.SetCellValue("XlsxFile", "B3", "函数名称");
|
||||||
file.SetCellValue("ExcelFile", "C3", "功能");
|
file.SetCellValue("XlsxFile", "C3", "功能");
|
||||||
file.SetColWidth("ExcelFile", "A", "A", 6);
|
file.SetColWidth("XlsxFile", "A", "A", 6);
|
||||||
file.SetColWidth("ExcelFile", "B", "B", 55);
|
file.SetColWidth("XlsxFile", "B", "B", 55);
|
||||||
file.SetColWidth("ExcelFile", "C", "C", 100);
|
file.SetColWidth("XlsxFile", "C", "C", 100);
|
||||||
file.SetCellStyle("ExcelFile", "A3", "C3", styleId);
|
file.SetCellStyle("XlsxFile", "A3", "C3", styleId);
|
||||||
|
|
||||||
|
|
||||||
style2 := TOfficeObj("TStyle");
|
style2 := TOfficeObj("TStyle");
|
||||||
@@ -108,9 +109,9 @@ Begin
|
|||||||
[err0, cell0] := file.CoordinatesToCellName(1, i+4);
|
[err0, cell0] := file.CoordinatesToCellName(1, i+4);
|
||||||
[err1, cell1] := file.CoordinatesToCellName(2, i+4);
|
[err1, cell1] := file.CoordinatesToCellName(2, i+4);
|
||||||
[err2, cell2] := file.CoordinatesToCellName(3, i+4);
|
[err2, cell2] := file.CoordinatesToCellName(3, i+4);
|
||||||
file.SetCellValue("ExcelFile", cell0, i+1);
|
file.SetCellValue("XlsxFile", cell0, i+1);
|
||||||
file.SetCellValue("ExcelFile", cell1, funcs[i]['funcname']);
|
file.SetCellValue("XlsxFile", cell1, funcs[i]['funcname']);
|
||||||
file.SetCellValue("ExcelFile", cell2, funcs[i]['name']);
|
file.SetCellValue("XlsxFile", cell2, funcs[i]['name']);
|
||||||
|
|
||||||
str := funcs[i]['name'] + "\nFunction " + funcs[i]['funcname'] + funcs[i]['comment'];
|
str := funcs[i]['name'] + "\nFunction " + funcs[i]['funcname'] + funcs[i]['comment'];
|
||||||
arr := str2array(str, "\n");
|
arr := str2array(str, "\n");
|
||||||
@@ -130,15 +131,15 @@ Begin
|
|||||||
hyperlink.LinkType := "location";
|
hyperlink.LinkType := "location";
|
||||||
hyperlink.LinkUrl := "Functions!" $ c1;
|
hyperlink.LinkUrl := "Functions!" $ c1;
|
||||||
|
|
||||||
file.SetCellHyperLink("ExcelFile", cell1, hyperlink);
|
file.SetCellHyperLink("XlsxFile", cell1, hyperlink);
|
||||||
file.SetCellStyle("ExcelFile", cell1, cell1, styleId4);
|
file.SetCellStyle("XlsxFile", cell1, cell1, styleId4);
|
||||||
|
|
||||||
End
|
End
|
||||||
|
|
||||||
file.SetColWidth('Functions', 'A', 'A', 120);
|
file.SetColWidth('Functions', 'A', 'A', 120);
|
||||||
PrintSuccess('SetColWidth', testing++);
|
PrintSuccess('SetColWidth', testing++);
|
||||||
|
|
||||||
saveName := utf8toansi("ExcelFile使用帮助.xlsx");
|
saveName := "XlsxFile使用帮助.xlsx";
|
||||||
[err, errinfo] := file.SaveAs('', saveName);
|
[err, errinfo] := file.SaveAs('', saveName);
|
||||||
if err then
|
if err then
|
||||||
return PrintError("SaveAs", err, errinfo);
|
return PrintError("SaveAs", err, errinfo);
|
||||||
@@ -320,6 +321,7 @@ Begin
|
|||||||
excel.SetCellValue(sheet_name, cell_1, name);
|
excel.SetCellValue(sheet_name, cell_1, name);
|
||||||
excel.MergeCell(sheet_name, cell_1, cell_2);
|
excel.MergeCell(sheet_name, cell_1, cell_2);
|
||||||
excel.SetCellStyle(sheet_name, cell_1, cell_2, styleid1);
|
excel.SetCellStyle(sheet_name, cell_1, cell_2, styleid1);
|
||||||
|
excel.SetRowHeight(sheet_name, row, 25);
|
||||||
row++;
|
row++;
|
||||||
|
|
||||||
desc_arr := obj_info[i]['Desc'];
|
desc_arr := obj_info[i]['Desc'];
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,4 +1,4 @@
|
|||||||
# OfficePlugin
|
# TSOffice
|
||||||
|
|
||||||
TSOffice 项目:纯 TSL 代码实现 excel、word 文件读写
|
TSOffice 项目:纯 TSL 代码实现 excel、word 文件读写
|
||||||
|
|
||||||
@@ -6,27 +6,36 @@ TSOffice 项目:纯 TSL 代码实现 excel、word 文件读写
|
|||||||
|
|
||||||
### windows
|
### windows
|
||||||
|
|
||||||
对应文件夹的dll文件按如下要求
|
对应文件夹的 dll 文件按如下要求
|
||||||
|
|
||||||
- `office_plugin` 放入 tsl 安装根目录下 Plugin 文件夹
|
- `office_plugin` 放入 tsl 安装根目录下 Plugin 文件夹
|
||||||
|
|
||||||
可选:
|
可选:
|
||||||
|
|
||||||
- `fmt_pubkrnl_plugin` 放入 tsl 安装根目录下 Plugin 文件夹,若需要执行Demo文件夹下的[ExcelHelp.tsl](./Demo/ExcelHelp.tsl)和[WordHelp.tsl](./Demo/WordHelp.tsl),需要部署改动态库
|
- `fmt_pubkrnl_plugin` 放入 tsl 安装根目录下 Plugin 文件夹,若需要执行 Demo 文件夹下的[XlsxHelp.tsl](./Demo/XlsxHelp.tsl)和[DocxHelp.tsl](./Demo/DocxHelp.tsl),需要部署改动态库
|
||||||
|
|
||||||
### Linux
|
### Linux
|
||||||
|
|
||||||
根据架构选择aarch64或x86版本将对应文件夹内容进行部署
|
#### Ubuntu-18.04
|
||||||
|
|
||||||
|
根据架构选择 aarch64 或 x86 版本将对应文件夹内容进行部署
|
||||||
|
|
||||||
- `liboffice_plugin` 放入 tsl 安装根目录下 Plugin 文件夹
|
- `liboffice_plugin` 放入 tsl 安装根目录下 Plugin 文件夹
|
||||||
|
|
||||||
## 帮助文档
|
## 帮助文档
|
||||||
|
|
||||||
- [Excel 帮助文档](./ExcelFile使用帮助.xlsx)
|
- [Excel 帮助文档](./XlsxFile使用帮助.xlsx)
|
||||||
|
|
||||||
- [Word 帮助文档](./DocxFile使用帮助.docx)
|
- [Word 帮助文档](./DocxFile使用帮助.docx)
|
||||||
|
|
||||||
|
## 扩展
|
||||||
|
|
||||||
|
扩展模块的内容需要通过`git submodule update --init --recursive`获取,相关帮助文档在`./funcext/TSOffice/Extensions/模块名`目录下可获取
|
||||||
|
|
||||||
|
支持的扩展:
|
||||||
|
|
||||||
|
- **OfficeVba**: 可通过类 Vba 方式对 office文件 进行读写操作。
|
||||||
|
|
||||||
## Demo
|
## Demo
|
||||||
|
|
||||||
Demo文件夹提供了一些参考的demo
|
Demo 文件夹提供了一些参考的 demo
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Submodule
+1
Submodule funcext/TSOffice/Extensions/OfficeVba added at 0aa9639ae0
+9348
-8837
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
+668
-597
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,4 @@
|
|||||||
// Version 1.4.4
|
// Version 1.5.0
|
||||||
|
|
||||||
Type TSExcelFile = Class
|
Type TSExcelFile = Class
|
||||||
///Version: V1.0 2022-08-08
|
///Version: V1.0 2022-08-08
|
||||||
@@ -915,7 +915,7 @@ Type TSExcelFile = Class
|
|||||||
|
|
||||||
///复制Sheet
|
///复制Sheet
|
||||||
///sourceSheet: 源工作表
|
///sourceSheet: 源工作表
|
||||||
///destSheet: 目的工作表
|
///destSheet: 目的工作表,如果destSheet存在,则覆盖destSheet,否则末尾新增destSheet
|
||||||
Function CopySheet(sourceSheet, destSheet);
|
Function CopySheet(sourceSheet, destSheet);
|
||||||
Begin
|
Begin
|
||||||
return workbook_.CopySheet(class(TSXml).CurCodePageToUtf8(sourceSheet), class(TSXml).CurCodePageToUtf8(destSheet));
|
return workbook_.CopySheet(class(TSXml).CurCodePageToUtf8(sourceSheet), class(TSXml).CurCodePageToUtf8(destSheet));
|
||||||
|
|||||||
@@ -1,277 +1,299 @@
|
|||||||
Type NodeInfo = class
|
Type NodeInfo = class
|
||||||
|
|
||||||
public
|
public
|
||||||
Function Create(parentObj, name);
|
Function Create(parentObj, name);
|
||||||
Begin
|
Begin
|
||||||
if ifObj(parentObj) then
|
if ifObj(parentObj) then
|
||||||
NodeUri := parentObj.NodeUri = '' ? name : (parentObj.NodeUri + '/' + name);
|
NodeUri := parentObj.NodeUri = '' ? name : (parentObj.NodeUri + '/' + name);
|
||||||
else
|
else
|
||||||
NodeUri := '';
|
NodeUri := '';
|
||||||
NodeName := name;
|
NodeName := name;
|
||||||
ExtAttr := array();
|
ExtAttr := array();
|
||||||
ExtNodes := array();
|
ExtNodes := array();
|
||||||
ReplaceArr := array();
|
ReplaceArr := array();
|
||||||
End
|
End
|
||||||
|
|
||||||
Function Root(); virtual;
|
Function Root(); virtual;
|
||||||
Begin
|
Begin
|
||||||
return RootObj;
|
return RootObj;
|
||||||
End
|
End
|
||||||
|
|
||||||
Function Update();
|
Function Update(position);overload;
|
||||||
Begin
|
Begin
|
||||||
if ifObj(RootObj) then Begin
|
if ifObj(RootObj) then Begin
|
||||||
arr := Marshal();
|
arr := Marshal();
|
||||||
if length(arr['attributes']) or length(arr['children']) then Begin
|
if length(arr['attributes']) or length(arr['children']) then Begin
|
||||||
curNode := class(TSXml).GetNode(RootObj, NodeUri);
|
curNode := class(TSXml).GetNode(RootObj, NodeUri, position);
|
||||||
if ifObj(curNode) then
|
if ifObj(curNode) then
|
||||||
class(TSXml).UpdateNode(curNode, arr['attributes'], arr['children']);
|
class(TSXml).UpdateNode(curNode, arr['attributes'], arr['children']);
|
||||||
End;
|
End;
|
||||||
End;
|
End;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
Function HandleAttrs(); virtual;
|
Function Update();overload;
|
||||||
Begin
|
Begin
|
||||||
End
|
self.Update("end");
|
||||||
|
End;
|
||||||
Function HandleChildren(); virtual;
|
|
||||||
Begin
|
Function Delete();overload;
|
||||||
End
|
Begin
|
||||||
|
if ifObj(RootObj) then
|
||||||
Function GetAttrs(); virtual;
|
begin
|
||||||
Begin
|
curNode := class(TSXml).GetNode(RootObj, NodeUri);
|
||||||
return ExtAttr;
|
if ifObj(curNode) then curNode.DeleteChildren();
|
||||||
End
|
end
|
||||||
|
End;
|
||||||
Function GetChildren(); virtual;
|
|
||||||
Begin
|
Function Delete(name);overload;
|
||||||
return ExtNodes;
|
Begin
|
||||||
End
|
if not ifObj(RootObj) then return false;
|
||||||
|
node := NodeUri <> '' ? class(TSXml).GetNode(RootObj, NodeUri) : RootObj;
|
||||||
Function GetNode(index); // 返回的index的对象
|
|
||||||
Begin
|
attrs := GetAttrsEx();
|
||||||
return ExtNodes[index]['obj'];
|
lName := lowerCase(name);
|
||||||
End
|
r := sselect * from attrs where lName = lowerCase([0]) end;
|
||||||
|
if istable(r) then
|
||||||
Function GetCount(); // 返回当前节点的个数
|
begin
|
||||||
Begin
|
node.DeleteAttribute(r[1]);
|
||||||
return length(ExtAttr);
|
return true;
|
||||||
End
|
end
|
||||||
|
|
||||||
// arr := array(('Size', 'sz', 15), ('Style', 'style', 'line'));
|
children := GetChildren();
|
||||||
Function AddAttr(arr); // 添加属性
|
r := select * from children where lName = lowerCase(['field']) end;
|
||||||
Begin
|
if istable(r) then Begin
|
||||||
if not istable(arr) then return;
|
r := r[0];
|
||||||
ExtAttr union= arr;
|
delete_node := node.FirstChildElement(r['name']);
|
||||||
return 1;
|
if ifObj(delete_node) then
|
||||||
End
|
begin
|
||||||
|
node.DeleteChild(delete_node);
|
||||||
Function Marshal();
|
return true;
|
||||||
Begin
|
end
|
||||||
children_ := nil;
|
End;
|
||||||
GetChildrenEx(); //优化为变量,减少数据COPY,2022-12-10
|
return false;
|
||||||
child_arr := array();
|
End;
|
||||||
len := 0;
|
|
||||||
for i:=0 to length(children_)-1 do
|
Function GetAttrs(); virtual;
|
||||||
begin
|
Begin
|
||||||
node_type := children_[i]['nodeType'];
|
return ExtAttr;
|
||||||
obj := children_[i]['obj'];
|
End
|
||||||
if ifnil(obj) then continue;
|
|
||||||
//find := select thisrowindex as "rowindex_", * from child_arr where ['name'] = children_[i]['name'] end; //优化为循环,性能提高15-20%,2022-12-20
|
Function GetChildren(); virtual;
|
||||||
find := array();
|
Begin
|
||||||
for j:=length(child_arr)-1 downto 0 do Begin //支持列表模式(如多节点:<w:t xml:space=""></w:t>),查找最近的节点
|
return ExtNodes;
|
||||||
if child_arr[j]['name'] = children_[i]['name'] then Begin
|
End
|
||||||
find[0] := child_arr[j];
|
|
||||||
find[0]['rowindex_'] := j;
|
Function GetNode(index); // 返回的index的对象
|
||||||
break;
|
Begin
|
||||||
End;
|
return ExtNodes[index]['obj'];
|
||||||
End;
|
End
|
||||||
if not ifnil(obj) and not ifObj(obj) and istable(find) and ifstring(children_[i]['attrEx']) and children_[i]['attrEx'] <> '' then
|
|
||||||
begin
|
Function GetCount(); // 返回当前节点的个数
|
||||||
if not ifarray(find[0]['attributes']) then find[0]['attributes'] := array();
|
Begin
|
||||||
key := children_[i]['attrEx'];
|
return length(ExtAttr);
|
||||||
find[0]['attributes'] union= array(key : obj);
|
End
|
||||||
child_arr[find[0]['rowindex_']]['attributes'] := find[0]['attributes'];
|
|
||||||
continue;
|
// arr := array(('Size', 'sz', 15), ('Style', 'style', 'line'));
|
||||||
end
|
Function AddAttr(arr); // 添加属性
|
||||||
|
Begin
|
||||||
arr := array('type': 'element', 'name': children_[i]['name'], 'attributes': array());
|
if not istable(arr) then return;
|
||||||
if node_type = 'empty' then // <b/>
|
ExtAttr union= arr;
|
||||||
begin
|
return 1;
|
||||||
empty_name := children_[i]['attrEx'] ? children_[i]['attrEx'] : 'val';
|
End
|
||||||
if obj = 0 then arr['attributes'] := array(empty_name: 0);
|
|
||||||
else if obj = 1 then arr['attributes'] := array(empty_name: 1)
|
Function Marshal();
|
||||||
end
|
Begin
|
||||||
else if node_type = 'pcdata' then
|
children_ := nil;
|
||||||
begin
|
GetChildrenEx(); //优化为变量,减少数据COPY,2022-12-10
|
||||||
arr['children'] := array(('type': 'pcdata', 'value': obj));
|
child_arr := array();
|
||||||
end
|
name_map := array();
|
||||||
else if ifObj(obj) then
|
len := 0;
|
||||||
begin
|
for i:=0 to length(children_)-1 do
|
||||||
marshal := obj.Marshal();
|
begin
|
||||||
if length(marshal['children'])=0 and length(marshal['attributes'])=0 then continue;
|
node_type := children_[i]['nodeType'];
|
||||||
arr['children'] := marshal['children'];
|
obj := children_[i]['obj'];
|
||||||
arr['attributes'] union= marshal['attributes'];
|
if ifnil(obj) then continue;
|
||||||
end
|
if not ifObj(obj) and not ifnil(name_map[children_[i]['name']]) and children_[i]['attrEx'] <> '' then
|
||||||
else
|
begin
|
||||||
begin
|
child_arr[name_map[children_[i]['name']]]['attributes'] union=array(children_[i]['attrEx'] : obj);
|
||||||
key := children_[i]['attrName'] ? children_[i]['attrName'] : children_[i]['attrEx'] ? children_[i]['attrEx'] : 'val';
|
continue;
|
||||||
arr['attributes'] := array(key : obj);
|
end
|
||||||
end
|
|
||||||
|
arr := array('type': 'element', 'name': children_[i]['name'], 'attributes': array());
|
||||||
child_arr[len++] := arr;
|
if node_type = 'empty' then // <b/>
|
||||||
end
|
begin
|
||||||
|
empty_name := children_[i]['attrEx'] ? children_[i]['attrEx'] : 'val';
|
||||||
name_arr := str2array(NodeName, '/');
|
if obj = 0 then arr['attributes'] := array(empty_name: 0);
|
||||||
tmp_arr := array('type': 'element', 'name': name_arr[length(name_arr)-1], 'children': child_arr);
|
else if obj = 1 then arr['attributes'] := array(empty_name: 1);
|
||||||
for i:=length(name_arr)-2 downto 0 do
|
end
|
||||||
begin
|
else if node_type = 'pcdata' then
|
||||||
tmp_arr := array('type': 'element', 'name': name_arr[i], 'children': array(tmp_arr));
|
begin
|
||||||
end
|
arr['children'] := array(('type': 'pcdata', 'value': obj));
|
||||||
|
end
|
||||||
attrs_arr := GetAttrs();
|
else if ifObj(obj) then
|
||||||
tmp_arr['attributes'] := array();
|
begin
|
||||||
for i:=0 to length(attrs_arr)-1 do
|
marshal := obj.Marshal();
|
||||||
begin
|
if length(marshal['children'])=0 and length(marshal['attributes'])=0 then continue;
|
||||||
if not ifnil(attrs_arr[i, 2]) then Begin
|
arr['children'] := marshal['children'];
|
||||||
tmp_arr['attributes'][ attrs_arr[i, 1] ] := attrs_arr[i, 2];
|
arr['attributes'] union= marshal['attributes'];
|
||||||
End;
|
end
|
||||||
end
|
else
|
||||||
return tmp_arr;
|
begin
|
||||||
End
|
key := children_[i]['attrName'] ? children_[i]['attrName'] : children_[i]['attrEx'] ? children_[i]['attrEx'] : 'val';
|
||||||
|
arr['attributes'] := array(key : obj);
|
||||||
Function NewChildNode(nodeArr);
|
end
|
||||||
Begin
|
name_map[children_[i]['name']] := len;
|
||||||
if not ifarray(nodeArr) then return 0;
|
child_arr[len++] := arr;
|
||||||
if not ifstring(nodeArr['name']) then return 0;
|
end
|
||||||
arr := array((
|
|
||||||
'name': nodeArr['name'],
|
name_arr := str2array(NodeName, '/');
|
||||||
'obj': nodeArr['obj'],
|
tmp_arr := array('type': 'element', 'name': name_arr[length(name_arr)-1], 'children': child_arr);
|
||||||
'attrEx': nodeArr['attrEx'],
|
for i:=length(name_arr)-2 downto 0 do
|
||||||
'nodeType': nodeArr['nodeType'],
|
begin
|
||||||
));
|
tmp_arr := array('type': 'element', 'name': name_arr[i], 'children': array(tmp_arr));
|
||||||
ExtNodes union= arr;
|
end
|
||||||
return 1;
|
|
||||||
End
|
attrs_arr := GetAttrs();
|
||||||
|
tmp_arr['attributes'] := array();
|
||||||
Function Value(name);
|
for i:=0 to length(attrs_arr)-1 do
|
||||||
Begin
|
begin
|
||||||
if not ifObj(RootObj) then return nil;
|
if not ifnil(attrs_arr[i, 2]) then Begin
|
||||||
if NodeUri <> '' then
|
tmp_arr['attributes'][ attrs_arr[i, 1] ] := attrs_arr[i, 2];
|
||||||
node := class(TSXml).GetNode(RootObj, NodeUri);
|
End;
|
||||||
else
|
end
|
||||||
node := RootObj;
|
return tmp_arr;
|
||||||
if not ifObj(node) then return nil;
|
End
|
||||||
|
|
||||||
attrs := GetAttrsEx();
|
Function NewChildNode(nodeArr);
|
||||||
lName := lowerCase(name);
|
Begin
|
||||||
r := sselect * from attrs where lName = lowerCase([0]) end;
|
if not ifarray(nodeArr) then return 0;
|
||||||
if istable(r) then
|
if not ifstring(nodeArr['name']) then return 0;
|
||||||
begin
|
arr := array((
|
||||||
value := node.GetAttribute(r[1]);
|
'name': nodeArr['name'],
|
||||||
return trystrtofloat(value, r) ? r : value;
|
'obj': nodeArr['obj'],
|
||||||
end
|
'attrEx': nodeArr['attrEx'],
|
||||||
|
'nodeType': nodeArr['nodeType'],
|
||||||
children := GetChildren();
|
));
|
||||||
r := select * from children where lName = lowerCase(['field']) end;
|
ExtNodes union= arr;
|
||||||
if istable(r) then Begin
|
return 1;
|
||||||
r := r[0];
|
End
|
||||||
node := node.FirstChildElement(r['name']);
|
|
||||||
if not ifObj(node) and r['nodeType'] = 'empty' then return false;
|
Function Value(name, nottransferable);
|
||||||
if not ifObj(node) then return nil;
|
Begin
|
||||||
if r['nodeType'] = 'pcdata' then //返回文本串
|
if not ifObj(RootObj) then return nil;
|
||||||
return node.GetText();
|
if NodeUri <> '' then
|
||||||
if ifObj(r['obj']) then //对象,返回XML串
|
node := class(TSXml).GetNode(RootObj, NodeUri);
|
||||||
return node.Data();
|
else
|
||||||
key := r['attrName'] ? r['attrName'] : r['attrEx'] ? r['attrEx'] : 'val';
|
node := RootObj;
|
||||||
value := node.GetAttribute(key);
|
if not ifObj(node) then return nil;
|
||||||
if r['nodeType'] = 'empty' and value = '' then return true;
|
|
||||||
return trystrtofloat(value, r) ? r : value;
|
attrs := GetAttrsEx();
|
||||||
End;
|
lName := lowerCase(name);
|
||||||
return nil;
|
r := sselect * from attrs where lName = lowerCase([0]) end;
|
||||||
End;
|
if istable(r) then
|
||||||
|
begin
|
||||||
Function Replace(hash, bChild);
|
value := node.GetAttribute(r[1]);
|
||||||
Begin
|
return nottransferable ? value : trystrtofloat(value, r) ? r : value;
|
||||||
if istable(hash) then Begin
|
end
|
||||||
ReplaceArr := hash;
|
|
||||||
replaceNodeName();
|
children := GetChildren();
|
||||||
if bChild then Begin
|
r := select * from children where lName = lowerCase(['field']) end;
|
||||||
r := GetChildren();
|
if istable(r) then Begin
|
||||||
for i:=0 to length(r)-1 do Begin
|
r := r[0];
|
||||||
if ifObj(r[i]['obj']) then
|
node := node.FirstChildElement(r['name']);
|
||||||
r[i]['obj'].Replace(hash, bChild);
|
if not ifObj(node) and r['nodeType'] = 'empty' and not nottransferable then return false;
|
||||||
End;
|
if not ifObj(node) then return nil;
|
||||||
End;
|
if r['nodeType'] = 'pcdata' then //返回文本串
|
||||||
End;
|
return node.GetText();
|
||||||
End
|
if ifObj(r['obj']) then //对象,返回XML串
|
||||||
|
return node.Data();
|
||||||
Function GetChildrenEx();
|
key := r['attrName'] ? r['attrName'] : r['attrEx'] ? r['attrEx'] : 'val';
|
||||||
Begin
|
value := node.GetAttribute(key);
|
||||||
if not ifarray(children_) then Begin
|
if r['nodeType'] = 'empty' and value = '' then return true;
|
||||||
children_ := getChildren();
|
return nottransferable ? value : trystrtofloat(value, r) ? r : value;
|
||||||
if not istable(ReplaceArr) then Begin
|
End;
|
||||||
for i:=0 to length(children_)-1 do Begin
|
return nil;
|
||||||
if ifarray(children_[i]['obj']) then Begin
|
End;
|
||||||
if istable(children_[i]['obj']) then
|
|
||||||
hasArr := 1;
|
Function Replace(hash, bChild);
|
||||||
else
|
Begin
|
||||||
children_[i]['obj'] := nil;
|
if istable(hash) then Begin
|
||||||
End;
|
ReplaceArr := hash;
|
||||||
End;
|
replaceNodeName();
|
||||||
End;
|
if bChild then Begin
|
||||||
if hasArr or istable(ReplaceArr) then Begin
|
r := GetChildren();
|
||||||
a := array();
|
for i:=0 to length(r)-1 do Begin
|
||||||
for i:=0 to length(children_)-1 do Begin
|
if ifObj(r[i]['obj']) then
|
||||||
if istable(ReplaceArr) then
|
r[i]['obj'].Replace(hash, bChild);
|
||||||
children_[i]['name'] := ReplaceName(children_[i]['name']);
|
End;
|
||||||
if istable(children_[i]['obj']) then Begin
|
End;
|
||||||
a union= children_[i]['obj'];
|
End;
|
||||||
End
|
End
|
||||||
else
|
|
||||||
a[ length(a) ] := children_[i];
|
Function GetChildrenEx();
|
||||||
end;
|
Begin
|
||||||
children_ := a;
|
if not ifarray(children_) then Begin
|
||||||
End;
|
children_ := getChildren();
|
||||||
End;
|
if not istable(ReplaceArr) then Begin
|
||||||
End;
|
for i:=0 to length(children_)-1 do Begin
|
||||||
|
if ifarray(children_[i]['obj']) then Begin
|
||||||
Function GetAttrsEx();
|
if istable(children_[i]['obj']) then
|
||||||
Begin
|
hasArr := 1;
|
||||||
return GetAttrs();//暂时没有发现需要更新属性前缀的情况
|
else
|
||||||
if not istable(ReplaceArr) then return GetAttrs();
|
children_[i]['obj'] := nil;
|
||||||
attr := GetAttrs();
|
End;
|
||||||
for i:=0 to length(attr)-1 do
|
End;
|
||||||
attr[i][1] := ReplaceName(attr[i][1]);
|
End;
|
||||||
return attr;
|
if hasArr or istable(ReplaceArr) then Begin
|
||||||
End
|
a := array();
|
||||||
|
for i:=0 to length(children_)-1 do Begin
|
||||||
private
|
if istable(ReplaceArr) then
|
||||||
Function replaceNodeName();
|
children_[i]['name'] := ReplaceName(children_[i]['name']);
|
||||||
Begin
|
if istable(children_[i]['obj']) then Begin
|
||||||
for k, v in ReplaceArr do
|
a union= children_[i]['obj'];
|
||||||
begin
|
End
|
||||||
NodeName := ReplaceStr(NodeName, k, v);
|
else
|
||||||
end
|
a[ length(a) ] := children_[i];
|
||||||
End
|
end;
|
||||||
|
children_ := a;
|
||||||
Function ReplaceName(name);
|
End;
|
||||||
Begin
|
End;
|
||||||
for k,v in ReplaceArr do Begin
|
End;
|
||||||
if k='' then
|
|
||||||
name := v + name;
|
Function GetAttrsEx();
|
||||||
else
|
Begin
|
||||||
name := ReplaceStr(name, k, v);
|
return GetAttrs();//暂时没有发现需要更新属性前缀的情况
|
||||||
End;
|
if not istable(ReplaceArr) then return GetAttrs();
|
||||||
return name;
|
attr := GetAttrs();
|
||||||
End;
|
for i:=0 to length(attr)-1 do
|
||||||
public
|
attr[i][1] := ReplaceName(attr[i][1]);
|
||||||
NodeName;
|
return attr;
|
||||||
ExtAttr;
|
End
|
||||||
ExtNodes;
|
|
||||||
//Parent;
|
private
|
||||||
ReplaceArr;
|
Function replaceNodeName();
|
||||||
RootObj; // xml node
|
Begin
|
||||||
NodeUri:string;
|
for k, v in ReplaceArr do
|
||||||
children_;
|
begin
|
||||||
End
|
NodeName := ReplaceStr(NodeName, k, v);
|
||||||
|
end
|
||||||
|
End
|
||||||
|
|
||||||
|
Function ReplaceName(name);
|
||||||
|
Begin
|
||||||
|
for k,v in ReplaceArr do Begin
|
||||||
|
if k='' then
|
||||||
|
name := v + name;
|
||||||
|
else
|
||||||
|
name := ReplaceStr(name, k, v);
|
||||||
|
End;
|
||||||
|
return name;
|
||||||
|
End;
|
||||||
|
public
|
||||||
|
NodeName;
|
||||||
|
ExtAttr;
|
||||||
|
ExtNodes;
|
||||||
|
ReplaceArr;
|
||||||
|
RootObj; // xml node
|
||||||
|
NodeUri:string;
|
||||||
|
children_;
|
||||||
|
End
|
||||||
|
|||||||
@@ -178,6 +178,33 @@ Type TOffice = Class
|
|||||||
Begin
|
Begin
|
||||||
return getTextBoxImpl(p, true);
|
return getTextBoxImpl(p, true);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
|
///获取docx的类型
|
||||||
|
///普通段落:0
|
||||||
|
///图片段落:1
|
||||||
|
///表格:2
|
||||||
|
///其他:-1
|
||||||
|
Function GetDocxPartType(part);
|
||||||
|
Begin
|
||||||
|
if not ifObj(part) then return -1;
|
||||||
|
case part.name_ of
|
||||||
|
'w:p':
|
||||||
|
begin
|
||||||
|
if class(TSXml).GetNode(part.node_, 'w:r/w:drawing') then return 1;
|
||||||
|
return 0;
|
||||||
|
end
|
||||||
|
'w:tbl':
|
||||||
|
return 2;
|
||||||
|
else
|
||||||
|
return -1;
|
||||||
|
end;
|
||||||
|
End;
|
||||||
|
|
||||||
|
///单元格内的标题是否添加到目录
|
||||||
|
Function SetCellTableContent(flag);
|
||||||
|
Begin
|
||||||
|
hash_["CELLFLAG"] := flag;
|
||||||
|
End;
|
||||||
|
|
||||||
Function Set(k, v);
|
Function Set(k, v);
|
||||||
Begin
|
Begin
|
||||||
|
|||||||
@@ -71,12 +71,14 @@ Type TSImage = Class
|
|||||||
Begin
|
Begin
|
||||||
des1 := 0xff;
|
des1 := 0xff;
|
||||||
des2 := 0xc0;
|
des2 := 0xc0;
|
||||||
|
des3 := 0xc2;
|
||||||
flag := 1;
|
flag := 1;
|
||||||
while flag do
|
while flag do
|
||||||
begin
|
begin
|
||||||
stringObj_.Read(byte1, 1);
|
r1 := stringObj_.Read(byte1, 1);
|
||||||
stringObj_.Read(byte2, 1);
|
r2 := stringObj_.Read(byte2, 1);
|
||||||
if byte1 = des1 and byte2 = des2 then flag := 0;
|
if r1 = 0 or r2 = 0 then break;
|
||||||
|
if byte1 = des1 and (byte2 = des2 or byte2 = des3) then flag := 0;
|
||||||
end
|
end
|
||||||
if flag then return array(0, 0);
|
if flag then return array(0, 0);
|
||||||
stringObj_.Read(tmp, 3);
|
stringObj_.Read(tmp, 3);
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@@ -52,8 +52,8 @@ Type TDocxChart = Class(TSChart)
|
|||||||
return true;
|
return true;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
docx_;
|
[weakref]docx_;
|
||||||
chartId_;
|
chartId_;
|
||||||
rId_;
|
rId_;
|
||||||
xmlObj_;
|
xmlObj_;
|
||||||
End;
|
End;
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,206 +1,207 @@
|
|||||||
Type TDocxStyles = Class
|
Type TDocxStyles = Class
|
||||||
//段落格式
|
//段落格式
|
||||||
Function Create(docx);
|
Function Create(docx);
|
||||||
Begin
|
Begin
|
||||||
docx_ := docx;
|
docx_ := docx;
|
||||||
stylesXml_ := docx.Zip().Get('word/styles.xml');
|
stylesXml_ := docx.Zip().Get('word/styles.xml');
|
||||||
idMap_ := array();
|
idMap_ := array();
|
||||||
nameMap_ := array();
|
nameMap_ := array();
|
||||||
maxStyleId_ := 1;
|
maxStyleId_ := 1;
|
||||||
|
|
||||||
if ifObj(stylesXml_) then Begin
|
if ifObj(stylesXml_) then Begin
|
||||||
stylesNode := stylesXml_.FirstChildElement('w:styles');
|
stylesNode := stylesXml_.FirstChildElement('w:styles');
|
||||||
if ifObj(stylesNode) then Begin
|
if ifObj(stylesNode) then Begin
|
||||||
node := stylesNode.FirstChildElement('w:style');
|
node := stylesNode.FirstChildElement('w:style');
|
||||||
while ifObj(node) do Begin
|
while ifObj(node) do Begin
|
||||||
o := TOfficeObj('TDocxStyle');
|
o := TOfficeObj('TDocxStyle');
|
||||||
o.Init(node);
|
o.Init(node);
|
||||||
id := StrToIntDef(o.StyleId, 0);
|
id := StrToIntDef(o.StyleId, 0);
|
||||||
if id > 0 and maxStyleId_ <= id then
|
if id > 0 and maxStyleId_ <= id then
|
||||||
maxStyleId_ := id + 1;
|
maxStyleId_ := id + 1;
|
||||||
_addStyle(o);
|
_addStyle(o);
|
||||||
node := node.NextElement('w:style');
|
node := node.NextElement('w:style');
|
||||||
End;
|
End;
|
||||||
pNode := class(TSXml).GetNode(stylesNode, 'w:docDefaults/w:pPrDefault');
|
pNode := class(TSXml).GetNode(stylesNode, 'w:docDefaults/w:pPrDefault');
|
||||||
if ifObj(pNode) then
|
if ifObj(pNode) then
|
||||||
defaultPpr_ := Class(TSXml).ReadPprFormat(pNode);
|
defaultPpr_ := Class(TSXml).ReadPprFormat(pNode);
|
||||||
|
|
||||||
rNode := class(TSXml).GetNode(stylesNode, 'w:docDefaults/w:rPrDefault');
|
rNode := class(TSXml).GetNode(stylesNode, 'w:docDefaults/w:rPrDefault');
|
||||||
if ifObj(rNode) then
|
if ifObj(rNode) then
|
||||||
defaultRpr_ := Class(TSXml).ReadRprFormat(rNode);
|
defaultRpr_ := Class(TSXml).ReadRprFormat(rNode);
|
||||||
End;
|
End;
|
||||||
End;
|
End;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///缺省样式
|
///缺省样式
|
||||||
///styleType:样式类型(paragraph、character、table)
|
///styleType:样式类型(paragraph、character、table)
|
||||||
///返回:TDocxStyle对象
|
///返回:TDocxStyle对象
|
||||||
Function Default(styleType);
|
Function Default(styleType);
|
||||||
Begin
|
Begin
|
||||||
for k, obj in idMap_ do Begin
|
for k, obj in idMap_ do Begin
|
||||||
if obj.wType = styleType then Begin
|
if obj.wType = styleType then Begin
|
||||||
v := obj.node_.GetAttribute('w:default');
|
v := obj.node_.GetAttribute('w:default');
|
||||||
if v <> '1' then
|
if v <> '1' then
|
||||||
return obj;
|
return obj;
|
||||||
End;
|
End;
|
||||||
End
|
End
|
||||||
return nil;
|
return nil;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///返回指定名称的TDocxStyle
|
///返回指定名称的TDocxStyle
|
||||||
///name:样式名称
|
///name:样式名称
|
||||||
///返回:TDocxStyle对象
|
///返回:TDocxStyle对象
|
||||||
Function GetStyle(name);
|
Function GetStyle(name);
|
||||||
Begin
|
Begin
|
||||||
return nameMap_[ class(TSXml).CurCodePageToUtf8(lowercase(name)) ];
|
return nameMap_[ class(TSXml).CurCodePageToUtf8(lowercase(name)) ];
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///返回指定StyleId名称的TDocxStyle
|
///返回指定StyleId名称的TDocxStyle
|
||||||
///id:StyleID号(数字ID号或名称字符串)
|
///id:StyleID号(数字ID号或名称字符串)
|
||||||
///返回:TDocxStyle对象
|
///返回:TDocxStyle对象
|
||||||
Function GetStyleById(id);
|
Function GetStyleById(id);
|
||||||
Begin
|
Begin
|
||||||
newid := ifnumber(id) ? tostring(id) : id;
|
newid := ifnumber(id) ? tostring(id) : id;
|
||||||
return idMap_[ newid ];
|
return idMap_[ newid ];
|
||||||
End;
|
End;
|
||||||
|
|
||||||
//返回全部LatentStyles对象列表
|
//返回全部LatentStyles对象列表
|
||||||
//返回:TDocxStyle对象列表
|
//返回:TDocxStyle对象列表
|
||||||
Function LatentStyles();
|
Function LatentStyles();
|
||||||
Begin
|
Begin
|
||||||
r := array();
|
r := array();
|
||||||
node := stylesXml_.FirstChildElement('w:styles');
|
node := stylesXml_.FirstChildElement('w:styles');
|
||||||
if ifObj(node) then
|
if ifObj(node) then
|
||||||
node := node.FirstChildElement('w:latentStyles');
|
node := node.FirstChildElement('w:latentStyles');
|
||||||
if ifObj(node) then Begin
|
if ifObj(node) then Begin
|
||||||
node := node.FirstChildElement('w:lsdException');
|
node := node.FirstChildElement('w:lsdException');
|
||||||
while ifObj(node) do Begin
|
while ifObj(node) do Begin
|
||||||
o := TOfficeObj('TDocxStyle');
|
o := TOfficeObj('TDocxStyle');
|
||||||
o.Init(node);
|
o.Init(node);
|
||||||
r[ length(r) ] := o;
|
r[ length(r) ] := o;
|
||||||
node := node.NextElement('w:lsdException');
|
node := node.NextElement('w:lsdException');
|
||||||
End;
|
End;
|
||||||
End;
|
End;
|
||||||
return r;
|
return r;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///返回全部Styles对象列表
|
///返回全部Styles对象列表
|
||||||
///返回:TDocxStyle对象列表
|
///返回:TDocxStyle对象列表
|
||||||
Function Styles();
|
Function Styles();
|
||||||
Begin
|
Begin
|
||||||
return idMap_;
|
return idMap_;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///插入新的段落样式
|
///插入新的段落样式
|
||||||
///styleId:样式ID,可以是自定义名称
|
///styleId:样式ID,可以是自定义名称
|
||||||
///xmlStr:InnerXml串
|
///xmlStr:InnerXml串
|
||||||
///返回:TDocxStyle对象
|
///返回:TDocxStyle对象
|
||||||
Function AddStyleByInnerXml(styleId, xmlStr);
|
Function AddStyleByInnerXml(styleId, xmlStr);
|
||||||
Begin
|
Begin
|
||||||
if ifstring(styleId) and styleId <> '' then Begin
|
if ifstring(styleId) and styleId <> '' then Begin
|
||||||
style := GetStyle(styleId);
|
style := GetStyle(styleId);
|
||||||
if ifObj(style) then
|
if ifObj(style) then
|
||||||
return style;
|
return style;
|
||||||
node := stylesXml_.FirstChildElement('w:styles').InsertEndChild(xmlStr);
|
node := stylesXml_.FirstChildElement('w:styles').InsertEndChild(xmlStr);
|
||||||
node.SetAttribute('w:styleId', styleId);
|
node.SetAttribute('w:styleId', styleId);
|
||||||
End
|
End
|
||||||
else Begin
|
else Begin
|
||||||
node := stylesXml_.FirstChildElement('w:styles').InsertEndChild(xmlStr);
|
node := stylesXml_.FirstChildElement('w:styles').InsertEndChild(xmlStr);
|
||||||
node.SetAttribute('w:styleId', maxStyleId_++);
|
node.SetAttribute('w:styleId', maxStyleId_++);
|
||||||
End;
|
End;
|
||||||
o := TOfficeObj('TDocxStyle');
|
o := TOfficeObj('TDocxStyle');
|
||||||
o.Init(node);
|
o.Init(node);
|
||||||
_addStyle(o);
|
_addStyle(o);
|
||||||
return o;
|
return o;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///插入新的段落样式
|
///插入新的段落样式
|
||||||
///o:TDocxStyle对象
|
///o:TDocxStyle对象
|
||||||
///StyleId:样式ID,可以是自定义名称
|
///StyleId:样式ID,可以是自定义名称
|
||||||
///返回:TDocxStyle对象
|
///返回:TDocxStyle对象
|
||||||
Function AddStyle(o, StyleId);
|
Function AddStyle(o, StyleId);
|
||||||
Begin
|
Begin
|
||||||
if ifObj(o) then Begin
|
if ifObj(o) then Begin
|
||||||
if ifString(StyleId) and StyleId <> '' and not ifObj(idMap_[ StyleId ]) then
|
if ifString(StyleId) and StyleId <> '' and not ifObj(idMap_[ StyleId ]) then
|
||||||
o.StyleId := StyleId;
|
o.StyleId := StyleId;
|
||||||
else
|
else
|
||||||
o.StyleId := maxStyleId_++;
|
o.StyleId := maxStyleId_++;
|
||||||
node := stylesXml_.FirstChildElement('w:styles').InsertEndChild(o.Marshal());
|
node := stylesXml_.FirstChildElement('w:styles').InsertEndChild(o.Marshal());
|
||||||
obj := TOfficeObj('TDocxStyle');
|
obj := TOfficeObj('TDocxStyle');
|
||||||
obj.Init(node);
|
obj.Init(node);
|
||||||
_addStyle(obj);
|
_addStyle(obj);
|
||||||
return obj;
|
return obj;
|
||||||
End;
|
End;
|
||||||
return nil;
|
return nil;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///复制样式
|
///复制样式
|
||||||
///newstyle:样式节点TDocxStyle对象
|
///newstyle:样式节点TDocxStyle对象
|
||||||
///返回:TDocxStyle对象
|
///返回:TDocxStyle对象
|
||||||
Function CopyStyle(newstyle);
|
Function CopyStyle(newstyle);
|
||||||
Begin
|
Begin
|
||||||
if ifObj(newstyle) and ifObj(newstyle.node_) then Begin
|
if ifObj(newstyle) and ifObj(newstyle.node_) then Begin
|
||||||
node := stylesXml_.FirstChildElement('w:styles').InsertEndChild(newstyle.node_.Marshal()[0]);
|
node := stylesXml_.FirstChildElement('w:styles').InsertEndChild(newstyle.node_.Marshal()[0]);
|
||||||
obj := TOfficeObj('TDocxStyle');
|
node.DeleteAttribute('w:default');
|
||||||
obj.StyleId := node.GetAttribute('w:styleId');
|
obj := TOfficeObj('TDocxStyle');
|
||||||
obj.Name := node.FirstChildElement('w:name').GetAttribute('w:val');
|
obj.StyleId := node.GetAttribute('w:styleId');
|
||||||
obj.Init(node);
|
obj.Name := node.FirstChildElement('w:name').GetAttribute('w:val');
|
||||||
_addStyle(obj);
|
obj.Init(node);
|
||||||
return obj;
|
_addStyle(obj);
|
||||||
End;
|
return obj;
|
||||||
return nil;
|
End;
|
||||||
End;
|
return nil;
|
||||||
|
End;
|
||||||
///插入新的LatentStyle段落样式
|
|
||||||
///o:TDocxStyle对象
|
///插入新的LatentStyle段落样式
|
||||||
///返回:TDocxStyle对象
|
///o:TDocxStyle对象
|
||||||
Function AddLatentStyle(o);
|
///返回:TDocxStyle对象
|
||||||
Begin
|
Function AddLatentStyle(o);
|
||||||
if ifObj(o) then Begin
|
Begin
|
||||||
latentStyles := stylesXml_.FirstChildElement('w:styles').InsertEndChild('w:latentStyles');
|
if ifObj(o) then Begin
|
||||||
node := latentStyles.InsertEndChild('lsdException');
|
latentStyles := stylesXml_.FirstChildElement('w:styles').InsertEndChild('w:latentStyles');
|
||||||
node.UnMarshal(o);
|
node := latentStyles.InsertEndChild('lsdException');
|
||||||
latentStyles.SetAttribute('w:count', length(LatentStyles()));
|
node.UnMarshal(o);
|
||||||
return node;
|
latentStyles.SetAttribute('w:count', length(LatentStyles()));
|
||||||
End;
|
return node;
|
||||||
return nil;
|
End;
|
||||||
End;
|
return nil;
|
||||||
|
End;
|
||||||
///插入缺省的段落样式(Title、Heading1-9)
|
|
||||||
///返回:TDocxStyle对象
|
///插入缺省的段落样式(Title、Heading1-9)
|
||||||
Function AddDefaultStyle(Name);
|
///返回:TDocxStyle对象
|
||||||
Begin
|
Function AddDefaultStyle(Name);
|
||||||
styleId := AnsiReplaceText(Name, ' ', '');
|
Begin
|
||||||
charId := StyleId + 'Char';
|
styleId := AnsiReplaceText(Name, ' ', '');
|
||||||
styleFname := 'wStyle/' + styleId + '.xml';
|
charId := StyleId + 'Char';
|
||||||
cStyleFname := 'wStyle/' + charId + '.xml';
|
styleFname := 'wStyle/' + styleId + '.xml';
|
||||||
xmlData := TOfficeTemplate(styleFname);
|
cStyleFname := 'wStyle/' + charId + '.xml';
|
||||||
if ifnil(xmlData) then
|
xmlData := TOfficeTemplate(styleFname);
|
||||||
return xmlData;
|
if ifnil(xmlData) then
|
||||||
o := AddStyleByInnerXml(styleId, xmlData);
|
return xmlData;
|
||||||
|
o := AddStyleByInnerXml(styleId, xmlData);
|
||||||
charStyle := idMap_[charId];
|
|
||||||
if not ifObj(charStyle) then Begin
|
charStyle := idMap_[charId];
|
||||||
xmlData := TOfficeTemplate(cStyleFname);
|
if not ifObj(charStyle) then Begin
|
||||||
if ifstring(xmlData) then Begin
|
xmlData := TOfficeTemplate(cStyleFname);
|
||||||
AddStyleByInnerXml(charId, xmlData);
|
if ifstring(xmlData) then Begin
|
||||||
End;
|
AddStyleByInnerXml(charId, xmlData);
|
||||||
End;
|
End;
|
||||||
return o;
|
End;
|
||||||
End;
|
return o;
|
||||||
|
End;
|
||||||
Function _addStyle(o);
|
|
||||||
Begin
|
Function _addStyle(o);
|
||||||
idMap_[ o.StyleId ] := o;
|
Begin
|
||||||
nameMap_[ lowercase(o.Name) ] := o;
|
idMap_[ o.StyleId ] := o;
|
||||||
End;
|
nameMap_[ lowercase(o.Name) ] := o;
|
||||||
|
End;
|
||||||
defaultPpr_;
|
|
||||||
defaultRpr_;
|
defaultPpr_;
|
||||||
private
|
defaultRpr_;
|
||||||
docx_;
|
private
|
||||||
stylesXml_;
|
[weakref]docx_;
|
||||||
idMap_;
|
stylesXml_;
|
||||||
nameMap_;
|
idMap_;
|
||||||
maxStyleId_:integer;
|
nameMap_;
|
||||||
End;
|
maxStyleId_:integer;
|
||||||
|
End;
|
||||||
|
|||||||
@@ -228,7 +228,7 @@ Type TNumbering = Class
|
|||||||
class(TSXml).UpdateNode(o.node_, arr['attributes'], arr['children']);
|
class(TSXml).UpdateNode(o.node_, arr['attributes'], arr['children']);
|
||||||
End;
|
End;
|
||||||
private
|
private
|
||||||
docx_;
|
[weakref]docx_;
|
||||||
numberingXml_;
|
numberingXml_;
|
||||||
maxAbstractNumId_:integer;
|
maxAbstractNumId_:integer;
|
||||||
maxNumId_:integer;
|
maxNumId_:integer;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ Type TTableContent = class
|
|||||||
Begin
|
Begin
|
||||||
Create(docx, nil);
|
Create(docx, nil);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
Function Create(docx, node);overload;
|
Function Create(docx, node);overload;
|
||||||
Begin
|
Begin
|
||||||
node_ := node;
|
node_ := node;
|
||||||
@@ -15,7 +15,7 @@ Type TTableContent = class
|
|||||||
//contentType := docx.Zip().Get('[Content_Types].xml');
|
//contentType := docx.Zip().Get('[Content_Types].xml');
|
||||||
//class(TSXml).AddOverrideContentType(contentType, 'wmf', 'image/x-wmf');
|
//class(TSXml).AddOverrideContentType(contentType, 'wmf', 'image/x-wmf');
|
||||||
End;
|
End;
|
||||||
|
|
||||||
Function SetDefaultFormat();
|
Function SetDefaultFormat();
|
||||||
Begin
|
Begin
|
||||||
defultFont := impl_.sdtPr.rPr;
|
defultFont := impl_.sdtPr.rPr;
|
||||||
@@ -39,7 +39,7 @@ Type TTableContent = class
|
|||||||
//impl_.sdtEndPr.rPr.SzCs := 22;
|
//impl_.sdtEndPr.rPr.SzCs := 22;
|
||||||
impl_.sdtEndPr.rPr.Bold := true;
|
impl_.sdtEndPr.rPr.Bold := true;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///应用目录样式
|
///应用目录样式
|
||||||
Function Apply(); override;
|
Function Apply(); override;
|
||||||
Begin
|
Begin
|
||||||
@@ -50,7 +50,7 @@ Type TTableContent = class
|
|||||||
arr := tmp_impl.Marshal();
|
arr := tmp_impl.Marshal();
|
||||||
class(TSXml).UpdateNode(node_, arr['attributes'], arr['children']);
|
class(TSXml).UpdateNode(node_, arr['attributes'], arr['children']);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///添加目录条目
|
///添加目录条目
|
||||||
///UpperHeadingLevel:标题最高级别
|
///UpperHeadingLevel:标题最高级别
|
||||||
///LowerHeadingLevel:标题最低级别
|
///LowerHeadingLevel:标题最低级别
|
||||||
@@ -79,26 +79,36 @@ Type TTableContent = class
|
|||||||
//mParagraph.Run.rPr.Size := 21/2;
|
//mParagraph.Run.rPr.Size := 21/2;
|
||||||
//mParagraph.Run.rPr.Bold := true;
|
//mParagraph.Run.rPr.Bold := true;
|
||||||
_AddStdContent(mParagraph);
|
_AddStdContent(mParagraph);
|
||||||
|
|
||||||
goback := TOfficeObj('TParagraph');
|
goback := TOfficeObj('TParagraph');
|
||||||
id := docx_.Document().GetBookMarkID();
|
id := docx_.Document().GetBookMarkID();
|
||||||
goback.MarkStart.Name := '_GoBack';
|
goback.MarkStart.Name := '_GoBack';
|
||||||
goback.MarkStart.ID := id;
|
goback.MarkStart.ID := id;
|
||||||
goback.MarkEnd.ID := id;
|
goback.MarkEnd.ID := id;
|
||||||
//_AddStdContent(goback);
|
//_AddStdContent(goback);
|
||||||
|
|
||||||
//缺省目录,需要word或wps打开后,更新目录
|
//缺省目录,需要word或wps打开后,更新目录
|
||||||
//_AddDefaultTableContent(UpperHeadingLevel, LowerHeadingLevel);
|
//_AddDefaultTableContent(UpperHeadingLevel, LowerHeadingLevel);
|
||||||
|
|
||||||
//自定义页码计算与word、wps有差异,不推荐使用
|
//自定义页码计算与word、wps有差异,不推荐使用
|
||||||
_AddTableContent(posOpt, UpperHeadingLevel, LowerHeadingLevel);
|
_AddTableContent(posOpt, UpperHeadingLevel, LowerHeadingLevel);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
|
///添加目录条目
|
||||||
|
///UpperHeadingLevel:标题最高级别
|
||||||
|
///LowerHeadingLevel:标题最低级别
|
||||||
|
/// 使用 UpperHeadingLevel 属性可设置起始标题级别(最高)。例如,若要设置 TOC 域语法 {TOC \o "1-3"},可将 LowerHeadingLevel 属性设为 3,并将 UpperHeadingLevel 属性设为 1。
|
||||||
|
Function CustomAdd(posOpt, UpperHeadingLevel, LowerHeadingLevel);
|
||||||
|
Begin
|
||||||
|
//自定义页码计算与word、wps有差异,不推荐使用
|
||||||
|
_AddTableContent(posOpt, UpperHeadingLevel, LowerHeadingLevel);
|
||||||
|
End;
|
||||||
|
|
||||||
Function _AddDefaultTableContent(UpperHeadingLevel, LowerHeadingLevel);
|
Function _AddDefaultTableContent(UpperHeadingLevel, LowerHeadingLevel);
|
||||||
Begin
|
Begin
|
||||||
p := _AddItem(UpperHeadingLevel, LowerHeadingLevel, UpperHeadingLevel - 1, true);
|
p := _AddItem(UpperHeadingLevel, LowerHeadingLevel, UpperHeadingLevel - 1, true);
|
||||||
_AddStdContent(p);
|
_AddStdContent(p);
|
||||||
|
|
||||||
p2 := TOfficeObj('TParagraph');
|
p2 := TOfficeObj('TParagraph');
|
||||||
//p2.Format.SpaceAfter := 0;
|
//p2.Format.SpaceAfter := 0;
|
||||||
run := p2.AddRun();
|
run := p2.AddRun();
|
||||||
@@ -107,7 +117,7 @@ Type TTableContent = class
|
|||||||
run.fldCharType := 'end';
|
run.fldCharType := 'end';
|
||||||
_AddStdContent(p2);
|
_AddStdContent(p2);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
Function _AddItem(UpperHeadingLevel, LowerHeadingLevel, level, first);
|
Function _AddItem(UpperHeadingLevel, LowerHeadingLevel, level, first);
|
||||||
Begin
|
Begin
|
||||||
p := TOfficeObj('TParagraph');
|
p := TOfficeObj('TParagraph');
|
||||||
@@ -118,13 +128,13 @@ Type TTableContent = class
|
|||||||
tab := TOfficeObj('TTabStop');
|
tab := TOfficeObj('TTabStop');
|
||||||
tab.Val := 'right';
|
tab.Val := 'right';
|
||||||
tab.leader := 'dot';
|
tab.leader := 'dot';
|
||||||
tab.Position := 8640;
|
tab.Position := TOfficeApi().Get("TTableContent-tab-position") ?: 8306;
|
||||||
p.Format.Tabs.Add(0, tab);
|
p.Format.Tabs.Add(0, tab);
|
||||||
if first then Begin
|
if first then Begin
|
||||||
//fldCharType
|
//fldCharType
|
||||||
r1 := p.AddRun();
|
r1 := p.AddRun();
|
||||||
r1.fldCharType := 'begin';
|
r1.fldCharType := 'begin';
|
||||||
r1.Dirty := 'true';
|
r1.Dirty := 0;
|
||||||
|
|
||||||
//instrText
|
//instrText
|
||||||
r2 := p.AddRun();
|
r2 := p.AddRun();
|
||||||
@@ -142,7 +152,7 @@ Type TTableContent = class
|
|||||||
Begin
|
Begin
|
||||||
///获取标题列表 array((("Level":level,"Paragraph":"object","Text":title,"numId":,"ilvl":,"numArr":));
|
///获取标题列表 array((("Level":level,"Paragraph":"object","Text":title,"numId":,"ilvl":,"numArr":));
|
||||||
numMap := array();
|
numMap := array();
|
||||||
r := docx_.Document().Body().GetHeadingListImpl(docx_, posOpt, UpperHeadingLevel, LowerHeadingLevel, numMap, true);
|
r := docx_.Document().Body().GetHeadingListImpl(docx_, nil, UpperHeadingLevel, LowerHeadingLevel, numMap);
|
||||||
for i:=0 to length(r)-1 do Begin
|
for i:=0 to length(r)-1 do Begin
|
||||||
p := _AddItem(UpperHeadingLevel, LowerHeadingLevel, r[i]['Level'], i = 0 ? true: false);
|
p := _AddItem(UpperHeadingLevel, LowerHeadingLevel, r[i]['Level'], i = 0 ? true: false);
|
||||||
//fldCharType
|
//fldCharType
|
||||||
@@ -160,9 +170,9 @@ Type TTableContent = class
|
|||||||
if ifObj(style) then
|
if ifObj(style) then
|
||||||
numStr := style.GetText(r[i]['ilvl'], r[i]['numArr']);
|
numStr := style.GetText(r[i]['ilvl'], r[i]['numArr']);
|
||||||
End
|
End
|
||||||
if numStr <> '' then run_t := numStr + ' ' + r[i]['Text'];
|
run_t := class(TSXml).CurCodePageToUtf8(r[i]['Text']);
|
||||||
else run_t := r[i]['Text'];
|
if numStr <> '' then run_t := numStr + ' ' + run_t;
|
||||||
r1.SetText(run_t);
|
r1.SetText(run_t, 1);
|
||||||
|
|
||||||
r2 := h.AddRun();
|
r2 := h.AddRun();
|
||||||
r2.rPr.noProof := true;
|
r2.rPr.noProof := true;
|
||||||
@@ -203,7 +213,6 @@ Type TTableContent = class
|
|||||||
r8.fldCharType := 'end';
|
r8.fldCharType := 'end';
|
||||||
|
|
||||||
_AddStdContent(p);
|
_AddStdContent(p);
|
||||||
|
|
||||||
End;
|
End;
|
||||||
|
|
||||||
p2 := TOfficeObj('TParagraph');
|
p2 := TOfficeObj('TParagraph');
|
||||||
@@ -215,29 +224,49 @@ Type TTableContent = class
|
|||||||
_AddStdContent(p2);
|
_AddStdContent(p2);
|
||||||
|
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///更新目录
|
///更新目录
|
||||||
Function UpdatePageNumbers();
|
Function UpdatePageNumbers();
|
||||||
Begin
|
Begin
|
||||||
End;
|
End;
|
||||||
|
|
||||||
|
Function Paragraphs();
|
||||||
|
Begin
|
||||||
|
node := class(TSXml).GetNode(docx_.Document().Body().Node(), 'w:sdt/w:sdtContent');
|
||||||
|
r := array();
|
||||||
|
if ifObj(node) then
|
||||||
|
begin
|
||||||
|
twbody := TOfficeObj('TwBody');
|
||||||
|
twbody.Create(nil, 'w:sdtContent');
|
||||||
|
twbody.InitRootNode(node);
|
||||||
|
twbody.InitNode(node);
|
||||||
|
parts := twbody.Paragraphs();
|
||||||
|
for i:=0 to length(parts)-1 do
|
||||||
|
begin
|
||||||
|
r[i] := TOfficeObj('TParagraph');
|
||||||
|
r[i].Init(parts[i].node_);
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return r;
|
||||||
|
End;
|
||||||
|
|
||||||
Function Marshal();
|
Function Marshal();
|
||||||
Begin
|
Begin
|
||||||
return impl_.Marshal();
|
return impl_.Marshal();
|
||||||
End;
|
End;
|
||||||
|
|
||||||
Property Format read readFormat;
|
Property Format read readFormat;
|
||||||
Function readFormat();
|
Function readFormat();
|
||||||
Begin
|
Begin
|
||||||
return impl_.sdtPr;
|
return impl_.sdtPr;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
Property EndFormat read readEndFormat;
|
Property EndFormat read readEndFormat;
|
||||||
Function readEndFormat();
|
Function readEndFormat();
|
||||||
Begin
|
Begin
|
||||||
return impl_.sdtEndPr;
|
return impl_.sdtEndPr;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
Property Font read readFont;
|
Property Font read readFont;
|
||||||
Function readFont();
|
Function readFont();
|
||||||
Begin
|
Begin
|
||||||
@@ -248,7 +277,7 @@ Type TTableContent = class
|
|||||||
Begin
|
Begin
|
||||||
impl_.SdtContent.NewChildNode( array("field":"", "name":"w:p", "obj":o, "attrEx":"", "nodeType":"") );
|
impl_.SdtContent.NewChildNode( array("field":"", "name":"w:p", "obj":o, "attrEx":"", "nodeType":"") );
|
||||||
End;
|
End;
|
||||||
|
|
||||||
Function _GetStyle(level);
|
Function _GetStyle(level);
|
||||||
Begin
|
Begin
|
||||||
styleName := ifstring(level) ? level : 'TOC' $ (level + 1);
|
styleName := ifstring(level) ? level : 'TOC' $ (level + 1);
|
||||||
@@ -258,30 +287,30 @@ Type TTableContent = class
|
|||||||
End;
|
End;
|
||||||
return style.StyleId;
|
return style.StyleId;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
Function _GetBookMarkId(p);
|
Function _GetBookMarkId(p);
|
||||||
Begin
|
Begin
|
||||||
node := p.node_.FirstChildElement('w:bookmarkStart');
|
node := p.node_.FirstChildElement('w:bookmarkStart');
|
||||||
if ifObj(node) then
|
if ifObj(node) then
|
||||||
return node.GetAttribute('w:name');
|
return node.GetAttribute('w:name');
|
||||||
bookMarkID := docx_.Document().GetBookMarkID();
|
bookMarkID := docx_.Document().GetBookMarkID();
|
||||||
return p.AddBookMark();
|
return p.AddBookMark(bookMarkID);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
Function _CheckNodes(name);
|
Function _CheckNodes(name);
|
||||||
Begin
|
Begin
|
||||||
z := docx_.Zip();
|
z := docx_.Zip();
|
||||||
xml := z.Get('word/' + name);
|
xml := z.Get('word/' + name);
|
||||||
if not ifObj(xml) then Begin
|
if not ifObj(xml) then Begin
|
||||||
xmlData := TOfficeTemplate(name);
|
xmlData := TOfficeTemplate(name);
|
||||||
if not ifString(xmlData) then
|
if not ifString(xmlData) then
|
||||||
return ;
|
return ;
|
||||||
z.Add('word/' + name, xmlData);
|
z.Add('word/' + name, xmlData);
|
||||||
rels := 'word/_rels/document.xml.rels';
|
rels := 'word/_rels/document.xml.rels';
|
||||||
relsObj := z.Get(rels);
|
relsObj := z.Get(rels);
|
||||||
[rId, target] := class(TSXml).FindRelationshipRid(relsObj, '');
|
[rId, target] := class(TSXml).FindRelationshipRid(relsObj, '');
|
||||||
rId ++;
|
rId ++;
|
||||||
|
|
||||||
if name = 'endnotes.xml' then Begin
|
if name = 'endnotes.xml' then Begin
|
||||||
class(TSXml).AddRelationshipRid(relsObj, name, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes', 'rId' $ rId);
|
class(TSXml).AddRelationshipRid(relsObj, name, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes', 'rId' $ rId);
|
||||||
contentType := z.Get('[Content_Types].xml');
|
contentType := z.Get('[Content_Types].xml');
|
||||||
@@ -294,8 +323,9 @@ Type TTableContent = class
|
|||||||
End;
|
End;
|
||||||
End;
|
End;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
docx_;
|
[weakref]docx_;
|
||||||
node_;
|
node_;
|
||||||
impl_;
|
impl_;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ Type docxDocument = Class
|
|||||||
bodyNode_ := root_.FirstChildElement('w:body');
|
bodyNode_ := root_.FirstChildElement('w:body');
|
||||||
body_ := TOfficeObj('TwBody');
|
body_ := TOfficeObj('TwBody');
|
||||||
body_.InitNode(bodyNode_);
|
body_.InitNode(bodyNode_);
|
||||||
|
body_.InitRootNode(bodyNode_);
|
||||||
body_.zipfile_ := z;
|
body_.zipfile_ := z;
|
||||||
body_.document_ := self;
|
body_.document_ := self;
|
||||||
bookmarkid_ := -1;
|
bookmarkid_ := -1;
|
||||||
@@ -19,6 +20,11 @@ Type docxDocument = Class
|
|||||||
Begin
|
Begin
|
||||||
return body_;
|
return body_;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
|
Function AddNameSpace(prefix, uri);
|
||||||
|
Begin
|
||||||
|
root_.SetAttribute('xmlns:' + prefix, uri);
|
||||||
|
End;
|
||||||
|
|
||||||
Function GetBookMarkID();
|
Function GetBookMarkID();
|
||||||
Begin
|
Begin
|
||||||
@@ -29,7 +35,7 @@ Type docxDocument = Class
|
|||||||
markStart := p.FirstChildElement('w:bookmarkStart');
|
markStart := p.FirstChildElement('w:bookmarkStart');
|
||||||
if ifObj(markStart) then Begin
|
if ifObj(markStart) then Begin
|
||||||
id := markStart.GetAttribute('w:id');
|
id := markStart.GetAttribute('w:id');
|
||||||
if ifstring(id) then Begin
|
if ifstring(id) and id <> '' then Begin
|
||||||
iVal := strtoint(id);
|
iVal := strtoint(id);
|
||||||
if bookmarkid_ <= iVal then
|
if bookmarkid_ <= iVal then
|
||||||
bookmarkid_ := iVal + 1;
|
bookmarkid_ := iVal + 1;
|
||||||
@@ -48,4 +54,4 @@ private
|
|||||||
body_;
|
body_;
|
||||||
document_;
|
document_;
|
||||||
bookmarkid_;
|
bookmarkid_;
|
||||||
End;
|
End;
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ Type xlsxChart = Class(TSChart)
|
|||||||
node := drawingXmlObj_.FirstChild('xdr:wsDr').InsertEndChild(o.Marshal());
|
node := drawingXmlObj_.FirstChild('xdr:wsDr').InsertEndChild(o.Marshal());
|
||||||
End;
|
End;
|
||||||
private
|
private
|
||||||
excel_;
|
[weakref]excel_;
|
||||||
drawingRID_:integer;
|
drawingRID_:integer;
|
||||||
chartId_;
|
chartId_;
|
||||||
chartRid_;
|
chartRid_;
|
||||||
|
|||||||
@@ -148,7 +148,11 @@ xmlns:v="urn:schemas-microsoft-com:vml">
|
|||||||
comment += r_node.FirstChildElement('t').GetText();
|
comment += r_node.FirstChildElement('t').GetText();
|
||||||
r_node := r_node.NextElement();
|
r_node := r_node.NextElement();
|
||||||
end
|
end
|
||||||
if length(comment) > 1 then comment := comment[2:];
|
if length(comment) > 1 then
|
||||||
|
begin
|
||||||
|
if comment[1] = "\n" then comment := comment[2:];
|
||||||
|
else if comment[1:2] = "\r\n" then comment := comment[3:];
|
||||||
|
end
|
||||||
return array(author, comment);
|
return array(author, comment);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
@@ -180,6 +184,7 @@ private
|
|||||||
End;
|
End;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
|
[weakref]excel_;//TSXlsxFile对象
|
||||||
authors_;
|
authors_;
|
||||||
commentId_;
|
commentId_;
|
||||||
commentFileName_:string;//'../comments/comment1.xml'
|
commentFileName_:string;//'../comments/comment1.xml'
|
||||||
@@ -187,7 +192,6 @@ private
|
|||||||
rId_:string;
|
rId_:string;
|
||||||
sheetName_:string;//sheet名称
|
sheetName_:string;//sheet名称
|
||||||
sheetFileName_;//xl/worksheets/sheetN.xml
|
sheetFileName_;//xl/worksheets/sheetN.xml
|
||||||
excel_;//TSExcelFile对象
|
|
||||||
commentXmlFile_;//XmlFile对象
|
commentXmlFile_;//XmlFile对象
|
||||||
commentObjs_;
|
commentObjs_;
|
||||||
End;
|
End;
|
||||||
|
|||||||
@@ -45,5 +45,5 @@ Type xlsxDocProps = Class
|
|||||||
End;
|
End;
|
||||||
|
|
||||||
private
|
private
|
||||||
excel_; //TSExcelFile对象
|
[weakref]excel_; //TSExcelFile对象
|
||||||
End;
|
End;
|
||||||
|
|||||||
@@ -33,6 +33,6 @@ Type xlsxHeaderFooter = Class
|
|||||||
|
|
||||||
private
|
private
|
||||||
sheet_; //XmlSheet对象
|
sheet_; //XmlSheet对象
|
||||||
file_; //TSExcelFile对象
|
[weakref]file_; //TSExcelFile对象
|
||||||
xmlFile_; //sheet对应的xml对象
|
xmlFile_; //sheet对应的xml对象
|
||||||
End;
|
End;
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ Type xlsxHyperLink = Class
|
|||||||
End;
|
End;
|
||||||
|
|
||||||
private
|
private
|
||||||
file_; //TSExcelFile对象
|
[weakref]file_; //TSExcelFile对象
|
||||||
xmlFile_;//XmlFile对象
|
xmlFile_;//XmlFile对象
|
||||||
sheetName_;
|
sheetName_;
|
||||||
|
|
||||||
|
|||||||
@@ -169,6 +169,6 @@ private
|
|||||||
|
|
||||||
private
|
private
|
||||||
sheetName_:string; //sheet名称
|
sheetName_:string; //sheet名称
|
||||||
excel_;//TSExcelFile对象
|
[weakref]excel_;//TSExcelFile对象
|
||||||
zipfile_;
|
zipfile_;
|
||||||
End;
|
End;
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ Type xlsxPageLayout = Class
|
|||||||
End;
|
End;
|
||||||
|
|
||||||
private
|
private
|
||||||
file_; //TSExcelFile对象
|
[weakref]file_; //TSExcelFile对象
|
||||||
sheet_;//XmlSheet对象
|
sheet_;//XmlSheet对象
|
||||||
xmlFile_; //sheet对应的xml对象
|
xmlFile_; //sheet对应的xml对象
|
||||||
End;
|
End;
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ private
|
|||||||
|
|
||||||
private
|
private
|
||||||
sheetName_:string; //sheet名称
|
sheetName_:string; //sheet名称
|
||||||
excel_;//TSExcelFile对象
|
[weakref]excel_;//TSExcelFile对象
|
||||||
zipfile_;
|
zipfile_;
|
||||||
drawingXmlObj_;
|
drawingXmlObj_;
|
||||||
End;
|
End;
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ Type xlsxSheetView = Class
|
|||||||
End;
|
End;
|
||||||
|
|
||||||
private
|
private
|
||||||
file_; //TSExcelFile对象
|
[weakref]file_; //TSExcelFile对象
|
||||||
sheet_;//XmlSheet对象
|
sheet_;//XmlSheet对象
|
||||||
xmlFile_; //sheet对应的xml对象
|
xmlFile_; //sheet对应的xml对象
|
||||||
End;
|
End;
|
||||||
|
|||||||
@@ -1,15 +1,29 @@
|
|||||||
Type xlsxStyles = Class
|
Type xlsxStyles = Class
|
||||||
|
|
||||||
Function Create(sheetobj, file);
|
Function Create(file);
|
||||||
Begin
|
Begin
|
||||||
sheet_ := sheetobj;
|
|
||||||
file_ := file;
|
file_ := file;
|
||||||
styleXmlFile_ := file_.WorkBook().GetXmlFileObj('xl/styles.xml');
|
style_xml_file_ := file_.WorkBook().GetXmlFileObj('xl/styles.xml');
|
||||||
|
style_ := array();
|
||||||
|
Init();
|
||||||
End
|
End
|
||||||
|
|
||||||
|
Function Init();
|
||||||
|
Begin
|
||||||
|
style_node := style_xml_file_.FirstChildElement("styleSheet");
|
||||||
|
xfs_node := style_node.FirstChildElement("cellXfs");
|
||||||
|
xf_node := xfs_node.FirstChildElement("xf");
|
||||||
|
count := 0;
|
||||||
|
while ifObj(xf_node) do
|
||||||
|
begin
|
||||||
|
style_[inttostr(count++)] := xf_node;
|
||||||
|
xf_node := xf_node.NextElement("xf");
|
||||||
|
end
|
||||||
|
End
|
||||||
|
|
||||||
Function GetStyleId(style);overload;
|
Function GetStyleId(style);overload;
|
||||||
Begin
|
Begin
|
||||||
node := styleXmlFile_.FirstChildElement('styleSheet');
|
node := style_xml_file_.FirstChildElement('styleSheet');
|
||||||
font_id := insertNode(node, 'fonts', style.Font);
|
font_id := insertNode(node, 'fonts', style.Font);
|
||||||
border_id := insertNode(node, 'borders', style.Border);
|
border_id := insertNode(node, 'borders', style.Border);
|
||||||
fill_id := insertNode(node, 'fills', style.Fill);
|
fill_id := insertNode(node, 'fills', style.Fill);
|
||||||
@@ -40,15 +54,16 @@ Type xlsxStyles = Class
|
|||||||
|
|
||||||
node := node.FirstChildElement('cellXfs');
|
node := node.FirstChildElement('cellXfs');
|
||||||
count := node.GetAttribute('count');
|
count := node.GetAttribute('count');
|
||||||
node.InsertEndChild(xf.Marshal());
|
|
||||||
node.SetAttribute('count', strtoint(count) + 1);
|
node.SetAttribute('count', strtoint(count) + 1);
|
||||||
|
xf_node := node.InsertEndChild(xf.Marshal());
|
||||||
|
style_[count] := xf_node;
|
||||||
return count;
|
return count;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
Function GetStyleId(newStyle, oldStyleId);overload;
|
Function GetStyleId(newStyle, oldStyleId);overload;
|
||||||
Begin
|
Begin
|
||||||
if oldStyleId = '' then return nil;
|
if oldStyleId = '' then return nil;
|
||||||
style_node := styleXmlFile_.FirstChildElement('styleSheet');
|
style_node := style_xml_file_.FirstChildElement('styleSheet');
|
||||||
cellXfs_node := style_node.FirstChildElement('cellXfs');
|
cellXfs_node := style_node.FirstChildElement('cellXfs');
|
||||||
count := strtoint(cellXfs_node.GetAttribute('count'));
|
count := strtoint(cellXfs_node.GetAttribute('count'));
|
||||||
Id := strtoint(oldStyleId);
|
Id := strtoint(oldStyleId);
|
||||||
@@ -89,19 +104,14 @@ Type xlsxStyles = Class
|
|||||||
xf_node.SetAttribute('applyProtection', 1);
|
xf_node.SetAttribute('applyProtection', 1);
|
||||||
end
|
end
|
||||||
|
|
||||||
|
style_[inttostr(count)] := xf_node;
|
||||||
return inttostr(count);
|
return inttostr(count);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
Function GetStyle(styleId);
|
Function GetStyle(styleId);
|
||||||
Begin
|
Begin
|
||||||
if styleId = '' then return nil;
|
xf := style_[styleId];
|
||||||
style_node := styleXmlFile_.FirstChildElement('styleSheet');
|
if not ifObj(xf) then return nil;
|
||||||
cellXfs_node := style_node.FirstChildElement('cellXfs');
|
|
||||||
count := strtoint(cellXfs_node.GetAttribute('count'));
|
|
||||||
Id := strtoint(styleId);
|
|
||||||
if Id > count-1 then return nil;
|
|
||||||
|
|
||||||
xf := getNode(cellXfs_node, 'xf', Id);
|
|
||||||
attrs := xf.Attributes();
|
attrs := xf.Attributes();
|
||||||
numfmt_id := trystrtoint(attrs['numFmtId'], r) ? r : 0;
|
numfmt_id := trystrtoint(attrs['numFmtId'], r) ? r : 0;
|
||||||
font_id := trystrtoint(attrs['fontId'], r) ? r : 0;
|
font_id := trystrtoint(attrs['fontId'], r) ? r : 0;
|
||||||
@@ -110,6 +120,7 @@ Type xlsxStyles = Class
|
|||||||
|
|
||||||
alignment := xf.FirstChildElement('alignment');
|
alignment := xf.FirstChildElement('alignment');
|
||||||
protection := xf.FirstChildElement('protection');
|
protection := xf.FirstChildElement('protection');
|
||||||
|
style_node := style_xml_file_.FirstChildElement('styleSheet');
|
||||||
style := TOfficeObj('TStyle');
|
style := TOfficeObj('TStyle');
|
||||||
numFmts_node := style_node.FirstChildElement('numFmts');
|
numFmts_node := style_node.FirstChildElement('numFmts');
|
||||||
fonts_node := style_node.FirstChildElement('fonts');
|
fonts_node := style_node.FirstChildElement('fonts');
|
||||||
@@ -127,12 +138,51 @@ Type xlsxStyles = Class
|
|||||||
return style;
|
return style;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
class Function NewObject(sheetname, file);
|
Function GetNumFmtId(styleId);
|
||||||
Begin
|
Begin
|
||||||
o := file.WorkBook().GetSheetObj(sheetname);
|
node := style_[styleId];
|
||||||
if not ifObj(o) then return 0;
|
if ifnil(node) then return '0';
|
||||||
styles := new xlsxStyles(o, file);
|
numfmt := node.GetAttribute("numFmtId");
|
||||||
return styles;
|
return numfmt = '' ? '' : numfmt;
|
||||||
|
End;
|
||||||
|
|
||||||
|
Function GetType(styleId, value);
|
||||||
|
Begin
|
||||||
|
numfmt_id := GetNumFmtId(styleId);
|
||||||
|
if numfmt_id = '' then return array(nil, value);
|
||||||
|
numfmt_id := strtoint(numfmt_id);
|
||||||
|
if numfmt_id = 0 then return array(nil, value);
|
||||||
|
if numfmt_id >= 1 and numfmt_id <= 10 then return array('n', value);
|
||||||
|
if numfmt_id >= 11 and numfmt_id <= 26 then
|
||||||
|
begin
|
||||||
|
if ifstring(value) and (trystrtodate(value, r) or trystrtodatetime(value, r) or trystrtotime(value, r)) then return array('n', r);
|
||||||
|
t := ifstring(value) ? 's' : 'n';
|
||||||
|
return array(t, value);
|
||||||
|
end
|
||||||
|
if numfmt_id >= 27 and numfmt_id <= 34 then return array('e', value);
|
||||||
|
if numfmt_id >= 35 and numfmt_id <= 48 then return array('n', value);
|
||||||
|
if numfmt_id = 49 then return array('s', value);
|
||||||
|
if numfmt_id >= 50 and numfmt_id <= 55 then
|
||||||
|
begin
|
||||||
|
if ifstring(value) and trystrtodate(value, r) then return array('n', r);
|
||||||
|
t := ifstring(value) ? 's' : 'n';
|
||||||
|
return array(t, value);
|
||||||
|
end
|
||||||
|
if numfmt_id >= 56 and numfmt_id <= 58 then
|
||||||
|
begin
|
||||||
|
if ifstring(value) and trystrtodatetime(value, r) then return array('n', r);
|
||||||
|
t := ifstring(value) ? 's' : 'n';
|
||||||
|
return array(t, value);
|
||||||
|
end
|
||||||
|
else begin
|
||||||
|
if ifstring(value) then
|
||||||
|
begin
|
||||||
|
if (pos("-", value) or pos("/", value)) and (trystrtodatetime(value, r) or trystrtodate(value, r)) then return array('n', r);
|
||||||
|
if trystrtofloat(value, r) then return array("n", value);
|
||||||
|
return array("s", value);
|
||||||
|
end
|
||||||
|
return array("n", value);
|
||||||
|
end
|
||||||
End;
|
End;
|
||||||
|
|
||||||
private
|
private
|
||||||
@@ -286,7 +336,61 @@ private
|
|||||||
End
|
End
|
||||||
|
|
||||||
private
|
private
|
||||||
sheet_; //XmlSheet对象
|
[weakref]file_; //TSXlsxFile对象
|
||||||
file_; //TSExcelFile对象
|
style_xml_file_;
|
||||||
styleXmlFile_; //xmlFile对象
|
style_; // 缓存style
|
||||||
End;
|
End;
|
||||||
|
|
||||||
|
// 参考:https://learn.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.numberingformat?view=openxml-3.0.1
|
||||||
|
// 0 General
|
||||||
|
// 1 0
|
||||||
|
// 2 0.00
|
||||||
|
// 3 #,##0
|
||||||
|
// 4 #,##0.00
|
||||||
|
// 5 整数,货币符号旁边($#,##0_);($#,##0))
|
||||||
|
// 6 带两位小数的货币符号($#,##0.00_);($#,##0.00)
|
||||||
|
// 7 整数,带括号表示负数($#,##0_);Red
|
||||||
|
// 8 带两位小数的货币符号和红色负数($#,##0.00_);Red
|
||||||
|
// 9 0%
|
||||||
|
// 10 0.00%
|
||||||
|
// 11 0.00E+00
|
||||||
|
// 12 # ?/?
|
||||||
|
// 13 # ??/??
|
||||||
|
// 14 mm-dd-yy
|
||||||
|
// 15 d-mmm-yy
|
||||||
|
// 16 d-mmm
|
||||||
|
// 17 mmm-yy
|
||||||
|
// 18 h:mm AM/PM
|
||||||
|
// 19 h:mm:ss AM/PM
|
||||||
|
// 20 h:mm
|
||||||
|
// 21 h:mm:ss
|
||||||
|
// 22 m/d/yy h:mm
|
||||||
|
// 27 [$-404]e/m/d yyyy"年"m"月"
|
||||||
|
// 28 [$-404]e"年"m"月"d"日" m"月"d"日"
|
||||||
|
// 29 [$-404]e"年"m"月"d"日" m"月"d"日"
|
||||||
|
// 30 m/d/yy m-d-yy
|
||||||
|
// 31 yyyy"年"m"月"d"日" yyyy"年"m"月"d"日"
|
||||||
|
// 32 hh"時"mm"分" h"时"mm"分"
|
||||||
|
// 33 hh"時"mm"分"ss"秒" h"时"mm"分"ss"秒"
|
||||||
|
// 34 上午/下午hh"時"mm"分" 上午/下午h"时"mm"分"
|
||||||
|
// 35 上午/下午hh"時"mm"分"ss"秒" 上午/下午h"时"mm"分"ss"秒"
|
||||||
|
// 36 [$-404]e/m/d yyyy"年"m"月"
|
||||||
|
// 37 #,##0 ;(#,##0)
|
||||||
|
// 38 #,##0 ;[Red](#,##0)
|
||||||
|
// 39 #,##0.00;(#,##0.00)
|
||||||
|
// 40 #,##0.00;[Red](#,##0.00)
|
||||||
|
// 45 mm:ss
|
||||||
|
// 46 [h]:mm:ss
|
||||||
|
// 47 mmss.0
|
||||||
|
// 48 ##0.0E+0
|
||||||
|
// 49 @(文本)
|
||||||
|
// 50 [$-404]e/m/d yyyy"年"m"月"
|
||||||
|
// 51 [$-404]e"年"m"月"d"日" m"月"d"日"
|
||||||
|
// 52 上午/下午hh"時"mm"分" yyyy"年"m"月"
|
||||||
|
// 53 上午/下午hh"時"mm"分"ss"秒" m"月"d"日"
|
||||||
|
// 54 [$-404]e"年"m"月"d"日" m"月"d"日"
|
||||||
|
// 55 上午/下午hh"時"mm"分" 上午/下午h"时"mm"分"
|
||||||
|
// 56 上午/下午hh"時"mm"分"ss"秒" 上午/下午h"时"mm"分"ss"秒"
|
||||||
|
// 57 [$-404]e/m/d yyyy"年"m"月"
|
||||||
|
// 58 [$-404]e"年"m"月"d"日" m"月"d"日"
|
||||||
|
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ private
|
|||||||
|
|
||||||
private
|
private
|
||||||
sheetName_:string; //sheet名称
|
sheetName_:string; //sheet名称
|
||||||
excel_;//TSExcelFile对象
|
[weakref]excel_;//TSExcelFile对象
|
||||||
zipfile_;
|
zipfile_;
|
||||||
tableXmlFile_;
|
tableXmlFile_;
|
||||||
End;
|
End;
|
||||||
|
|||||||
+1645
-1604
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user