From ced0d6b04c053f1193bd2915d72e05c53edb4901 Mon Sep 17 00:00:00 2001 From: csh Date: Wed, 26 Jul 2023 14:35:05 +0800 Subject: [PATCH] v1.3.7 --- funcext/TSOffice/TOfficeObj.tsf | 63 ++++++++++++++++++--------- funcext/TSOffice/TSDocxFile.tsf | 3 +- funcext/TSOffice/TSExcelFile.tsf | 4 +- funcext/TSOffice/TSUtils/NodeInfo.tsf | 8 ++-- 更新日志.md | 10 +++++ 5 files changed, 61 insertions(+), 27 deletions(-) diff --git a/funcext/TSOffice/TOfficeObj.tsf b/funcext/TSOffice/TOfficeObj.tsf index 3b8d3d8..ad0c39b 100644 --- a/funcext/TSOffice/TOfficeObj.tsf +++ b/funcext/TSOffice/TOfficeObj.tsf @@ -1,4 +1,4 @@ -// Version 1.3.6 +// Version 1.3.7 Function TOfficeObj(n); Begin @@ -14237,12 +14237,13 @@ Type TCell = Class(TDocumentBody, TWTc) Function Create(node);overload; Begin Class(TDocumentBody).Create(node); - Create(nil, 'w:tc'); + Create(node, 'w:tc'); End; Function Create(pNode, name);overload; Begin - Class(TWTc).Create(pNode, 'w:tc'); + Class(TWTc).Create(nil, 'w:tc'); + InitRootNode(pNode); name_ := 'w:tc'; mergeSpan_ := 0; pPr_ := new TwpPr(); @@ -14445,23 +14446,6 @@ Type TTable = Class(DocObject, TTableImpl) TblGrid.GridCol := gridArr; End; - Function RowHeight(row, height); - Begin - if row <= 0 or row > Rows() then return; - node := node_.FirstChildElement('w:tr'); - cnt := row - 1; - while(cnt) do - begin - node := node.NextElement('w:tr'); - cnt--; - end - trnode := node.FirstChildElement("w:trPr"); - if not ifObj(trnode) then trnode := node.InsertFirstChild('element', 'w:trPr'); - node := trnode.FirstChildElement('w:trHeight'); - if not ifObj(node) then node := trnode.InsertFirstChild('element', 'w:trHeight'); - node.SetAttribute('w:val', height); - End; - Property Format read readFormat; Function readFormat(); Begin @@ -14518,6 +14502,45 @@ Type TTable = Class(DocObject, TTableImpl) if n >0 and n <= length(TblGrid.GridCol) then TblGrid.GridCol[n-1]['obj'].W := wth; End; + + /// 设置行高 + Function RowHeight(row, height); + Begin + if row <= 0 or row > Rows() then return; + node := node_.FirstChildElement('w:tr'); + cnt := row - 1; + while(cnt) do + begin + node := node.NextElement('w:tr'); + cnt--; + end + trnode := node.FirstChildElement("w:trPr"); + if not ifObj(trnode) then trnode := node.InsertFirstChild('element', 'w:trPr'); + node := trnode.FirstChildElement('w:trHeight'); + if not ifObj(node) then node := trnode.InsertFirstChild('element', 'w:trHeight'); + node.SetAttribute('w:val', height); + End; + + Function Height(row); + Begin + if row <= 0 or row > Rows() then return nil; + node := node_.FirstChildElement('w:tr'); + cnt := row - 1; + while(cnt) do + begin + node := node.NextElement('w:tr'); + cnt--; + end + obj := new TwTr(); + obj.InitRootNode(node); + return obj.TrPr.Value('Height'); + End; + + Function Width(col); + Begin + obj := Cell(1, col); + return obj.Format.Value('Width'); + End; ///合并单元格 ///del: bool,是否删除其它单元格内容(只保留左上单元格内容) diff --git a/funcext/TSOffice/TSDocxFile.tsf b/funcext/TSOffice/TSDocxFile.tsf index 6a6c938..31b0f4b 100644 --- a/funcext/TSOffice/TSDocxFile.tsf +++ b/funcext/TSOffice/TSDocxFile.tsf @@ -1,4 +1,4 @@ -// Version 1.3.6 +// Version 1.3.7 Type TSDocxFile = Class ///Version: V1.0 2022-09-20 @@ -49,6 +49,7 @@ Type TSDocxFile = Class Function OpenFile(alias, fname, passwd); Begin if not ifObj(zipfile_) then return array(-1, 'Create ZipFile object fail.'); + if zipfile_.FilesCount() > 0 then zipfile_ := new ZipFile(); [err, errmsg] := zipfile_.Open(alias, fname, passwd); if err=0 then Begin document_ := new docxDocument(zipfile_); diff --git a/funcext/TSOffice/TSExcelFile.tsf b/funcext/TSOffice/TSExcelFile.tsf index c58d990..6286633 100644 --- a/funcext/TSOffice/TSExcelFile.tsf +++ b/funcext/TSOffice/TSExcelFile.tsf @@ -1,4 +1,4 @@ -// Version 1.3.6 +// Version 1.3.7 Type TSExcelFile = Class ///Version: V1.0 2022-08-08 @@ -49,8 +49,8 @@ Type TSExcelFile = Class ///返回: [err, errmsg] Function OpenFile(alias, fname, passwd); Begin - init(); if not ifObj(zipfile_) then return array(-1, 'Create ZipFile object fail.'); + if zipfile_.FilesCount() > 0 then zipfile_ := new ZipFile(); [err, errmsg] := zipfile_.Open(alias, fname, passwd); if err=0 then Begin workbook_ := new xlsxWorkBook(zipfile_); diff --git a/funcext/TSOffice/TSUtils/NodeInfo.tsf b/funcext/TSOffice/TSUtils/NodeInfo.tsf index f8a40e7..5febe3c 100644 --- a/funcext/TSOffice/TSUtils/NodeInfo.tsf +++ b/funcext/TSOffice/TSUtils/NodeInfo.tsf @@ -1,10 +1,10 @@ Type NodeInfo = class public - Function Create(p, name); + Function Create(parentObj, name); Begin - if ifObj(p) then - NodeUri := p.NodeUri = '' ? name : (p.NodeUri + '/' + name); + if ifObj(parentObj) then + NodeUri := parentObj.NodeUri = '' ? name : (parentObj.NodeUri + '/' + name); else NodeUri := ''; NodeName := name; @@ -270,7 +270,7 @@ public ExtNodes; //Parent; ReplaceArr; - RootObj; + RootObj; // xml node NodeUri:string; children_; End diff --git a/更新日志.md b/更新日志.md index a400f23..c98270f 100644 --- a/更新日志.md +++ b/更新日志.md @@ -1,5 +1,15 @@ # 更新日志 +## 2023-7-26 + +### V1.3.7 + +新增表格获取高度和宽度方法`table.Height(row) table.Width(col)` + +#### word + +新增对表格的行高设置`table.RowHeight(row, height)` + ## 2023-7-19 ### V1.3.6