From 8cd87118d5de0eb39aaa1deed28ec7dab9b17099 Mon Sep 17 00:00:00 2001 From: csh Date: Thu, 28 Sep 2023 16:22:33 +0800 Subject: [PATCH] v1.4.8-patch1 --- funcext/TSOffice/TOfficeObj.tsf | 72 ++++++++++----------- funcext/TSOffice/TSDocxFile.tsf | 2 +- funcext/TSOffice/document/TTableContent.tsf | 2 +- 3 files changed, 37 insertions(+), 39 deletions(-) diff --git a/funcext/TSOffice/TOfficeObj.tsf b/funcext/TSOffice/TOfficeObj.tsf index 242869a..06f357a 100644 --- a/funcext/TSOffice/TOfficeObj.tsf +++ b/funcext/TSOffice/TOfficeObj.tsf @@ -13921,7 +13921,7 @@ Type TDocumentBody = Class(DocObject) return array(length(errArr), tslTagCount, errArr); End; - Function GetHeadingListImpl(docx, posOpt, UpperHeadingLevel, LowerHeadingLevel, numIds, bHeadList); + Function GetHeadingListImpl(docx, posOpt, UpperHeadingLevel, LowerHeadingLevel, numIds); Begin r := array(); if ifObj(posOpt) then @@ -13933,45 +13933,43 @@ Type TDocumentBody = Class(DocObject) if name = 'w:p' and not ifObj(pNode.FirstChildElement('w:sectPr')) then begin p := new TParagraph(pNode); - //统计数字项目编号 - numArr := array(); - numId := getNumPr('numId', docx, p); - ilvl := getNumPr('Level', docx, p); - if not ilvl then ilvl := 0; - if ifarray(numIds) then Begin - if ilvl >= 0 and ilvl < 10 then Begin - if not istable(numIds[numId]) then - numIds[numId] := array(0,0,0,0,0,0,0,0,0,0); - prev := numIds[numId, ilvl]; - if prev then Begin - for i:=ilvl+1 to 9 do - numIds[numId, i] := 0; - End; - numIds[numId, ilvl]++; - numArr := numIds[numId]; - End; - End; - if bHeadList then Begin //统计大纲显示(目录) - styleId := p.Format.Value('StyleId', 1); - if styleId <> '' then Begin - obj := docx.StyleObject().GetStyleById(styleId); - if ifObj(obj) then Begin - level := getHeadingLevel(docx, obj); - iLevel := Class(TSXml).SafeStrToIntDef(level, -1); - if p.Text() <> "" and iLevel+1 >= UpperHeadingLevel and iLevel+1 <= LowerHeadingLevel then Begin - r[ind]['Level'] := strtoint(level); - r[ind]['Paragraph'] := p; - r[ind]['Text'] := p.Text(); - r[ind]['numId'] := ifnumber(numId) ? integer(numId) : 0; //数字项目编号 - r[ind]['ilvl'] := ilvl; //级别 - r[ind]['numArr'] := numArr; //累加数字编码 - ind++; + styleId := p.Format.Value('StyleId', 1); + if styleId <> '' and (obj := docx.StyleObject().GetStyleById(styleId)) and ifObj(obj) then + begin + level := getHeadingLevel(docx, obj); + iLevel := Class(TSXml).SafeStrToIntDef(level, -1); + if iLevel+1 >= UpperHeadingLevel and iLevel+1 <= LowerHeadingLevel then Begin + //统计数字项目编号 + text := p.Text(); + if text = "" then continue; + numArr := array(); + numId := getNumPr('numId', docx, p); + ilvl := getNumPr('Level', docx, p); + if not ilvl then ilvl := 0; + if ifarray(numIds) then Begin + if ilvl >= 0 and ilvl < 10 then Begin + if not istable(numIds[numId]) then + numIds[numId] := array(0,0,0,0,0,0,0,0,0,0); + prev := numIds[numId, ilvl]; + if prev then Begin + for i:=ilvl+1 to 9 do + numIds[numId, i] := 0; + End; + numIds[numId, ilvl]++; + numArr := numIds[numId]; End; End; + r[ind]['Level'] := strtoint(level); + r[ind]['Paragraph'] := p; + r[ind]['Text'] := text; + r[ind]['numId'] := ifnumber(numId) ? integer(numId) : 0; //数字项目编号 + r[ind]['ilvl'] := ilvl; //级别 + r[ind]['numArr'] := numArr; //累加数字编码 + ind++; End; - End; + end End - else if ifarray(numIds) and name = 'w:tbl' then Begin + else if false and ifarray(numIds) and name = 'w:tbl' then Begin tbl := TOfficeObj('TTable'); tbl.Init(pNode); rows := tbl.Rows(); @@ -13979,7 +13977,7 @@ Type TDocumentBody = Class(DocObject) for i:=1 to rows do Begin for j:=1 to cols do Begin cell := tbl.Cell(i, j); - if cell then [a, b] := cell.GetHeadingListImpl(docx, nil, UpperHeadingLevel, LowerHeadingLevel, numIds, false);//表格内递归查找,统计数字项目编号,但不显示在大纲中 + if cell then [a, b] := cell.GetHeadingListImpl(docx, nil, UpperHeadingLevel, LowerHeadingLevel, numIds);//表格内递归查找,统计数字项目编号,但不显示在大纲中 End; End; End; diff --git a/funcext/TSOffice/TSDocxFile.tsf b/funcext/TSOffice/TSDocxFile.tsf index 74fd793..0ab7e22 100644 --- a/funcext/TSOffice/TSDocxFile.tsf +++ b/funcext/TSOffice/TSDocxFile.tsf @@ -519,7 +519,7 @@ Type TSDocxFile = Class ///返回:array((("Level":level,"Paragraph":"object","Text":title)); Function GetHeadingList(UpperHeadingLevel, LowerHeadingLevel); Begin - return document_.Body().GetHeadingListImpl(self, nil, UpperHeadingLevel, LowerHeadingLevel, nil, true); + return document_.Body().GetHeadingListImpl(self, nil, UpperHeadingLevel, LowerHeadingLevel, nil); End; //返回Document对象 diff --git a/funcext/TSOffice/document/TTableContent.tsf b/funcext/TSOffice/document/TTableContent.tsf index 6c02810..897e39a 100644 --- a/funcext/TSOffice/document/TTableContent.tsf +++ b/funcext/TSOffice/document/TTableContent.tsf @@ -142,7 +142,7 @@ Type TTableContent = class Begin ///获取标题列表 array((("Level":level,"Paragraph":"object","Text":title,"numId":,"ilvl":,"numArr":)); numMap := array(); - r := docx_.Document().Body().GetHeadingListImpl(docx_, nil, UpperHeadingLevel, LowerHeadingLevel, numMap, true); + r := docx_.Document().Body().GetHeadingListImpl(docx_, nil, UpperHeadingLevel, LowerHeadingLevel, numMap); for i:=0 to length(r)-1 do Begin p := _AddItem(UpperHeadingLevel, LowerHeadingLevel, r[i]['Level'], i = 0 ? true: false); //fldCharType