From 2d423ca1fb153e319206b91e86ff13b2efa647c3 Mon Sep 17 00:00:00 2001 From: csh Date: Thu, 5 Dec 2024 16:37:20 +0800 Subject: [PATCH] v1.7.3 --- funcext/TSOffice/TOfficeObj.tsf | 4 +- funcext/TSOffice/TSDocxFile.tsf | 2 +- funcext/TSOffice/TSXlsxFile.tsf | 2 +- funcext/TSOffice/document/TDocxCopy.tsf | 53 +++++++++++++++++++++++++ 更新日志.md | 8 ++++ 5 files changed, 64 insertions(+), 5 deletions(-) diff --git a/funcext/TSOffice/TOfficeObj.tsf b/funcext/TSOffice/TOfficeObj.tsf index 3b144b5..7b5a415 100644 --- a/funcext/TSOffice/TOfficeObj.tsf +++ b/funcext/TSOffice/TOfficeObj.tsf @@ -1,4 +1,4 @@ -// Version 1.7.2 +// Version 1.7.3 Function TOfficeObj(n); Begin case lowercase(n) of @@ -14034,7 +14034,6 @@ Type TDocumentBody = Class(DocObject) end End else if TOfficeApi().Get('CELLFLAG') and ifarray(numIds) and name = 'w:tbl' then Begin - println("enter..."); tbl := TOfficeObj('TTable'); tbl.Init(pNode); rows := tbl.Rows(); @@ -14058,7 +14057,6 @@ Type TDocumentBody = Class(DocObject) End; pNode := pNode.NextElement(); End; - return r; End; diff --git a/funcext/TSOffice/TSDocxFile.tsf b/funcext/TSOffice/TSDocxFile.tsf index 49a842b..7823249 100644 --- a/funcext/TSOffice/TSDocxFile.tsf +++ b/funcext/TSOffice/TSDocxFile.tsf @@ -1,4 +1,4 @@ -// Version 1.7.2 +// Version 1.7.3 Type TSDocxFile = Class ///Version: V1.0 2022-09-20 ///适用于 Microsoft Word docx格式文件 diff --git a/funcext/TSOffice/TSXlsxFile.tsf b/funcext/TSOffice/TSXlsxFile.tsf index 58bf011..b5d69d1 100644 --- a/funcext/TSOffice/TSXlsxFile.tsf +++ b/funcext/TSOffice/TSXlsxFile.tsf @@ -1,4 +1,4 @@ -// Version 1.7.2 +// Version 1.7.3 Type TSXlsxFile = Class ///Version: V1.0 2022-08-08 ///适用于 Microsoft Excel? 2007 及以上版本创建的电子表格文档。支持 XLSX / XLSM / XLTM / XLTX 等多种文档格式。 diff --git a/funcext/TSOffice/document/TDocxCopy.tsf b/funcext/TSOffice/document/TDocxCopy.tsf index 6cdbd48..3b53dae 100644 --- a/funcext/TSOffice/document/TDocxCopy.tsf +++ b/funcext/TSOffice/document/TDocxCopy.tsf @@ -101,6 +101,56 @@ private end End; + Function SetRObject(node); + Begin + image_data_node := class(TSXml).GetNode(node, 'v:shape/v:imagedata'); + if not ifObj(node) then return; + rid := image_data_node.GetAttribute('r:id'); + id := CopyRidContent(rid, 'media/image', 'image'); + if id then image_data_node.SetAttribute('r:id', 'rId' $ id); + ole_node := class(TSXml).GetNode(node, 'o:OLEObject'); + if not ifObj(node) then return; + rid := ole_node.GetAttribute('r:id'); + id := CopyRidContent(rid, 'embeddings/oleObject', 'oleObject'); + if id then ole_node.SetAttribute('r:id', 'rId' $ id); + End; + + function CopyRidContent(id, tar_prefix, type_postfix); + begin + rels := new_docx_obj_.Zip().Get('word/_rels/document.xml.rels'); + target := class(TSXml).FindRelationshipTarget(rels, id); + image_file := new_docx_obj_.Zip().Get('word/' $ target).Data(); + + // 比较新文件的图片在旧文件中是否存在 + zip := old_docx_obj_.Zip(); + xml := zip.Get('word/_rels/document.xml.rels'); + files := sselect ['FileName'] from zip.Files() where AnsiStartsText('word/' $ tar_prefix, ['FileName']) end; + for i:=0 to length(files)-1 do Begin + if zip.Diff(files[i], image_file) = 0 then Begin + prefix := ReplaceStr(files[i], 'word/', ''); + [maxRid, imageFile, rid] := class(TSXml).FindRelationshipRid(xml, prefix); + End; + End; + if rid = 0 then + begin + image_cnt := length(files) + 1; + if ParseRegExpr("\\w+$", target, "", result, Mpos, Mlen) then + begin + postfix := result[0][0]; + image_path := tar_prefix $ image_cnt $ '.' $ postfix; + [rid, tar] := class(TSXml).FindRelationshipRid(xml, ''); + rid ++; + class(TSXml).AddRelationshipRid(xml, image_path, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/' $ type_postfix, 'rId' $ rid); + zip.Add('word/' + image_path, image_file); + contentXml := zip.Get('[Content_Types].xml'); + if postfix = 'wmf' then content_type := 'image/x-wmf'; + else if postfix = 'bin' then content_type := 'application/vnd.openxmlformats-officedocument.oleObject'; + class(TSXml).AddDefaultContentType(contentXml, postfix, content_type); + end + end + return rid; + end; + Function SetPic(node); Begin // 获取新文件的图片 @@ -224,6 +274,9 @@ private begin CopyFootnote(run); CopyStyle(run, 'w:rPr/w:rStyle'); + obj_node := class(TSXml).GetNode(run, 'w:object'); + if ifObj(obj_node) then + SetRObject(obj_node); run := run.NextElement(); end End; diff --git a/更新日志.md b/更新日志.md index 0388387..0a767b6 100644 --- a/更新日志.md +++ b/更新日志.md @@ -1,5 +1,13 @@ # 更新日志 +## 2024-12-05 + +### V1.7.3 + +#### word + +1. `insertfile`支持ole对象的插入,如wmf公式,excel表格 + ## 2024-12-04 ### V1.7.2