Compare commits

...
16 Commits
Author SHA1 Message Date
csh 4a2961a635 Merge branch 'word' 2023-12-07 13:41:38 +08:00
csh 9f660c09f6 v1.5.2-patch1 2023-12-05 15:31:49 +08:00
csh 1e9b8f3a12 v1.5.2 2023-12-01 10:42:08 +08:00
csh b617f235fa v1.5.1 2023-11-15 10:51:24 +08:00
csh ee7b7164ce v1.5.0 2023-11-14 11:38:27 +08:00
csh aab0a498c6 v1.4.9-patch2 2023-10-19 14:47:21 +08:00
csh 5172a78e3e v1.4.9-patch1 2023-10-17 16:20:41 +08:00
csh de0af521bc v1.4.9 2023-10-16 17:35:16 +08:00
csh 8cd87118d5 v1.4.8-patch1 2023-09-28 16:22:33 +08:00
csh 9c917cfb70 v1.4.8 2023-09-27 14:50:53 +08:00
csh d72d88d68a v1.4.7 2023-09-22 09:42:31 +08:00
csh 5f1064794d v1.4.6-patch3 2023-09-21 09:22:15 +08:00
csh 493691b930 v1.4.6-patch2 2023-09-20 09:14:36 +08:00
csh f3094c148c v1.4.6-patch1 2023-09-19 17:00:37 +08:00
csh addc41144e v1.4.6 2023-09-19 10:10:29 +08:00
csh 8aa050461c v1.4.5 2023-08-30 15:43:03 +08:00
20 changed files with 2728 additions and 1196 deletions
+23 -23
View File
@@ -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,14 +34,14 @@ 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++);
@@ -65,15 +65,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 +108,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 +130,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 := utf8toansi("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);
Binary file not shown.
Binary file not shown.
Binary file not shown.
+4 -2
View File
@@ -12,17 +12,19 @@ TSOffice 项目:纯 TSL 代码实现 excel、word 文件读写
可选: 可选:
- `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
#### Ubuntu-18.04
根据架构选择aarch64或x86版本将对应文件夹内容进行部署 根据架构选择aarch64或x86版本将对应文件夹内容进行部署
- `liboffice_plugin` 放入 tsl 安装根目录下 Plugin 文件夹 - `liboffice_plugin` 放入 tsl 安装根目录下 Plugin 文件夹
## 帮助文档 ## 帮助文档
- [Excel 帮助文档](./ExcelFile使用帮助.xlsx) - [Excel 帮助文档](./XlsxFile使用帮助.xlsx)
- [Word 帮助文档](./DocxFile使用帮助.docx) - [Word 帮助文档](./DocxFile使用帮助.docx)
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large Load Diff
+45 -8
View File
@@ -1,4 +1,4 @@
// Version 1.4.4 // Version 1.5.2
Type TSDocxFile = Class Type TSDocxFile = Class
///Version: V1.0 2022-09-20 ///Version: V1.0 2022-09-20
@@ -124,6 +124,13 @@ Type TSDocxFile = Class
return document_.Body().Paragraphs(); return document_.Body().Paragraphs();
End; End;
///word文档最后一个段落
///返回:TParagraph对象
Function LastParagraph();
Begin
return document_.Body().LastParagraph();
End;
///添加新段落 ///添加新段落
///paragraph: TParagraph对象 ///paragraph: TParagraph对象
///posOpt: 段落位置,0 在DOCX文件开头;-1 文件尾;N 在第N段之后;XmlNode节点对象或DocObject对象 在posOpt之后新添加段落 ///posOpt: 段落位置,0 在DOCX文件开头;-1 文件尾;N 在第N段之后;XmlNode节点对象或DocObject对象 在posOpt之后新添加段落
@@ -230,10 +237,12 @@ Type TSDocxFile = Class
///插入数据表 ///插入数据表
///tbl: TTable对象 ///tbl: TTable对象
///posOpt: 段落位置,0 在DOCX文件开头;-1 文件尾;N 在第N段之后;XmlNode节点对象或DocObject对象 在posOpt之后新添加表格 ///posOpt: 段落位置,0 在DOCX文件开头;-1 文件尾;N 在第N段之后;XmlNode节点对象或DocObject对象 在posOpt之后新添加表格
///customCell: 二维数组,自定义指定单元格的样式
/// 如:一行一列arr[0][0] := array(twtcPr, twpPr, twrPr);其中twtcPr是twtcPr对象,twpPr是twpPr对象,twrPr是twrPr对象
///返回: TTable对象 ///返回: TTable对象
Function InsertTable(tbl, posOpt); Function InsertTable(tbl, posOpt, customCell);
Begin Begin
return document_.Body().InsertTable(tbl, getPosNode(posOpt)); return document_.Body().InsertTable(tbl, getPosNode(posOpt), customCell);
End; End;
///返回CoreProperties对象 ///返回CoreProperties对象
@@ -372,6 +381,25 @@ Type TSDocxFile = Class
return nil; return nil;
End; End;
///复制Word内容
///alias: string,文件目录别名
///fileName: string,文件名
///posOpt: 段落位置,0 在DOCX文件开头;-1 文件尾;N 在第N段之后;XmlNode节点对象或DocObject对象 在posOpt之后新添加图片
///返回: [err, TDocxCopy对象]
///TDocxCopy.GetCopiedTable() 返回复制的对象表格数组
///TDocxCopy.GetCopiedParagraph() 返回复制对象的段落数组
///TDocxCopy.GetCopiedDrawing() 返回复制对象的图表数组
Function InsertFile(alias, fileName, posOpt);overload;
Begin
docxObj := new TSDocxFile();
[err, msg] := docxObj.OpenFile(alias, fileName);
if err then return array(err, msg);
copy_obj := new TDocxCopy(self, docxObj);
copy_obj.Init();
copy_obj.Copy(posOpt);
return array(0, copy_obj);
End;
///复制Word内容 ///复制Word内容
///docxObj: TSDocxFile对象 ///docxObj: TSDocxFile对象
///posOpt: 段落位置,0 在DOCX文件开头;-1 文件尾;N 在第N段之后;XmlNode节点对象或DocObject对象 在posOpt之后新添加图片 ///posOpt: 段落位置,0 在DOCX文件开头;-1 文件尾;N 在第N段之后;XmlNode节点对象或DocObject对象 在posOpt之后新添加图片
@@ -379,11 +407,8 @@ Type TSDocxFile = Class
///TDocxCopy.GetCopiedTable() 返回复制的对象表格数组 ///TDocxCopy.GetCopiedTable() 返回复制的对象表格数组
///TDocxCopy.GetCopiedParagraph() 返回复制对象的段落数组 ///TDocxCopy.GetCopiedParagraph() 返回复制对象的段落数组
///TDocxCopy.GetCopiedDrawing() 返回复制对象的图表数组 ///TDocxCopy.GetCopiedDrawing() 返回复制对象的图表数组
Function InsertFile(alias, fileName, posOpt); Function InsertFile(docxObj, posOpt);overload;
Begin Begin
docxObj := new TSDocxFile();
[err, msg] := docxObj.OpenFile(alias, fileName);
if err then return array(err, msg);
copy_obj := new TDocxCopy(self, docxObj); copy_obj := new TDocxCopy(self, docxObj);
copy_obj.Init(); copy_obj.Init();
copy_obj.Copy(posOpt); copy_obj.Copy(posOpt);
@@ -510,7 +535,7 @@ Type TSDocxFile = Class
///返回:array((("Level":level,"Paragraph":"object","Text":title)); ///返回:array((("Level":level,"Paragraph":"object","Text":title));
Function GetHeadingList(UpperHeadingLevel, LowerHeadingLevel); Function GetHeadingList(UpperHeadingLevel, LowerHeadingLevel);
Begin Begin
return document_.Body().GetHeadingListImpl(self, nil, UpperHeadingLevel, LowerHeadingLevel, nil, true); return document_.Body().GetHeadingListImpl(self, nil, UpperHeadingLevel, LowerHeadingLevel, nil);
End; End;
//返回Document对象 //返回Document对象
@@ -535,6 +560,17 @@ Type TSDocxFile = Class
return numberingObj_; return numberingObj_;
End; End;
///返回:TFootnotes对象
Function FootNotesObject();
Begin
if not ifObj(footnotesObj_) then
begin
footnotesObj_ := new TOfficeObj('TFootnoteBody');
footnotesObj_.InitFootnotes(self.Zip());
end
return footnotesObj_;
End;
///执行word文档内嵌tsl代码(执行内嵌脚本的环境字符集为GBK) ///执行word文档内嵌tsl代码(执行内嵌脚本的环境字符集为GBK)
///返回:[err,tslFuncCount,errArr]: err 执行错误TSL代码段次数,tslFuncCount TSL代码段总数,errArr 执行TSL错误信息(array(('code':'代码', 'err':'错误信息')) ///返回:[err,tslFuncCount,errArr]: err 执行错误TSL代码段次数,tslFuncCount TSL代码段总数,errArr 执行TSL错误信息(array(('code':'代码', 'err':'错误信息'))
Function ExecInnerTSL(); Function ExecInnerTSL();
@@ -591,6 +627,7 @@ private
zipfile_; //压缩文件对象 zipfile_; //压缩文件对象
document_; //Document对象 document_; //Document对象
styleObj_; styleObj_;
footnotesObj_;
numberingObj_; numberingObj_;
DocPrId_; DocPrId_;
End; End;
+2 -2
View File
@@ -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));
+19 -25
View File
@@ -18,25 +18,31 @@ public
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; Function Delete();
Begin Begin
End if ifObj(RootObj) then
begin
curNode := class(TSXml).GetNode(RootObj, NodeUri);
if ifObj(curNode) then curNode.DeleteChildren();
end
End;
Function GetAttrs(); virtual; Function GetAttrs(); virtual;
Begin Begin
@@ -71,27 +77,16 @@ public
children_ := nil; children_ := nil;
GetChildrenEx(); //优化为变量,减少数据COPY2022-12-10 GetChildrenEx(); //优化为变量,减少数据COPY2022-12-10
child_arr := array(); child_arr := array();
name_map := array();
len := 0; len := 0;
for i:=0 to length(children_)-1 do for i:=0 to length(children_)-1 do
begin begin
node_type := children_[i]['nodeType']; node_type := children_[i]['nodeType'];
obj := children_[i]['obj']; obj := children_[i]['obj'];
if ifnil(obj) then continue; if ifnil(obj) then continue;
//find := select thisrowindex as "rowindex_", * from child_arr where ['name'] = children_[i]['name'] end; //优化为循环,性能提高15-20%2022-12-20 if not ifObj(obj) and not ifnil(name_map[children_[i]['name']]) and children_[i]['attrEx'] <> '' then
find := array();
for j:=length(child_arr)-1 downto 0 do Begin //支持列表模式(如多节点:<w:t xml:space=""></w:t>),查找最近的节点
if child_arr[j]['name'] = children_[i]['name'] then Begin
find[0] := child_arr[j];
find[0]['rowindex_'] := j;
break;
End;
End;
if not ifnil(obj) and not ifObj(obj) and istable(find) and ifstring(children_[i]['attrEx']) and children_[i]['attrEx'] <> '' then
begin begin
if not ifarray(find[0]['attributes']) then find[0]['attributes'] := array(); child_arr[name_map[children_[i]['name']]]['attributes'] union=array(children_[i]['attrEx'] : obj);
key := children_[i]['attrEx'];
find[0]['attributes'] union= array(key : obj);
child_arr[find[0]['rowindex_']]['attributes'] := find[0]['attributes'];
continue; continue;
end end
@@ -118,7 +113,7 @@ public
key := children_[i]['attrName'] ? children_[i]['attrName'] : children_[i]['attrEx'] ? children_[i]['attrEx'] : 'val'; key := children_[i]['attrName'] ? children_[i]['attrName'] : children_[i]['attrEx'] ? children_[i]['attrEx'] : 'val';
arr['attributes'] := array(key : obj); arr['attributes'] := array(key : obj);
end end
name_map[children_[i]['name']] := len;
child_arr[len++] := arr; child_arr[len++] := arr;
end end
@@ -154,7 +149,7 @@ public
return 1; return 1;
End End
Function Value(name); Function Value(name, nottransferable);
Begin Begin
if not ifObj(RootObj) then return nil; if not ifObj(RootObj) then return nil;
if NodeUri <> '' then if NodeUri <> '' then
@@ -169,7 +164,7 @@ public
if istable(r) then if istable(r) then
begin begin
value := node.GetAttribute(r[1]); value := node.GetAttribute(r[1]);
return trystrtofloat(value, r) ? r : value; return nottransferable ? value : trystrtofloat(value, r) ? r : value;
end end
children := GetChildren(); children := GetChildren();
@@ -186,7 +181,7 @@ public
key := r['attrName'] ? r['attrName'] : r['attrEx'] ? r['attrEx'] : 'val'; key := r['attrName'] ? r['attrName'] : r['attrEx'] ? r['attrEx'] : 'val';
value := node.GetAttribute(key); value := node.GetAttribute(key);
if r['nodeType'] = 'empty' and value = '' then return true; if r['nodeType'] = 'empty' and value = '' then return true;
return trystrtofloat(value, r) ? r : value; return nottransferable ? value : trystrtofloat(value, r) ? r : value;
End; End;
return nil; return nil;
End; End;
@@ -269,7 +264,6 @@ public
NodeName; NodeName;
ExtAttr; ExtAttr;
ExtNodes; ExtNodes;
//Parent;
ReplaceArr; ReplaceArr;
RootObj; // xml node RootObj; // xml node
NodeUri:string; NodeUri:string;
+5 -3
View File
@@ -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
+107 -12
View File
@@ -9,6 +9,7 @@ Type TDocxCopy = class
copy_drawing_ := array(); copy_drawing_ := array();
style_copy_obj_ := new TDocxStyleCopy(oldObj.StyleObject(), newObj.StyleObject()); style_copy_obj_ := new TDocxStyleCopy(oldObj.StyleObject(), newObj.StyleObject());
number_copy_obj_ := new TDocxNumberCopy(oldObj, newObj); number_copy_obj_ := new TDocxNumberCopy(oldObj, newObj);
footnote_copy_obj_ := new TDocxFootnoteCopy(oldObj, newObj);
End; End;
Function Init(); Function Init();
@@ -21,7 +22,7 @@ Type TDocxCopy = class
Function Copy(posOpt); Function Copy(posOpt);
Begin Begin
// 复制所有的样式 // 复制所有的样式
style_copy_obj_.CopyStyle(); style_copy_obj_.CopyStyle(number_copy_obj_);
parts := new_docx_obj_.Body().Parts(); parts := new_docx_obj_.Body().Parts();
pos := old_docx_obj_.GetPosNode(posOpt); pos := old_docx_obj_.GetPosNode(posOpt);
@@ -110,6 +111,7 @@ private
// 比较新文件的图片在旧文件中是否存在 // 比较新文件的图片在旧文件中是否存在
zip := old_docx_obj_.Zip(); zip := old_docx_obj_.Zip();
xml := zip.Get('word/_rels/document.xml.rels');
files := sselect ['FileName'] from zip.Files() where AnsiStartsText('word/media/image', ['FileName']) end; files := sselect ['FileName'] from zip.Files() where AnsiStartsText('word/media/image', ['FileName']) end;
for i:=0 to length(files)-1 do Begin for i:=0 to length(files)-1 do Begin
if zip.Diff(files[i], image_file) = 0 then Begin if zip.Diff(files[i], image_file) = 0 then Begin
@@ -117,7 +119,6 @@ private
[maxRid, imageFile, rid] := class(TSXml).FindRelationshipRid(xml, prefix); [maxRid, imageFile, rid] := class(TSXml).FindRelationshipRid(xml, prefix);
End; End;
End; End;
xml := zip.Get('word/_rels/document.xml.rels');
if rid = 0 then if rid = 0 then
begin begin
image_cnt := length(files) + 1; image_cnt := length(files) + 1;
@@ -131,9 +132,9 @@ private
zip.Add('word/' + image_path, image_file); zip.Add('word/' + image_path, image_file);
contentXml := zip.Get('[Content_Types].xml'); contentXml := zip.Get('[Content_Types].xml');
class(TSXml).AddDefaultContentType(contentXml, postfix, 'image/' $ postfix); class(TSXml).AddDefaultContentType(contentXml, postfix, 'image/' $ postfix);
end
end
node.SetAttribute('r:embed', 'rId' $ rid); node.SetAttribute('r:embed', 'rId' $ rid);
end
end
End; End;
Function SetChart(node); Function SetChart(node);
@@ -210,21 +211,64 @@ private
Function SetParagraphInfo(paragraph); Function SetParagraphInfo(paragraph);
Begin Begin
style := class(TSXml).GetNode(paragraph.node_, 'w:pPr/w:pStyle'); CopyStyle(paragraph.node_, 'w:pPr/w:pStyle');
CopyNumber(paragraph.node_, 'w:pPr/w:numPr/w:numId');
SetRunsInfo(paragraph.node_);
DeleteComment(paragraph); // 删除批注
End;
Function SetRunsInfo(node);
Begin
run := node.FirstChildElement('w:r');
while ifObj(run) do
begin
CopyFootnote(run);
CopyStyle(run, 'w:rPr/w:rStyle');
run := run.NextElement();
end
End;
Function CopyStyle(node, path);
Begin
style := class(TSXml).GetNode(node, path);
if ifObj(style) then if ifObj(style) then
begin begin
styleid := style.GetAttribute('w:val'); styleid := style.GetAttribute('w:val');
new_id := style_copy_obj_.GetStyleNewId(styleid); new_id := style_copy_obj_.GetStyleNewId(styleid);
if new_id then style.SetAttribute('w:val', new_id); if new_id then style.SetAttribute('w:val', new_id);
end end
numpr := class(TSXml).GetNode(paragraph.node_, 'w:pPr/w:numPr/w:numId'); End;
Function CopyNumber(node, path);
Begin
numpr := class(TSXml).GetNode(node, path);
if ifObj(numpr) then if ifObj(numpr) then
begin begin
id := numpr.GetAttribute('w:val'); id := numpr.GetAttribute('w:val');
numberid := number_copy_obj_.CopyNumbering(id); numberid := number_copy_obj_.CopyNumbering(id);
numpr.SetAttribute('w:val', id); numpr.SetAttribute('w:val', numberid);
end
End;
Function CopyFootnote(node);
Begin
footnote := node.FirstChildElement('w:footnoteReference');
if not ifObj(footnote) then return;
id := footnote.GetAttribute('w:id');
if id then
begin
obj := footnote_copy_obj_.CopyFootnote(id);
footnote.SetAttribute('w:id', obj.Id);
parts := obj.Parts();
for i:=0 to length(parts)-1 do
begin
case GetPartType(parts[i]) of
0: SetParagraphInfo(parts[i]);
1: SetDrawingInfo(parts[i]);
2: SetTableInfo(parts[i]);
end;
end
end end
DeleteComment(paragraph); // 删除批注
End; End;
Function SetTableInfo(table); Function SetTableInfo(table);
@@ -295,6 +339,7 @@ private
new_docx_obj_; new_docx_obj_;
style_copy_obj_; style_copy_obj_;
number_copy_obj_; number_copy_obj_;
footnote_copy_obj_;
copy_table_; copy_table_;
copy_paragraph_; copy_paragraph_;
@@ -326,11 +371,12 @@ Type TDocxStyleCopy = class
end end
End; End;
Function CopyStyle(); Function CopyStyle(numberobj);
Begin Begin
for id, obj in id_map_ do for id, obj in id_map_ do
begin begin
SetBasedOn(obj); SetBasedOn(obj);
SetNumId(obj, numberobj);
SetLink(obj); SetLink(obj);
old_style_obj_.CopyStyle(obj); old_style_obj_.CopyStyle(obj);
end; end;
@@ -382,11 +428,23 @@ private
end end
End; End;
Function SetNumId(obj, numberobj);
Begin
if not ifObj(numberobj) then return;
numPr := class(TSXml).GetNode(obj.node_, 'w:pPr/w:numPr/w:numId');
if ifObj(numPr) then
begin
id := numpr.GetAttribute('w:val');
numberid := numberobj.CopyNumbering(id);
numpr.SetAttribute('w:val', numberid);
end
End;
Function GetNewName(name); Function GetNewName(name);
Begin Begin
new_name := name; new_name := name;
count := 0; count := 0;
while ifObj(old_style_obj_.GetStyle(new_name)) or style_name_map2_[new_name] do while ifObj(old_style_obj_.GetStyle(class(TSXml).Utf8ToCurCodePage(new_name))) or style_name_map2_[new_name] do
new_name := new_name $ count++; new_name := new_name $ count++;
return new_name; return new_name;
End; End;
@@ -437,9 +495,9 @@ Type TDocxNumberCopy = class
begin begin
number_obj := old_number_obj_.CopyNumber(obj); number_obj := old_number_obj_.CopyNumber(obj);
id_map_[number] := number_obj; id_map_[number] := number_obj;
return number_obj;
end end
end; return id_map_[number];
end
End; End;
private private
@@ -448,3 +506,40 @@ private
id_map_; // [id: styleobj] id_map_; // [id: styleobj]
End; End;
Type TDocxFootnoteCopy = class
Function Create(oldObj, newObj);
Begin
footnotexml := newObj.Zip().Get('word/footnotes.xml');
if ifObj(footnotexml) then
begin
old_footnote_obj_ := oldObj.FootNotesObject();
new_footnote_obj_ := newObj.FootNotesObject();
end
else begin
old_footnote_obj_ := nil;
new_footnote_obj_ := nil;
end
id_map_ := array();
End;
Function CopyFootnote(id);
Begin
if ifObj(old_footnote_obj_) and ifObj(new_footnote_obj_) then
begin
if (obj := new_footnote_obj_.GetFootnote(id)) and not id_map_[id] then
begin
footnote_obj := old_footnote_obj_.CopyFootnote(obj);
id_map_[id] := footnote_obj;
end
return id_map_[id];
end
End;
private
old_footnote_obj_;
new_footnote_obj_;
id_map_; // [id: footnote]
End;
+25 -5
View File
@@ -142,7 +142,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 +160,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 +203,6 @@ Type TTableContent = class
r8.fldCharType := 'end'; r8.fldCharType := 'end';
_AddStdContent(p); _AddStdContent(p);
End; End;
p2 := TOfficeObj('TParagraph'); p2 := TOfficeObj('TParagraph');
@@ -221,6 +220,26 @@ Type TTableContent = class
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();
@@ -299,3 +318,4 @@ Type TTableContent = class
node_; node_;
impl_; impl_;
End; End;
+2 -1
View File
@@ -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;
@@ -29,7 +30,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;
+73 -60
View File
@@ -166,64 +166,71 @@ Type xlsxWorkBook = Class
Begin Begin
lname := LowerCase(sheet); lname := LowerCase(sheet);
if ifint(sheetIndexMap_[ lname ]) then return 'The sheet already exists.'; if ifint(sheetIndexMap_[ lname ]) then return 'The sheet already exists.';
rid := getWorkbookRelsRid();
fname := sheetPrefix_ $ inttostr(sheetsCount_ + 1) $ '.xml';
sheetId := addSheetN(fname);
rid := setWorkbookRels();
setWorkbookSheet(sheet, sheetId, rid);
setDocPropsApp(sheet);
setContentTypes(fname);
sheetNames_[sheetsCount_]['name'] := sheet;
sheetNames_[sheetsCount_]['sheetId'] := sheetId;
sheetNames_[sheetsCount_]['rid'] := rid;
sheetNames_[sheetsCount_]['file'] := fname;
sheetIndexMap_[ lname ] := sheetsCount_;
sheetsCount_ ++;
SetDefaultSheet(sheet);
End;
Function addSheetN(fname);
Begin
//添加文件xl/worksheets/sheetN.xml //添加文件xl/worksheets/sheetN.xml
sheetId := vselect maxof(['sheetId']) from sheetNames_ end; sheetId := vselect maxof(['sheetId']) from sheetNames_ end;
sheetId := integer(sheetId) + 1; sheetId := integer(sheetId) + 1;
fname := sheetPrefix_ $ inttostr(sheetsCount_ + 1) $ '.xml';
zipfile_.Add(fname, class(TSXml).XmlHeader() + class(TSXml).GetTemplate('sheet1')); zipfile_.Add(fname, class(TSXml).XmlHeader() + class(TSXml).GetTemplate('sheet1'));
return sheetId;
End;
Function setWorkbookRels();
Begin
rid := getWorkbookRelsRid();
//设置 workbook.xml.rels //设置 workbook.xml.rels
workbook_rels := GetXmlFileObj('xl/_rels/workbook.xml.rels'); workbook_rels := GetXmlFileObj('xl/_rels/workbook.xml.rels');
rels := workbook_rels.FirstChildElement('Relationships').InsertEndChild('element', 'Relationship'); rels := workbook_rels.FirstChildElement('Relationships').InsertEndChild('element', 'Relationship');
rels.SetAttribute('Target', getTarget( sheetsCount_ + 1)); rels.SetAttribute('Target', getTarget( sheetsCount_ + 1));
rels.SetAttribute('Type', class(TSXml).GetTemplate('RelationshipWorkSheet')); rels.SetAttribute('Type', class(TSXml).GetTemplate('RelationshipWorkSheet'));
rels.SetAttribute('Id', rid); rels.SetAttribute('Id', rid);
//workbook_rels.Print; return rid;
End;
Function setWorkbookSheet(sheetName, sheetId, rid);
Begin
//设置 xl/workbook.xml //设置 xl/workbook.xml
workbook := GetXmlFileObj('xl/workbook.xml'); workbook := GetXmlFileObj('xl/workbook.xml');
node := workbook.FirstChildElement('workbook').FirstChildElement('sheets').InsertEndChild('element','sheet'); node := workbook.FirstChildElement('workbook').FirstChildElement('sheets').InsertEndChild('element','sheet');
node.SetAttribute('name', sheet); node.SetAttribute('name', sheetName);
node.SetAttribute('sheetId', sheetId); node.SetAttribute('sheetId', sheetId);
node.SetAttribute('r:id', rid); node.SetAttribute('r:id', rid);
//workbook.Print(); End;
Function setDocPropsApp(sheet);
Begin
//设置docProps/app.xml //设置docProps/app.xml
app := GetXmlFileObj(class(TSXml).GetFileName('docProps_app')); app := GetXmlFileObj(class(TSXml).GetFileName('docProps_app'));
//app.Print(); vector := class(TSXml).GetNode(app, 'Properties/TitlesOfParts/vt:vector');
node := app.FirstChildElement('Properties').FirstChildElement('TitlesOfParts');
if not ifObj(node) then Begin
node := app.FirstChildElement('Properties').InsertEndChild('element','TitlesOfParts');
End;
vector := node.FirstChildElement('vt:vector');
if not ifObj(vector) then Begin
vector := node.InsertEndChild('element', 'vt:vector');
vector.SetAttribute('baseType', 'lpstr');
vector.SetAttribute('size', length(sheetNames_) + 1);
for i:=0 to length(sheetNames_)-1 do Begin
vector.InsertEndChild('element', 'vt:lpstr', sheetNames_[i]['name']);
End;
End
else
vector.SetAttribute('size', length(sheetNames_) + 1); vector.SetAttribute('size', length(sheetNames_) + 1);
vector.InsertEndChild('element', 'vt:lpstr', sheet); vector.InsertEndChild('element', 'vt:lpstr', sheet);
//app.Print(); End;
Function setContentTypes(fname);
Begin
//设置[Content_Types].xml //设置[Content_Types].xml
content_xml := GetXmlFileObj(class(TSXml).GetFileName('Content_Types')); content_xml := GetXmlFileObj(class(TSXml).GetFileName('Content_Types'));
class(TSXml).AddOverrideContentType(content_xml, '/' + fname, class(TSXml).GetTemplate('sheetContentType')); class(TSXml).AddOverrideContentType(content_xml, '/' + fname, class(TSXml).GetTemplate('sheetContentType'));
sheetNames_[sheetsCount_]['name'] := sheet;
sheetNames_[sheetsCount_]['sheetId'] := sheetId;
sheetNames_[sheetsCount_]['rid'] := rid;
sheetNames_[sheetsCount_]['file'] := fname;
sheetIndexMap_[ LowerCase(sheet) ] := sheetsCount_;
sheetsCount_ ++;
SetDefaultSheet(sheet);
End; End;
Function NewSheet(sourceSheet, destSheet);overload; Function NewSheet(sourceSheet, destSheet);overload;
Begin Begin
lname := LowerCase(destSheet); lname := LowerCase(destSheet);
@@ -512,15 +519,19 @@ Type xlsxWorkBook = Class
Function CopySheet(sourceSheet, destSheet); Function CopySheet(sourceSheet, destSheet);
Begin Begin
ind := sheetIndexMap_[ LowerCase(destSheet) ];
if ifint(ind) then return destSheet $ ' already exists.';
ind := sheetIndexMap_[ LowerCase(sourceSheet) ]; ind := sheetIndexMap_[ LowerCase(sourceSheet) ];
if not ifint(ind) then return sourceSheet $ ' does not exists.'; if not ifint(ind) then return sourceSheet $ ' does not exists.';
dest_ind := sheetIndexMap_[ LowerCase(destSheet) ];
//copy sheet //copy sheet
sheetId := vselect maxof(['sheetId']) from sheetNames_ end; if ifint(dest_ind) then
sheetId := integer(sheetId) + 1; begin
fname := sheetNames_[dest_ind]['file'];
zipfile_.Remove(fname);
end
else begin
fname := sheetPrefix_ $ inttostr(sheetsCount_ + 1) $ '.xml'; fname := sheetPrefix_ $ inttostr(sheetsCount_ + 1) $ '.xml';
end
sheet := GetSheetXmlFile(sourceSheet); sheet := GetSheetXmlFile(sourceSheet);
zipfile_.Add(fname, sheet.Data()); zipfile_.Add(fname, sheet.Data());
xml_file := GetXmlFileObj(fname); xml_file := GetXmlFileObj(fname);
@@ -549,7 +560,14 @@ Type xlsxWorkBook = Class
sheet_rels := GetSheetRelsFile(sourceSheet); sheet_rels := GetSheetRelsFile(sourceSheet);
if ifObj(sheet_rels) then if ifObj(sheet_rels) then
begin begin
if ifint(dest_ind) then
begin
rels_name := 'xl/worksheets/_rels/' + ExtractFileName(sheetNames_[dest_ind]['file']) + '.rels';
zipfile_.Remove(rels_name);
end
else begin
rels_name := 'xl/worksheets/_rels/' + 'sheet' + inttostr(sheetsCount_ + 1) + '.xml.rels'; rels_name := 'xl/worksheets/_rels/' + 'sheet' + inttostr(sheetsCount_ + 1) + '.xml.rels';
end
zipfile_.Add(rels_name, sheet_rels.Data()); zipfile_.Add(rels_name, sheet_rels.Data());
rels_file := GetXmlFileObj(rels_name); rels_file := GetXmlFileObj(rels_name);
relationship := rels_file.FirstChildElement('Relationships').FirstChildElement('Relationship'); relationship := rels_file.FirstChildElement('Relationships').FirstChildElement('Relationship');
@@ -576,6 +594,8 @@ Type xlsxWorkBook = Class
end end
end end
if ifint(dest_ind) then return;
//workbook.xml.rels //workbook.xml.rels
rid := getWorkbookRelsRid(); rid := getWorkbookRelsRid();
workbook_rels := GetXmlFileObj('xl/_rels/workbook.xml.rels'); workbook_rels := GetXmlFileObj('xl/_rels/workbook.xml.rels');
@@ -585,6 +605,8 @@ Type xlsxWorkBook = Class
rels.SetAttribute('Id', rid); rels.SetAttribute('Id', rid);
//xl/workbook.xml //xl/workbook.xml
sheetId := vselect maxof(['sheetId']) from sheetNames_ end;
sheetId := integer(sheetId) + 1;
workbook := GetXmlFileObj('xl/workbook.xml'); workbook := GetXmlFileObj('xl/workbook.xml');
node := workbook.FirstChildElement('workbook').FirstChildElement('sheets').InsertEndChild('element','sheet'); node := workbook.FirstChildElement('workbook').FirstChildElement('sheets').InsertEndChild('element','sheet');
node.SetAttribute('name', destSheet); node.SetAttribute('name', destSheet);
@@ -726,23 +748,25 @@ Type xlsxWorkBook = Class
Function SetSheetVisible(sheet, visible); Function SetSheetVisible(sheet, visible);
Begin Begin
workbook := GetXmlFileObj('xl/workbook.xml'); workbook := GetXmlFileObj('xl/workbook.xml');
node := workbook.FirstChildElement('workbook').FirstChildElement('sheets').FirstChildElement('sheet'); node := class(TSXml).GetNode(workbook, 'workbook/sheets/sheet');
hidden := visible = 1 ? 0 : 1; if GetSheetsCount() = 1 then return "Only one sheet, can't set visible.";
default_sheet_name := GetDefaultSheet(); sheet := lowercase(sheet);
if default_sheet_name = sheet then default_sheet_name := lowercase(GetDefaultSheet());
if default_sheet_name = sheet and not visible then
begin begin
ind := sheetIndexMap_[LowerCase(default_sheet_name)]; ind := sheetIndexMap_[LowerCase(default_sheet_name)];
if ind = 0 then default_name := sheetNames_[ind + 1]['name']; default_name := ind = 0 ? sheetNames_[1]['name'] : sheetNames_[ind - 1]['name'];
else default_name := sheetNames_[ind - 1]['name'];
SetDefaultSheet(default_name); SetDefaultSheet(default_name);
end end
if visible then SetDefaultSheet(sheet);
state := visible ? "nohidden" : "hidden";
while ifObj(node) do while ifObj(node) do
Begin Begin
name := node.GetAttribute('name'); name := lowercase(node.GetAttribute('name'));
if name = sheet then if name = sheet then
Begin Begin
if hidden then node.SetAttribute('state', 'hidden'); node.SetAttribute('state', state);
else node.DeleteAttribute('state'); break;
End End
node := node.NextElement(); node := node.NextElement();
End End
@@ -753,11 +777,12 @@ Type xlsxWorkBook = Class
Begin Begin
sheet_file := GetSheetXmlFile(sheet); sheet_file := GetSheetXmlFile(sheet);
if not ifObj(sheet_file) then return 0; if not ifObj(sheet_file) then return 0;
sheet := lowercase(sheet);
workbook := GetXmlFileObj('xl/workbook.xml'); workbook := GetXmlFileObj('xl/workbook.xml');
node := workbook.FirstChildElement('workbook').FirstChildElement('sheets').FirstChildElement('sheet'); node := class(TSXml).GetNode(workbook, 'workbook/sheets/sheet');
while ifObj(node) do while ifObj(node) do
Begin Begin
name := node.GetAttribute('name'); name := lowercase(node.GetAttribute('name'));
if name = sheet then if name = sheet then
Begin Begin
val := node.GetAttribute('state'); val := node.GetAttribute('state');
@@ -1104,29 +1129,17 @@ Type xlsxWorkBook = Class
node := sheet_node.InsertFirstChild('element', 'sheetView'); node := sheet_node.InsertFirstChild('element', 'sheetView');
node.SetAttribute('workbookViewId', 0); node.SetAttribute('workbookViewId', 0);
end end
if name = sheet then if lowercase(name) = lowercase(sheet) then
Begin Begin
node.SetAttribute('tabselected', 1); node.SetAttribute('tabSelected', 1);
workbook := GetXmlFileObj('xl/workbook.xml'); workbook := GetXmlFileObj('xl/workbook.xml');
workbook_node := workbook.FirstChildElement('workbook'); view_node := class(TSXml).GetNode(workbook, 'workbook/bookViews/workbookView');
book_view_node := workbook_node.FirstChildElement('bookViews');
if not ifObj(book_view_node) then
begin
prev_node := class(TSXml).GetWorkBookPrevNode(workbook_node, 'bookViews');
if not ifObj(prev_node) then book_view_node := workbook_node.InsertFirstChild('element', 'bookViews');
else book_view_node := workbook_node.InsertAfterChild(prev_node, 'element', 'bookViews');
end;
view_node := book_view_node.FirstChildElement('workbookView');
if not ifObj(view_node) then
begin
view_node := book_view_node.InsertFirstChild('element', 'workbookView');
end
view_node.SetAttribute('activeTab', ind); view_node.SetAttribute('activeTab', ind);
End End
else else
begin begin
node := root_node.FirstChildElement('sheetViews').FirstChildElement('sheetView'); node := root_node.FirstChildElement('sheetViews').FirstChildElement('sheetView');
node.SetAttribute('tabselected', 0); node.SetAttribute('tabSelected', 0);
end end
end end
End End
+109 -22
View File
@@ -1,5 +1,92 @@
# 更新日志 # 更新日志
## 2023-12-1
### V1.5.2
#### excel
1. 修复公式中文转码问题
## 2023-11-15
### V1.5.1
1. 支持识别图片中含有`0xffc2`段的jpg格式的大小
## 2023-11-14
### V1.5.0
#### word
1. 新增对脚注的支持,方法`TSDocxFile.FootnotesObject().Add`
2. `TSDocxFile.InsertFile`支持脚注插入
### excel
1. 升级`TSXlsxFile.CopySheet`
## 2023-10-16
### V1.4.9
#### word
1. 新增`TSDocxFile.InsertFile`重载方法
2. 新增`Table.SetStyle`方法
## 2023-9-27
### V1.4.8
#### word
1. 支持`Inserttable`时候加入对单元格样式的设置
2. 新增`TSDocxFile.LastParagraph`方法
3. 新增`TParagraph.PrevParagraph`方法
4. 性能优化
## 2023-9-22
### V1.4.7
#### word
1. 修复项目符号属于样式时,生成目录无法识别出项目符号问题
## 2023-9-19
### V1.4.6
#### word
1. 修复表格存在合并单元格,生成目录报错问题
2. 修复单元格添加 run 对象,设置样式不生效问题
3. 修复插入 word 后,中文样式重复问题
### excel
🔔 重要升级:`TSExcelFile`更名为`TSXlsxFile`,建议更改,旧名字现阶段仍可使用
1. 整理`NewSheet``SetSheetVisible`代码
#### excel
1. 修复`NewSheet`excel 打开遇到提示错误问题
## 2023-8-30
### V1.4.5
#### word
1. 支持生成目录后返回目录对象的所有段落内容`目录对象.Paragraphs()`
#### excel
1. 修复`NewSheet`excel 打开遇到提示错误问题
## 2023-8-28 ## 2023-8-28
### V1.4.4 ### V1.4.4
@@ -8,7 +95,7 @@
1. 修复`insertFile`样式错误问题 1. 修复`insertFile`样式错误问题
2. 修复`insertFile`后删除段落再新增段落位置错误问题 2. 修复`insertFile`后删除段落再新增段落位置错误问题
3. 修复生成目录中文编码未转换导致word打开失败问题 3. 修复生成目录中文编码未转换导致 word 打开失败问题
## 2023-8-22 ## 2023-8-22
@@ -24,7 +111,7 @@
#### word #### word
支持插入另一个word内容`InsertFile(alias, fileName, posOpt)` 支持插入另一个 word 内容`InsertFile(alias, fileName, posOpt)`
## 2023-8-11 ## 2023-8-11
@@ -32,7 +119,7 @@
#### word #### word
修复插入表格后,设置样式ID无法全部生效问题 修复插入表格后,设置样式 ID 无法全部生效问题
## 2023-8-10 ## 2023-8-10
@@ -40,7 +127,7 @@
#### word #### word
支持三级以内目录设置字体,一级目录样式ID为`TOC1`,二级目录样式ID为`TOC2`,三级为`TOC3`,通过样式设置相关属性即可修改目录字体 支持三级以内目录设置字体,一级目录样式 ID `TOC1`,二级目录样式 ID `TOC2`,三级为`TOC3`,通过样式设置相关属性即可修改目录字体
## 2023-8-7 ## 2023-8-7
@@ -48,7 +135,7 @@
#### word #### word
支持`AddHeading`时传入样式Id 支持`AddHeading`时传入样式 Id
## 2023-8-2 ## 2023-8-2
@@ -80,13 +167,13 @@
#### word #### word
段落字体大小设置调整,对齐VBA设置 段落字体大小设置调整,对齐 VBA 设置
## 2023-7-11 ## 2023-7-11
### V1.3.4 ### V1.3.4
修复加密Bug 修复加密 Bug
## 2023-7-4 ## 2023-7-4
@@ -98,11 +185,11 @@ word/excel 新增加密方法`SetPassword`,升级`OpenFile(alias, fileName, Pa
### V1.3.2 ### V1.3.2
修复.net使用rdo2执行失败问题,使用rdo2时候,需调用`TOfficeInit()`初始化 修复.net 使用 rdo2 执行失败问题,使用 rdo2 时候,需调用`TOfficeInit()`初始化
#### word #### word
1. 修复word模板`template.docx`执行失败问题 1. 修复 word 模板`template.docx`执行失败问题
## 2023-6-20 ## 2023-6-20
@@ -122,7 +209,7 @@ word/excel 新增加密方法`SetPassword`,升级`OpenFile(alias, fileName, Pa
#### excel #### excel
1. 支持excel程序设置字体样式粗体,斜体等此类问题的返回类型,如`style.Font.Bold`返回`true 或 false` 1. 支持 excel 程序设置字体样式粗体,斜体等此类问题的返回类型,如`style.Font.Bold`返回`true 或 false`
## 2023-4-4 ## 2023-4-4
@@ -138,7 +225,7 @@ word/excel 新增加密方法`SetPassword`,升级`OpenFile(alias, fileName, Pa
#### excel #### excel
1. 修复由.net客户端导出的excel兼容性问题,`SetColWidth``Set/GetDefaultSheet``SetSheetHeaderFooter` 1. 修复由.net 客户端导出的 excel 兼容性问题,`SetColWidth``Set/GetDefaultSheet``SetSheetHeaderFooter`
## 2023-3-23 ## 2023-3-23
@@ -207,7 +294,7 @@ word/excel 新增加密方法`SetPassword`,升级`OpenFile(alias, fileName, Pa
#### excel #### excel
1. Get相关方法重新Set后不再覆盖原有设置,影响方法如下`Set(Get)PageMargins`,`Set(Get)CellHyperLink`,`Set(Get)PageLayout`,`Set(Get)CalcOptions`,`Set(Get)DefaultFont`,`Set(Get)SheetViewOptions` 1. Get 相关方法重新 Set 后不再覆盖原有设置,影响方法如下`Set(Get)PageMargins`,`Set(Get)CellHyperLink`,`Set(Get)PageLayout`,`Set(Get)CalcOptions`,`Set(Get)DefaultFont`,`Set(Get)SheetViewOptions`
## 2023-2-23 ## 2023-2-23
@@ -244,7 +331,7 @@ word/excel 新增加密方法`SetPassword`,升级`OpenFile(alias, fileName, Pa
1. 新增`LoadFromMem`, `SavaToMem` 1. 新增`LoadFromMem`, `SavaToMem`
2. 新增重载方法`NewSheet` 2. 新增重载方法`NewSheet`
3. 新增`SetCalcOptions` 3. 新增`SetCalcOptions`
4. 修复删除sheet报错问题 4. 修复删除 sheet 报错问题
## 2023-2-13 ## 2023-2-13
@@ -280,7 +367,7 @@ word/excel 新增加密方法`SetPassword`,升级`OpenFile(alias, fileName, Pa
#### word #### word
1. 修复获取段落样式ID失败问题 1. 修复获取段落样式 ID 失败问题
2. 修复文本框添加图片失败问题 2. 修复文本框添加图片失败问题
#### excel #### excel
@@ -337,8 +424,8 @@ word/excel 新增加密方法`SetPassword`,升级`OpenFile(alias, fileName, Pa
#### word #### word
1. 新增ExecInnerTSl 1. 新增 ExecInnerTSl
2. 新增修改chart图(数据) 2. 新增修改 chart 图(数据)
3. 修复`TNumbering::AddStyleByInnerXml`错误 3. 修复`TNumbering::AddStyleByInnerXml`错误
4. 完善帮助文档 4. 完善帮助文档
@@ -356,11 +443,11 @@ word/excel 新增加密方法`SetPassword`,升级`OpenFile(alias, fileName, Pa
#### word #### word
1. 修复chart图兼容性问题 1. 修复 chart 图兼容性问题
### V1.0.6 ### V1.0.6
中文自动转换API由`class(xlsxXml).CodePage('中文');`调整为`TOfficeApi().CodePage('中文');` 中文自动转换 API `class(xlsxXml).CodePage('中文');`调整为`TOfficeApi().CodePage('中文');`
## 2023-1-5 ## 2023-1-5
@@ -370,15 +457,15 @@ word/excel 新增加密方法`SetPassword`,升级`OpenFile(alias, fileName, Pa
#### word #### word
1. 修复 Properties执行报错 1. 修复 Properties 执行报错
2. 修复格式刷 2. 修复格式刷
#### excel #### excel
1. 移除API `JoinCellName` 1. 移除 API `JoinCellName`
2. 修改`RGBToHSL``HSLToRGB`返回值 2. 修改`RGBToHSL``HSLToRGB`返回值
3. 修复获取超链接`GetCellHyperLink`失败问题 3. 修复获取超链接`GetCellHyperLink`失败问题
4. 修复一个对象新建文件,打开文件之后引发的xlsx文件错误问题 4. 修复一个对象新建文件,打开文件之后引发的 xlsx 文件错误问题
5. 修复`GetCoreProps`,`GetAppProps`失败问题 5. 修复`GetCoreProps`,`GetAppProps`失败问题
## 2022-12-30 ## 2022-12-30
@@ -398,4 +485,4 @@ word/excel 新增加密方法`SetPassword`,升级`OpenFile(alias, fileName, Pa
5. 修复`SetRowVisible``GetRowVisible``SetSheetVisible`问题 5. 修复`SetRowVisible``GetRowVisible``SetSheetVisible`问题
如何设置字符集(中文支持)? 如何设置字符集(中文支持)?
★用户的脚本可能是UFT8格式,或可能是GBK码格式,系统提供API自动设置当前字符集环境:`class(xlsxXml).CodePage('中文');` 在文件头设置该代码后,系统会自动检测当前的环境字符集 用户的脚本可能是 UFT8 格式,或可能是 GBK 码格式,系统提供 API 自动设置当前字符集环境:`class(xlsxXml).CodePage('中文');` 在文件头设置该代码后,系统会自动检测当前的环境字符集