Compare commits

..
49 Commits
Author SHA1 Message Date
csh 19b8614c93 v1.8.8 2026-09-10 15:03:04 +08:00
csh 3df8ce2be0 v1.8.7 2026-07-30 14:05:16 +08:00
csh 6b0f11cebb v1.8.6 2026-01-16 14:32:22 +08:00
csh bbe0821f68 v1.8.5 2025-12-15 13:28:02 +08:00
csh ea528f3094 v1.8.4 2025-11-07 14:24:12 +08:00
csh 95a00e7002 v1.8.3 2025-10-30 15:58:12 +08:00
csh 2b62e4e1a5 v1.8.3 2025-10-30 15:50:10 +08:00
csh a2c3905cd0 v1.8.2 2025-10-29 15:47:51 +08:00
csh ca03e53285 v1.8.1 2025-07-22 16:35:36 +08:00
csh d57631a19a v1.8.0 2025-06-23 10:50:55 +08:00
csh c05b646104 v1.7.9 2025-02-28 13:41:23 +08:00
csh 39b7549665 v1.7.8 2025-01-22 13:58:18 +08:00
csh 93533c41a0 v1.7.7 2025-01-17 18:33:30 +08:00
csh 0f07603d73 v1.7.6 2025-01-08 15:31:04 +08:00
csh 3c16ce510a v1.7.5 2025-01-07 10:56:24 +08:00
csh 3243db0e2d v1.7.4-patch1 2024-12-23 14:17:49 +08:00
csh fdd2bd0fef v1.7.4 2024-12-23 11:07:05 +08:00
csh 2d423ca1fb v1.7.3 2024-12-05 16:37:20 +08:00
csh 0e35cc0463 v1.7.2 2024-12-04 09:50:13 +08:00
csh c7b7971d9a v1.7.1 2024-11-19 18:26:49 +08:00
csh 066a8f6562 v1.70-patch3 2024-07-31 13:30:20 +08:00
csh 9e04cc2cff v1.7.0-patch2 2024-07-26 14:11:22 +08:00
csh bb8d3591ac v1.7.0-patch1 2024-07-22 11:06:49 +08:00
csh 037cb41560 v1.7.0 2024-07-18 17:26:41 +08:00
csh 5469ca318d v1.6.9 2024-05-06 15:12:37 +08:00
csh c3432d1812 v1.6.8-patch1 2024-04-17 16:22:48 +08:00
csh 53d83f91ae v1.6.8 2024-04-12 14:14:47 +08:00
csh 893a3a928b v1.6.7-patch1 2024-03-25 10:15:28 +08:00
csh 72554969bb v1.6.7 2024-03-21 16:34:38 +08:00
csh fa8800e20d v.1.6.6-patch2 2024-03-15 10:27:28 +08:00
csh 92257c380f v1.6.6-patch1 2024-03-14 14:09:55 +08:00
csh fb22cf9b0a v1.6.6 2024-03-14 10:18:16 +08:00
csh a3df0d5df9 v1.6.5 2024-03-04 16:14:03 +08:00
csh b4ef4a531c v1.6.4 2024-03-04 14:11:34 +08:00
csh f499526f04 v1.6.3 2024-02-23 11:19:29 +08:00
csh c1a93bb16e v1.6.2 2024-02-07 15:59:35 +08:00
csh 03e101fa46 v1.6.1 2024-02-06 11:28:13 +08:00
csh 1231868aa7 v1.6.0 2024-02-05 16:15:22 +08:00
csh 6d6281229c v1.5.9 2024-01-31 17:39:37 +08:00
csh 522e52ed46 v1.5.8 2024-01-31 09:52:10 +08:00
csh a774f57335 v1.5.7-patch1 2024-01-30 18:03:53 +08:00
csh 800f91870d v1.5.7 2024-01-17 17:10:16 +08:00
csh e5d011e59b v1.5.6-patch1 2024-01-12 09:11:38 +08:00
csh d588ac67d4 v1.5.6 2024-01-11 15:00:26 +08:00
csh dc7d48c318 v1.5.5 2023-12-29 10:11:50 +08:00
csh fcb2a8e7b3 v1.5.4 2023-12-18 11:33:26 +08:00
csh 91f3c5af49 v1.5.3-patch1 2023-12-15 15:14:44 +08:00
csh c16566d2f1 v1.5.3 2023-12-11 15:48:41 +08:00
csh 3607dab833 v1.5.2-patch2 2023-12-07 14:04:28 +08:00
35 changed files with 14151 additions and 13160 deletions
+4
View File
@@ -0,0 +1,4 @@
*.swp
*.swo
*.cmd
script.ps1
+3
View File
@@ -0,0 +1,3 @@
[submodule "funcext/TSOffice/Extensions/OfficeVba"]
path = funcext/TSOffice/Extensions/OfficeVba
url = https://git.mytsl.cn/tinysoft/OfficeVba.git
+1 -1
View File
@@ -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);
+5 -3
View File
@@ -1,8 +1,8 @@
path := ExtractFileDir(ExtractFileDir(PluginPath())); path := ExtractFileDir(ExtractFileDir(PluginPath()));
{$IFNDEF Win32} {$IFNDEF Win32}
path := path + '\\funcext\\TSOffice\\TSXlsxFile.tsf';
{$ELSE}
path := path + '/funcext/TSOffice/TSXlsxFile.tsf'; path := path + '/funcext/TSOffice/TSXlsxFile.tsf';
{$ELSE}
path := path + '\\funcext\\TSOffice\\TSXlsxFile.tsf';
{$ENDIF} {$ENDIF}
funcs := LoadClassInfo(path); funcs := LoadClassInfo(path);
@@ -43,6 +43,7 @@ PrintSuccess("GetCellRichText", testing++);
file.MergeCell('XlsxFile', 'A1', 'C1'); file.MergeCell('XlsxFile', 'A1', 'C1');
PrintSuccess("MergeCell", testing++); PrintSuccess("MergeCell", testing++);
file.SetRowHeight('XlsxFile', 1, 60);
style := TOfficeObj('TStyle'); style := TOfficeObj('TStyle');
@@ -138,7 +139,7 @@ End
file.SetColWidth('Functions', 'A', 'A', 120); file.SetColWidth('Functions', 'A', 'A', 120);
PrintSuccess('SetColWidth', testing++); PrintSuccess('SetColWidth', testing++);
saveName := utf8toansi("XlsxFile使用帮助.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.
+12 -5
View File
@@ -1,4 +1,4 @@
# OfficePlugin # TSOffice
TSOffice 项目:纯 TSL 代码实现 excel、word 文件读写 TSOffice 项目:纯 TSL 代码实现 excel、word 文件读写
@@ -6,19 +6,19 @@ TSOffice 项目:纯 TSL 代码实现 excel、word 文件读写
### windows ### windows
对应文件夹的dll文件按如下要求 对应文件夹的 dll 文件按如下要求
- `office_plugin` 放入 tsl 安装根目录下 Plugin 文件夹 - `office_plugin` 放入 tsl 安装根目录下 Plugin 文件夹
可选: 可选:
- `fmt_pubkrnl_plugin` 放入 tsl 安装根目录下 Plugin 文件夹,若需要执行Demo文件夹下的[XlsxHelp.tsl](./Demo/XlsxHelp.tsl)和[DocxHelp.tsl](./Demo/DocxHelp.tsl),需要部署改动态库 - `fmt_pubkrnl_plugin` 放入 tsl 安装根目录下 Plugin 文件夹,若需要执行 Demo 文件夹下的[XlsxHelp.tsl](./Demo/XlsxHelp.tsl)和[DocxHelp.tsl](./Demo/DocxHelp.tsl),需要部署改动态库
### Linux ### Linux
#### Ubuntu-18.04 #### Ubuntu-18.04
根据架构选择aarch64x86版本将对应文件夹内容进行部署 根据架构选择 aarch64x86 版本将对应文件夹内容进行部署
- `liboffice_plugin` 放入 tsl 安装根目录下 Plugin 文件夹 - `liboffice_plugin` 放入 tsl 安装根目录下 Plugin 文件夹
@@ -28,7 +28,14 @@ TSOffice 项目:纯 TSL 代码实现 excel、word 文件读写
- [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.
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large Load Diff
+299 -271
View File
@@ -1,271 +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(position);overload; 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, position); 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 Update();overload; Function Update();overload;
Begin Begin
self.Update("end"); self.Update("end");
End; End;
Function Delete(); Function Delete();overload;
Begin Begin
if ifObj(RootObj) then if ifObj(RootObj) then
begin begin
curNode := class(TSXml).GetNode(RootObj, NodeUri); curNode := class(TSXml).GetNode(RootObj, NodeUri);
if ifObj(curNode) then curNode.DeleteChildren(); if ifObj(curNode) then curNode.DeleteChildren();
end end
End; End;
Function GetAttrs(); virtual; Function Delete(name);overload;
Begin Begin
return ExtAttr; if not ifObj(RootObj) then return false;
End node := NodeUri <> '' ? class(TSXml).GetNode(RootObj, NodeUri) : RootObj;
Function GetChildren(); virtual; attrs := GetAttrsEx();
Begin lName := lowerCase(name);
return ExtNodes; r := sselect * from attrs where lName = lowerCase([0]) end;
End if istable(r) then
begin
Function GetNode(index); // 返回的index的对象 node.DeleteAttribute(r[1]);
Begin return true;
return ExtNodes[index]['obj']; end
End
children := GetChildren();
Function GetCount(); // 返回当前节点的个数 r := select * from children where lName = lowerCase(['field']) end;
Begin if istable(r) then Begin
return length(ExtAttr); r := r[0];
End delete_node := node.FirstChildElement(r['name']);
if ifObj(delete_node) then
// arr := array(('Size', 'sz', 15), ('Style', 'style', 'line')); begin
Function AddAttr(arr); // 添加属性 node.DeleteChild(delete_node);
Begin return true;
if not istable(arr) then return; end
ExtAttr union= arr; End;
return 1; return false;
End End;
Function Marshal(); Function GetAttrs(); virtual;
Begin Begin
children_ := nil; return ExtAttr;
GetChildrenEx(); //优化为变量,减少数据COPY2022-12-10 End
child_arr := array();
name_map := array(); Function GetChildren(); virtual;
len := 0; Begin
for i:=0 to length(children_)-1 do return ExtNodes;
begin End
node_type := children_[i]['nodeType'];
obj := children_[i]['obj']; Function GetNode(index); // 返回的index的对象
if ifnil(obj) then continue; Begin
if not ifObj(obj) and not ifnil(name_map[children_[i]['name']]) and children_[i]['attrEx'] <> '' then return ExtNodes[index]['obj'];
begin End
child_arr[name_map[children_[i]['name']]]['attributes'] union=array(children_[i]['attrEx'] : obj);
continue; Function GetCount(); // 返回当前节点的个数
end Begin
return length(ExtAttr);
arr := array('type': 'element', 'name': children_[i]['name'], 'attributes': array()); End
if node_type = 'empty' then // <b/>
begin // arr := array(('Size', 'sz', 15), ('Style', 'style', 'line'));
empty_name := children_[i]['attrEx'] ? children_[i]['attrEx'] : 'val'; Function AddAttr(arr); // 添加属性
if obj = 0 then arr['attributes'] := array(empty_name: 0); Begin
else if obj = 1 then arr['attributes'] := array(empty_name: 1) if not istable(arr) then return;
end ExtAttr union= arr;
else if node_type = 'pcdata' then return 1;
begin End
arr['children'] := array(('type': 'pcdata', 'value': obj));
end Function Marshal();
else if ifObj(obj) then Begin
begin children_ := nil;
marshal := obj.Marshal(); GetChildrenEx(); //优化为变量,减少数据COPY2022-12-10
if length(marshal['children'])=0 and length(marshal['attributes'])=0 then continue; child_arr := array();
arr['children'] := marshal['children']; name_map := array();
arr['attributes'] union= marshal['attributes']; len := 0;
end for i:=0 to length(children_)-1 do
else begin
begin node_type := children_[i]['nodeType'];
key := children_[i]['attrName'] ? children_[i]['attrName'] : children_[i]['attrEx'] ? children_[i]['attrEx'] : 'val'; obj := children_[i]['obj'];
arr['attributes'] := array(key : obj); if ifnil(obj) then continue;
end if not ifObj(obj) and not ifnil(name_map[children_[i]['name']]) and children_[i]['attrEx'] <> '' then
name_map[children_[i]['name']] := len; begin
child_arr[len++] := arr; child_arr[name_map[children_[i]['name']]]['attributes'] union=array(children_[i]['attrEx'] : obj);
end continue;
end
name_arr := str2array(NodeName, '/');
tmp_arr := array('type': 'element', 'name': name_arr[length(name_arr)-1], 'children': child_arr); arr := array('type': 'element', 'name': children_[i]['name'], 'attributes': array());
for i:=length(name_arr)-2 downto 0 do if node_type = 'empty' then // <b/>
begin begin
tmp_arr := array('type': 'element', 'name': name_arr[i], 'children': array(tmp_arr)); 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);
attrs_arr := GetAttrs(); end
tmp_arr['attributes'] := array(); else if node_type = 'pcdata' then
for i:=0 to length(attrs_arr)-1 do begin
begin arr['children'] := array(('type': 'pcdata', 'value': obj));
if not ifnil(attrs_arr[i, 2]) then Begin end
tmp_arr['attributes'][ attrs_arr[i, 1] ] := attrs_arr[i, 2]; else if ifObj(obj) then
End; begin
end marshal := obj.Marshal();
return tmp_arr; if length(marshal['children'])=0 and length(marshal['attributes'])=0 then continue;
End arr['children'] := marshal['children'];
arr['attributes'] union= marshal['attributes'];
Function NewChildNode(nodeArr); end
Begin else
if not ifarray(nodeArr) then return 0; begin
if not ifstring(nodeArr['name']) then return 0; key := children_[i]['attrName'] ? children_[i]['attrName'] : children_[i]['attrEx'] ? children_[i]['attrEx'] : 'val';
arr := array(( arr['attributes'] := array(key : obj);
'name': nodeArr['name'], end
'obj': nodeArr['obj'], name_map[children_[i]['name']] := len;
'attrEx': nodeArr['attrEx'], child_arr[len++] := arr;
'nodeType': nodeArr['nodeType'], end
));
ExtNodes union= arr; name_arr := str2array(NodeName, '/');
return 1; tmp_arr := array('type': 'element', 'name': name_arr[length(name_arr)-1], 'children': child_arr);
End for i:=length(name_arr)-2 downto 0 do
begin
Function Value(name, nottransferable); tmp_arr := array('type': 'element', 'name': name_arr[i], 'children': array(tmp_arr));
Begin end
if not ifObj(RootObj) then return nil;
if NodeUri <> '' then attrs_arr := GetAttrs();
node := class(TSXml).GetNode(RootObj, NodeUri); tmp_arr['attributes'] := array();
else for i:=0 to length(attrs_arr)-1 do
node := RootObj; begin
if not ifObj(node) then return nil; if not ifnil(attrs_arr[i, 2]) then Begin
tmp_arr['attributes'][ attrs_arr[i, 1] ] := attrs_arr[i, 2];
attrs := GetAttrsEx(); End;
lName := lowerCase(name); end
r := sselect * from attrs where lName = lowerCase([0]) end; return tmp_arr;
if istable(r) then End
begin
value := node.GetAttribute(r[1]); Function NewChildNode(nodeArr);
return nottransferable ? value : trystrtofloat(value, r) ? r : value; Begin
end if not ifarray(nodeArr) then return 0;
if not ifstring(nodeArr['name']) then return 0;
children := GetChildren(); arr := array((
r := select * from children where lName = lowerCase(['field']) end; 'name': nodeArr['name'],
if istable(r) then Begin 'obj': nodeArr['obj'],
r := r[0]; 'attrEx': nodeArr['attrEx'],
node := node.FirstChildElement(r['name']); 'nodeType': nodeArr['nodeType'],
if not ifObj(node) and r['nodeType'] = 'empty' then return false; ));
if not ifObj(node) then return nil; ExtNodes union= arr;
if r['nodeType'] = 'pcdata' then //返回文本串 return 1;
return node.GetText(); End
if ifObj(r['obj']) then //对象,返回XML串
return node.Data(); Function Value(name, nottransferable);
key := r['attrName'] ? r['attrName'] : r['attrEx'] ? r['attrEx'] : 'val'; Begin
value := node.GetAttribute(key); if not ifObj(RootObj) then return nil;
if r['nodeType'] = 'empty' and value = '' then return true; if NodeUri <> '' then
return nottransferable ? value : trystrtofloat(value, r) ? r : value; node := class(TSXml).GetNode(RootObj, NodeUri);
End; else
return nil; node := RootObj;
End; if not ifObj(node) then return nil;
Function Replace(hash, bChild); attrs := GetAttrsEx();
Begin lName := lowerCase(name);
if istable(hash) then Begin r := sselect * from attrs where lName = lowerCase([0]) end;
ReplaceArr := hash; if istable(r) then
replaceNodeName(); begin
if bChild then Begin value := node.GetAttribute(r[1]);
r := GetChildren(); return nottransferable ? value : trystrtofloat(value, r) ? r : value;
for i:=0 to length(r)-1 do Begin end
if ifObj(r[i]['obj']) then
r[i]['obj'].Replace(hash, bChild); children := GetChildren();
End; r := select * from children where lName = lowerCase(['field']) end;
End; if istable(r) then Begin
End; r := r[0];
End node := node.FirstChildElement(r['name']);
if not ifObj(node) and r['nodeType'] = 'empty' and not nottransferable then return false;
Function GetChildrenEx(); if not ifObj(node) then return nil;
Begin if r['nodeType'] = 'pcdata' then //返回文本串
if not ifarray(children_) then Begin return node.GetText();
children_ := getChildren(); if ifObj(r['obj']) then //对象,返回XML串
if not istable(ReplaceArr) then Begin return node.Data();
for i:=0 to length(children_)-1 do Begin key := r['attrName'] ? r['attrName'] : r['attrEx'] ? r['attrEx'] : 'val';
if ifarray(children_[i]['obj']) then Begin value := node.GetAttribute(key);
if istable(children_[i]['obj']) then if r['nodeType'] = 'empty' and value = '' then return true;
hasArr := 1; return nottransferable ? value : trystrtofloat(value, r) ? r : value;
else End;
children_[i]['obj'] := nil; return nil;
End; End;
End;
End; Function Replace(hash, bChild);
if hasArr or istable(ReplaceArr) then Begin Begin
a := array(); if istable(hash) then Begin
for i:=0 to length(children_)-1 do Begin ReplaceArr := hash;
if istable(ReplaceArr) then replaceNodeName();
children_[i]['name'] := ReplaceName(children_[i]['name']); if bChild then Begin
if istable(children_[i]['obj']) then Begin r := GetChildren();
a union= children_[i]['obj']; for i:=0 to length(r)-1 do Begin
End if ifObj(r[i]['obj']) then
else r[i]['obj'].Replace(hash, bChild);
a[ length(a) ] := children_[i]; End;
end; End;
children_ := a; End;
End; End
End;
End; Function GetChildrenEx();
Begin
Function GetAttrsEx(); if not ifarray(children_) then Begin
Begin children_ := getChildren();
return GetAttrs();//暂时没有发现需要更新属性前缀的情况 if not istable(ReplaceArr) then Begin
if not istable(ReplaceArr) then return GetAttrs(); for i:=0 to length(children_)-1 do Begin
attr := GetAttrs(); if ifarray(children_[i]['obj']) then Begin
for i:=0 to length(attr)-1 do if istable(children_[i]['obj']) then
attr[i][1] := ReplaceName(attr[i][1]); hasArr := 1;
return attr; else
End children_[i]['obj'] := nil;
End;
private End;
Function replaceNodeName(); End;
Begin if hasArr or istable(ReplaceArr) then Begin
for k, v in ReplaceArr do a := array();
begin for i:=0 to length(children_)-1 do Begin
NodeName := ReplaceStr(NodeName, k, v); if istable(ReplaceArr) then
end children_[i]['name'] := ReplaceName(children_[i]['name']);
End if istable(children_[i]['obj']) then Begin
a union= children_[i]['obj'];
Function ReplaceName(name); End
Begin else
for k,v in ReplaceArr do Begin a[ length(a) ] := children_[i];
if k='' then end;
name := v + name; children_ := a;
else End;
name := ReplaceStr(name, k, v); End;
End; End;
return name;
End; Function GetAttrsEx();
public Begin
NodeName; return GetAttrs();//暂时没有发现需要更新属性前缀的情况
ExtAttr; if not istable(ReplaceArr) then return GetAttrs();
ExtNodes; attr := GetAttrs();
ReplaceArr; for i:=0 to length(attr)-1 do
RootObj; // xml node attr[i][1] := ReplaceName(attr[i][1]);
NodeUri:string; return attr;
children_; End
End
private
Function replaceNodeName();
Begin
for k, v in ReplaceArr do
begin
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
+27
View File
@@ -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
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -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
+207 -206
View File
@@ -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
///idStyleID号(数字ID号或名称字符串) ///idStyleID号(数字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,可以是自定义名称
///xmlStrInnerXml串 ///xmlStrInnerXml串
///返回: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;
///插入新的段落样式 ///插入新的段落样式
///oTDocxStyle对象 ///oTDocxStyle对象
///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段落样式
///oTDocxStyle对象 ///插入新的LatentStyle段落样式
///返回TDocxStyle对象 ///oTDocxStyle对象
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;
+1 -1
View File
@@ -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;
+14 -4
View File
@@ -94,6 +94,16 @@ Type TTableContent = class
_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);
@@ -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();
@@ -284,7 +294,7 @@ Type TTableContent = class
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);
@@ -314,7 +324,7 @@ Type TTableContent = class
End; End;
End; End;
docx_; [weakref]docx_;
node_; node_;
impl_; impl_;
End; End;
@@ -20,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
+1 -1
View File
@@ -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_;
+6 -2
View File
@@ -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;
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -92,7 +92,7 @@ Type xlsxHyperLink = Class
End; End;
private private
file_; //TSExcelFile对象 [weakref]file_; //TSExcelFile对象
xmlFile_;//XmlFile对象 xmlFile_;//XmlFile对象
sheetName_; sheetName_;
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -113,7 +113,7 @@ private
private private
sheetName_:string; //sheet名称 sheetName_:string; //sheet名称
excel_;//TSExcelFile对象 [weakref]excel_;//TSExcelFile对象
zipfile_; zipfile_;
drawingXmlObj_; drawingXmlObj_;
End; End;
+1 -1
View File
@@ -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;
+126 -22
View File
@@ -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"日"
+1 -1
View File
@@ -126,7 +126,7 @@ private
private private
sheetName_:string; //sheet名称 sheetName_:string; //sheet名称
excel_;//TSExcelFile对象 [weakref]excel_;//TSExcelFile对象
zipfile_; zipfile_;
tableXmlFile_; tableXmlFile_;
End; End;
File diff suppressed because it is too large Load Diff
+839 -488
View File
File diff suppressed because it is too large Load Diff