From 4dc02530ba4dc3d50d3acfc44c3da9df696dda5c Mon Sep 17 00:00:00 2001 From: csh Date: Tue, 16 May 2023 16:49:34 +0800 Subject: [PATCH 1/7] init `word_templat` --- funcext/TSOffice/TOfficeObj.tsf | 166 +++++++++--------- funcext/TSOffice/TSDocxFile.tsf | 1 + funcext/TSOffice/TSUtils/TOfficeApi.tsf | 5 + funcext/TSOffice/word/_ExcelChartCopyPic.tsf | 3 + .../word/_WordAddOleObjectFromFile.tsf | 3 + funcext/TSOffice/word/_WordBr.tsf | 5 + funcext/TSOffice/word/_WordCopyFromExcel.tsf | 34 ++++ .../TSOffice/word/_WordCopyPicFromExcel.tsf | 3 + .../TSOffice/word/_WordGetCurrentDocument.tsf | 4 + .../TSOffice/word/_WordGetCurrentRange.tsf | 4 + funcext/TSOffice/word/_WordGetFont.tsf | 10 ++ funcext/TSOffice/word/_WordGetLastRange.tsf | 4 + funcext/TSOffice/word/_WordGetLastShape.tsf | 16 ++ funcext/TSOffice/word/_WordGetLastTable.tsf | 4 + .../word/_WordGetLastTableCellProp.tsf | 12 ++ .../TSOffice/word/_WordGetLastTableProp.tsf | 11 ++ funcext/TSOffice/word/_WordGetRangeProp.tsf | 3 + funcext/TSOffice/word/_WordLastTableMerge.tsf | 11 ++ funcext/TSOffice/word/_WordLastTableSplit.tsf | 3 + .../TSOffice/word/_WordSetCurrnetRange.tsf | 4 + funcext/TSOffice/word/_WordSetFont.tsf | 8 + .../word/_WordSetLastTableCellProp.tsf | 17 ++ .../TSOffice/word/_WordSetLastTableProp.tsf | 18 ++ funcext/TSOffice/word/_WordSetRangeProp.tsf | 5 + funcext/TSOffice/word/_WordTemplate.tsf | 10 ++ funcext/TSOffice/word/_WordWrite.tsf | 17 ++ .../TSOffice/word/_WordWritePicFromFile.tsf | 11 ++ funcext/TSOffice/word/_WordWriteTable.tsf | 8 + funcext/TSOffice/word/_wordCompTable.tsf | 10 ++ funcext/TSOffice/word/create.tsf | 26 +++ 30 files changed, 353 insertions(+), 83 deletions(-) create mode 100644 funcext/TSOffice/word/_ExcelChartCopyPic.tsf create mode 100644 funcext/TSOffice/word/_WordAddOleObjectFromFile.tsf create mode 100644 funcext/TSOffice/word/_WordBr.tsf create mode 100644 funcext/TSOffice/word/_WordCopyFromExcel.tsf create mode 100644 funcext/TSOffice/word/_WordCopyPicFromExcel.tsf create mode 100644 funcext/TSOffice/word/_WordGetCurrentDocument.tsf create mode 100644 funcext/TSOffice/word/_WordGetCurrentRange.tsf create mode 100644 funcext/TSOffice/word/_WordGetFont.tsf create mode 100644 funcext/TSOffice/word/_WordGetLastRange.tsf create mode 100644 funcext/TSOffice/word/_WordGetLastShape.tsf create mode 100644 funcext/TSOffice/word/_WordGetLastTable.tsf create mode 100644 funcext/TSOffice/word/_WordGetLastTableCellProp.tsf create mode 100644 funcext/TSOffice/word/_WordGetLastTableProp.tsf create mode 100644 funcext/TSOffice/word/_WordGetRangeProp.tsf create mode 100644 funcext/TSOffice/word/_WordLastTableMerge.tsf create mode 100644 funcext/TSOffice/word/_WordLastTableSplit.tsf create mode 100644 funcext/TSOffice/word/_WordSetCurrnetRange.tsf create mode 100644 funcext/TSOffice/word/_WordSetFont.tsf create mode 100644 funcext/TSOffice/word/_WordSetLastTableCellProp.tsf create mode 100644 funcext/TSOffice/word/_WordSetLastTableProp.tsf create mode 100644 funcext/TSOffice/word/_WordSetRangeProp.tsf create mode 100644 funcext/TSOffice/word/_WordTemplate.tsf create mode 100644 funcext/TSOffice/word/_WordWrite.tsf create mode 100644 funcext/TSOffice/word/_WordWritePicFromFile.tsf create mode 100644 funcext/TSOffice/word/_WordWriteTable.tsf create mode 100644 funcext/TSOffice/word/_wordCompTable.tsf create mode 100644 funcext/TSOffice/word/create.tsf diff --git a/funcext/TSOffice/TOfficeObj.tsf b/funcext/TSOffice/TOfficeObj.tsf index 1e5edfa..3767698 100644 --- a/funcext/TSOffice/TOfficeObj.tsf +++ b/funcext/TSOffice/TOfficeObj.tsf @@ -9933,7 +9933,7 @@ type TProtect=class(NodeInfo) Function GetAttrs(); override; Begin HandleAttrs(); - return array(("Sheet", "sheet", Sheet, ""),("EditObjects", "objects", EditObjects, ""),("EditScenarios", "scenarios", EditScenarios, ""),("FormatCells", "formatCells", FormatCells, ""),("FormatColumns", "formatColumns", FormatColumns, ""),("FormatRows", "formatRows", FormatRows, ""),("InsertColumns", "insertColumns", InsertColumns, ""),("InsertRows", "insertRows", InsertRows, ""),("InsertHyperlinks", "insertHyperlinks", InsertHyperlinks, ""),("DeleteColumns", "deleteColumns", DeleteColumns, ""),("DeleteRows", "deleteRows", DeleteRows, ""),("SelectLockedCells", "selectLockedCells", SelectLockedCells, ""),("Sort", "sort", Sort, ""),("AutoFilter", "autoFilter", AutoFilter, ""),("PivotTables", "pivotTables", PivotTables, ""),("SelectUnLockedCells", "selectUnlockedCells", SelectUnLockedCells, "")) union ExtAttr; + return array(("Password", "password", Password, ""),("AlgorithmName", "algorithmName", AlgorithmName, ""),("HashValue", "hashValue", HashValue, ""),("SaltValue", "saltValue", SaltValue, ""),("SpinCount", "spinCount", SpinCount, ""),("Sheet", "sheet", Sheet, ""),("EditObjects", "objects", EditObjects, ""),("EditScenarios", "scenarios", EditScenarios, ""),("FormatCells", "formatCells", FormatCells, ""),("FormatColumns", "formatColumns", FormatColumns, ""),("FormatRows", "formatRows", FormatRows, ""),("InsertColumns", "insertColumns", InsertColumns, ""),("InsertRows", "insertRows", InsertRows, ""),("InsertHyperlinks", "insertHyperlinks", InsertHyperlinks, ""),("DeleteColumns", "deleteColumns", DeleteColumns, ""),("DeleteRows", "deleteRows", DeleteRows, ""),("SelectLockedCells", "selectLockedCells", SelectLockedCells, ""),("Sort", "sort", Sort, ""),("AutoFilter", "autoFilter", AutoFilter, ""),("PivotTables", "pivotTables", PivotTables, ""),("SelectUnLockedCells", "selectUnlockedCells", SelectUnLockedCells, "")) union ExtAttr; End; Function GetChildren(); override; @@ -9943,6 +9943,11 @@ type TProtect=class(NodeInfo) End; //Attributes + Password; + AlgorithmName; + HashValue; + SaltValue; + SpinCount; Sheet; EditObjects; EditScenarios; @@ -11323,20 +11328,22 @@ Type TPicture = Class(DocObject, TPictureImpl) ETU := 360045;//1cm单位 maxX := 17.0;//水平方向17cm maxY := 23.0;//垂直方向23cm + imageW := image.Width() / 28.346 * ETU; + imageH := image.Height() / 28.346 * ETU; if Width <= 0 and Height <= 0 then Begin //图像缺省大小 - widthVal := image.Width(); - heightVal := image.Height(); + widthVal := imageW; + heightVal := imageH; End else Begin //用户设置了图片尺寸 widthVal := ETU * Width; heightVal := ETU * Height; - if Width <= 0 and image.Height() and image.Width() then Begin //按照图片比例自动缩放 - scaling_factor := image.Width() / image.Height(); + if Width <= 0 and imageH and imageW then Begin //按照图片比例自动缩放 + scaling_factor := imageW / imageH; widthVal := round(heightVal * scaling_factor); End; - if Height <= 0 and image.Height() and image.Width() then Begin //按照图片比例自动缩放 - scaling_factor := image.Width() / image.Height(); + if Height <= 0 and imageH and imageW then Begin //按照图片比例自动缩放 + scaling_factor := imageW / imageH; heightVal := round(widthVal / scaling_factor); End; End; @@ -11361,7 +11368,7 @@ Type TPicture = Class(DocObject, TPictureImpl) heightVal *= ratio; widthVal *= ratio; End; - //println('w={}-{},maxx={}, h={}-{},maxh={},ratio={}',integer(image.Width()),integer(widthVal),15 * ETU, integer(image.Height()),integer(heightVal),23 * ETU,ratio); + //println('w={}-{},maxx={}, h={}-{},maxh={},ratio={}',integer(imageW),integer(widthVal),15 * ETU, integer(imageH),integer(heightVal),23 * ETU,ratio); return array(integer(widthVal), integer(heightVal)); End; @@ -12946,6 +12953,7 @@ Type TDocumentBody = Class(DocObject) Function InsertTable(tbl, posOpt); Begin addPart(posOpt, tbl); + TOfficeApi().Set('CurrentTable', tbl.node_); tblBorders := class(TSXml).GetNode(tbl.node_, 'w:tblPr/w:tblBorders'); tblCellMar := class(TSXml).GetNode(tbl.node_, 'w:tblPr/w:tblCellMar'); if ifObj(tblBorders) or ifObj(tblCellMar) then Begin @@ -13107,6 +13115,7 @@ Type TDocumentBody = Class(DocObject) p := new TPicture(picture.node_); _set_lastParagraph_(posOpt, picture.node_); + TOfficeApi().Set('CurrentShape', picture.node_); return p; End; @@ -13268,8 +13277,9 @@ Type TDocumentBody = Class(DocObject) begParagraphIndex := -1; begPos := 0; begTxtLen := 0; - for i:=0 to length(tArr)-1 do Begin + while i < length(tArr) do Begin txt := ''; + iStep := 1; if ifObj(tArr[i]['rNode']) then Begin run := new TRun(tArr[i]['rNode']); txt := run.Text(); @@ -13342,7 +13352,8 @@ Type TDocumentBody = Class(DocObject) flag := '[TSL]'; '[TSL][/TSL': if c = ']' then Begin - curParagraphNode := tslArr[0]['pNode']; + tslBegParagraphNode := tslArr[0]['pNode']; + tslEndParagraphNode := tArr[i]['pNode']; ind := length(tslArr) - 1; if tslArr[ind]['pIndex'] <> tArr[i]['pIndex'] or tslArr[ind]['rIndex'] <> tArr[i]['rIndex'] then Begin ind ++; @@ -13359,7 +13370,7 @@ Type TDocumentBody = Class(DocObject) oldNode := prevRun; tArr[i]['rNode'] := run._duplicate_r(oldNode); run._adjust_r(tArr[i]['rNode'], wz, txtLen); - i--; + iStep := 0; End; curRunNode := tslArr[0]['rNode']; curRun := new TRun(curRunNode); @@ -13382,84 +13393,68 @@ Type TDocumentBody = Class(DocObject) code := leftstr(code, lengthW(code) - 5 - endPos); CodePage := TOfficeApi().Get('CodePage'); TOfficeApi().Set('Docx', docx); - TOfficeApi().Set('CurrentParagraph', curParagraphNode); + TOfficeApi().Set('CurrentParagraph', tslBegParagraphNode); + TOfficeApi().Set('CurrentPosition', tslBegParagraphNode); TOfficeApi().Set('CurrentRun', curRunNode); TOfficeApi().Set('CodePage', 'gbk'); try tslFuncCount ++; + println('run code=[{}]', code); if code <> '' then - str := eval(&code); + eval(&code); except println('run code={},err={}', code, ExceptObject.ErrInfo); errArr[ length(errArr) ] := array('code':code, 'err':ExceptObject.ErrInfo); - str := ''; End; tNode := curRun.node_.FirstChildElement('w:t'); if not ifObj(tNode) then Begin //没有在外部插入文字 - if not ifstring(str) or str = '' then Begin //删除w:r - curParagraphNode.DeleteChild(curRunNode); - hasrNode := curParagraphNode.FirstChildElement('w:r'); - if not ifObj(hasrNode) then Begin//删除空段落 - curParagraphNode.Parent().DeleteChild(curParagraphNode); - curParagraphNode := nil; - End; - End - else Begin - str := AnsiToUTF8(str); - lines := str2array(str, '\r\n'); - lineCnt := length(lines); - if lineCnt = 1 then Begin //单行 - curRun.SetText(str, true); + tslBegParagraphNode.DeleteChild(curRunNode); + //兼容WordTemplate函数,不删除空段落(TSL脚本段落) + //hasrNode := tslBegParagraphNode.FirstChildElement('w:r'); + //if not ifObj(hasrNode) then Begin//删除空段落 + // tslBegParagraphNode.Parent().DeleteChild(tslBegParagraphNode); + // tslBegParagraphNode := nil; + //End; + End; + //段落炸裂 + curPosotion := TOfficeApi().Get('CurrentPosition'); + if i+iStep < length(tArr) and tArr[i+iStep]['pNode'] = tslEndParagraphNode and tslBegParagraphNode <> curPosotion then Begin + data := tslEndParagraphNode.Marshal(); + NewParagraphNode := tslEndParagraphNode.Parent().InsertAfterChild(curPosotion, data[0]);//复制段落 + rmvArr := array(); + cnt := 0; + curLine := 0; + prevRNode := tArr[i+iStep]['rNode'].PrevElement('w:r'); + while ifObj(prevRNode) do Begin + curLine ++; + prevRNode := prevRNode.PrevElement('w:r'); + End; + rmvN := 0; + nextRNode := tArr[i+iStep]['rNode']; + while ifObj(nextRNode) do Begin + rmvArr[rmvN++] := nextRNode; + nextRNode := nextRNode.NextElement('w:r'); + End; + rNode := NewParagraphNode.FirstChildElement('w:r'); + nI := 0; + rIndex := 0; + while ifObj(rNode) do Begin + cnt ++; + if cnt <= curLine then Begin + rmvArr[rmvN++] := rNode; End - else Begin //多行 - curRun.SetText(lines[0], true); - nextRun := curRun.node_.NextElement('w:r'); - if ifObj(nextRun) then Begin //段落炸裂 - curLine := 0; - prevRNode := curRunNode; - while ifObj(prevRNode) do Begin - curLine ++; - prevRNode := prevRNode.PrevElement('w:r'); - End; - data := curParagraphNode.Marshal(); - LastParagraphNode := curParagraphNode.Parent().InsertAfterChild(curParagraphNode, data[0]);//复制段落 - rmvArr := array(); - cnt := 0; - rNode := LastParagraphNode.FirstChildElement('w:r'); - while ifObj(rNode) do Begin - cnt ++; - if cnt < curLine then - rmvArr[rmvN++] := rNode; - else if cnt = curLine then Begin - rNode.ClearText(); - rNode.SetText(lines[lineCnt-1], true); - lineCnt--; - End; - rNode := rNode.NextElement('w:r'); - End; - cnt := 0; - rNode := curParagraphNode.FirstChildElement('w:r'); - while ifObj(rNode) do Begin - cnt ++; - if cnt > curLine then - rmvArr[rmvN++] := rNode; - rNode := rNode.NextElement('w:r'); - End; - //删除重复的run - for rmvN := 0 to rmvN < length(rmvArr)-1 do begin - rmvArr[rmvN].Parent().DeleteChild(rmvArr[rmvN]); - End; - End;//段落炸裂 - curParagraph := new TParagraph(curParagraphNode); - prev := curParagraph; - for nP:=1 to lineCnt - 1 do Begin //新段落 - if lines[nP]='' then continue; - p := new TParagraph(); - p.Run.SetText(lines[nP], true); - prev := docx.AddParagraph(p, prev.Node()); - docx.CopyFormat(curParagraph, prev);//格式刷 - End; + else Begin + tArr[i+iStep+nI]['pNode'] := NewParagraphNode; + tArr[i+iStep+nI]['rNode'] := rNode; + tArr[i+iStep+nI]['rIndex'] := rIndex++; + nr := new TRun(tArr[i+iStep+nI]['rNode']); + nI ++; End; + rNode := rNode.NextElement('w:r'); + End; + //删除重复的run + for rmvN := 0 to length(rmvArr)-1 do begin + rmvArr[rmvN].Parent().DeleteChild(rmvArr[rmvN]); End; End; TOfficeApi().Set('CodePage', CodePage); @@ -13467,7 +13462,7 @@ Type TDocumentBody = Class(DocObject) flag := ''; code := nil; tslArr := array(); - continue; + break; End else flag := '[TSL]'; @@ -13492,6 +13487,7 @@ Type TDocumentBody = Class(DocObject) if tslArr[ind]['pIndex'] <> tArr[i]['pIndex'] or tslArr[ind]['rIndex'] <> tArr[i]['rIndex'] then tslArr[ind + 1] := tArr[i]; End; + i += iStep; End; return array(length(errArr), tslFuncCount, errArr); End; @@ -13625,6 +13621,7 @@ Type TDocumentBody = Class(DocObject) else Begin raise 'Invalid input param.'; End; + TOfficeApi().Set('CurrentPosition', o.node_); End; Function findNode(posOpt, b); @@ -14131,25 +14128,28 @@ Type TTable = Class(DocObject, TTableImpl) ///设置表格数据 ///data: table,数据表 - ///[IncludeHeader: bool] 是否包括表头,默认FALSE - ///[IncludeIndex: bool] 是否自动添加索引号,默认FALSE - Function SetData(docx, data, IncludeHeader, IncludeIndex); + ///[includeHeader: bool] 是否包括表头,默认FALSE + ///[includeIndex: bool] 是否自动添加索引号,默认FALSE + Function SetData(docx, data, includeHeader, includeIndex); Begin if not IsTable(data) then raise "Invalid Data."; + [rowcount,colcount] := mSize(data);//一维数组 + if colcount = 0 then + data := array(data); fields := FieldNames(data); if IsTable(fields) then Begin r := nils(length(data),length(fields)); r[:,:] := data; data := r; End; - if IncludeIndex then Begin + if includeIndex then Begin n := length(data)-1; r := array(0->n); data := `r | data; End; - if IncludeHeader and IsTable(fields) then Begin - if IncludeIndex then + if includeHeader and IsTable(fields) then Begin + if includeIndex then fields := array("Index") union fields; data := array(fields) union data; End; diff --git a/funcext/TSOffice/TSDocxFile.tsf b/funcext/TSOffice/TSDocxFile.tsf index b8d8b1f..03f15c0 100644 --- a/funcext/TSOffice/TSDocxFile.tsf +++ b/funcext/TSOffice/TSDocxFile.tsf @@ -271,6 +271,7 @@ Type TSDocxFile = Class p := AddParagraph(p, getPosNode(posOpt), nil); chart.pNode := p.node_; p.Node().InsertEndChild(o.GetInnerXml()); + TOfficeApi().Set('CurrentShape', p.node_); return chart; End; diff --git a/funcext/TSOffice/TSUtils/TOfficeApi.tsf b/funcext/TSOffice/TSUtils/TOfficeApi.tsf index 048ca70..3811999 100644 --- a/funcext/TSOffice/TSUtils/TOfficeApi.tsf +++ b/funcext/TSOffice/TSUtils/TOfficeApi.tsf @@ -73,6 +73,11 @@ Type TOffice = Class hash_['Paragraph-Node-' + name] := hash_['CurrentParagraph']; End; + Function GetCurrentPosition() + Begin + return hash_['CurrentPosition']; + End; + ///获取当前TSL代码段所在段落 ///返回:TParagraph对象 Function GetCurrentParagraph(); diff --git a/funcext/TSOffice/word/_ExcelChartCopyPic.tsf b/funcext/TSOffice/word/_ExcelChartCopyPic.tsf new file mode 100644 index 0000000..a7446f9 --- /dev/null +++ b/funcext/TSOffice/word/_ExcelChartCopyPic.tsf @@ -0,0 +1,3 @@ +Function _ExcelChartCopyPic(excelFileName, excelSheetName, picType); +Begin +End; \ No newline at end of file diff --git a/funcext/TSOffice/word/_WordAddOleObjectFromFile.tsf b/funcext/TSOffice/word/_WordAddOleObjectFromFile.tsf new file mode 100644 index 0000000..7843725 --- /dev/null +++ b/funcext/TSOffice/word/_WordAddOleObjectFromFile.tsf @@ -0,0 +1,3 @@ +Function _WordAddOleObjectFromFile(fileName, width, height); +Begin +End; \ No newline at end of file diff --git a/funcext/TSOffice/word/_WordBr.tsf b/funcext/TSOffice/word/_WordBr.tsf new file mode 100644 index 0000000..162c79b --- /dev/null +++ b/funcext/TSOffice/word/_WordBr.tsf @@ -0,0 +1,5 @@ +Function _WordBr(); +Begin + TOfficeApi().GetDocument().AddLineBreak(TOfficeApi().Get('CurrentPosition')); +End; + diff --git a/funcext/TSOffice/word/_WordCopyFromExcel.tsf b/funcext/TSOffice/word/_WordCopyFromExcel.tsf new file mode 100644 index 0000000..c910872 --- /dev/null +++ b/funcext/TSOffice/word/_WordCopyFromExcel.tsf @@ -0,0 +1,34 @@ +Function _WordCopyFromExcel(excelFileName, excelSheetName, startRow, startCol, endRow, endCol); +Begin + excel := new TSExcelFile(); + [err, msg] := excel.OpenFile('', excelFileName); + if err then return false; + total_row := excel.TotalRows(excelSheetName); + total_col := excel.TotalCols(excelSheetName); + if not total_row or not total_col then return false; + if ifnil(startRow) then + startRow := 1; + if ifnil(startCol) then + startCol := 1; + if ifnil(endRow) then + endRow := total_row; + if ifnil(endCol) then + endCol := total_col; + data := excel.GetTable(excelSheetName, + CoordinatesToCellName(startCol, startRow), + CoordinatesToCellName(endCol, endRow), + false, + false, + false); + if length(data) = 0 then return false; + //println('data={}',data); + docx := TOfficeApi().GetDocument(); + tbl := docx.CreateTable(data, false, false); + tbl.Format.Borders.Top.Val := 'dashed'; + tbl.Format.Borders.Left.Val := 'dashed'; + tbl.Format.Borders.Bottom.Val := 'dashed'; + tbl.Format.Borders.Right.Val := 'dashed'; + tbl.Format.Borders.InsideH.Val := 'dashed'; + tbl.Format.Borders.InsideV.Val := 'dashed'; + tbl := docx.InsertTable(tbl, TOfficeApi().GetCurrentPosition()); +End; diff --git a/funcext/TSOffice/word/_WordCopyPicFromExcel.tsf b/funcext/TSOffice/word/_WordCopyPicFromExcel.tsf new file mode 100644 index 0000000..80a9ab1 --- /dev/null +++ b/funcext/TSOffice/word/_WordCopyPicFromExcel.tsf @@ -0,0 +1,3 @@ +Function _WordCopyPicFormatExcel(excelFileName, excelSheetName, startRow, startCol, endRow, endCol, picType); +Begin +End; \ No newline at end of file diff --git a/funcext/TSOffice/word/_WordGetCurrentDocument.tsf b/funcext/TSOffice/word/_WordGetCurrentDocument.tsf new file mode 100644 index 0000000..2de32b1 --- /dev/null +++ b/funcext/TSOffice/word/_WordGetCurrentDocument.tsf @@ -0,0 +1,4 @@ +Function _WordGetCurrentDocument(); +Begin + return TOfficeApi().GetDocument(); +End; \ No newline at end of file diff --git a/funcext/TSOffice/word/_WordGetCurrentRange.tsf b/funcext/TSOffice/word/_WordGetCurrentRange.tsf new file mode 100644 index 0000000..8503ae5 --- /dev/null +++ b/funcext/TSOffice/word/_WordGetCurrentRange.tsf @@ -0,0 +1,4 @@ +Function _WordGetCurrentRange(); +Begin + return TOfficeApi().GetCurrentPosition(); +End; \ No newline at end of file diff --git a/funcext/TSOffice/word/_WordGetFont.tsf b/funcext/TSOffice/word/_WordGetFont.tsf new file mode 100644 index 0000000..e495c26 --- /dev/null +++ b/funcext/TSOffice/word/_WordGetFont.tsf @@ -0,0 +1,10 @@ +Function _WordGetFont(prop, value); +Begin + crun := TOfficeApi().GetCurrentRun(); + node := crun.Node().FirstChildElement('w:rPr'); + rPr := TOfficeObj('TwrPr'); + rPr.InitRootNode(node); + value := rPr.Value(prop); + if not ifnil(value) then return true; + return false; +End; diff --git a/funcext/TSOffice/word/_WordGetLastRange.tsf b/funcext/TSOffice/word/_WordGetLastRange.tsf new file mode 100644 index 0000000..2daa3e5 --- /dev/null +++ b/funcext/TSOffice/word/_WordGetLastRange.tsf @@ -0,0 +1,4 @@ +Function _WordGetLastRange(); +Begin + return TOfficeApi().GetCurrentPosition(); +End; \ No newline at end of file diff --git a/funcext/TSOffice/word/_WordGetLastShape.tsf b/funcext/TSOffice/word/_WordGetLastShape.tsf new file mode 100644 index 0000000..ea5ab59 --- /dev/null +++ b/funcext/TSOffice/word/_WordGetLastShape.tsf @@ -0,0 +1,16 @@ +Function _WordGetLastShape(); +Begin + node := TOfficeApi().Get('CurrentShape'); + if not ifObj(node) then return nil; + uri := 'w:r/w:drawing/wp:inline/a:graphic/a:graphicData/c:chart'; + cNode := class(TSXml).GetNode(node, uri); + if ifObj(cNode) then Begin + chart := TOfficeObj('TChart'); + chart.Init(TOfficeApi().GetDocument(), node, cNode); + return chart; + End; + + pic := TOfficeObj('TPicture'); + pic.Init(node); + return pic; +End; \ No newline at end of file diff --git a/funcext/TSOffice/word/_WordGetLastTable.tsf b/funcext/TSOffice/word/_WordGetLastTable.tsf new file mode 100644 index 0000000..cb268cc --- /dev/null +++ b/funcext/TSOffice/word/_WordGetLastTable.tsf @@ -0,0 +1,4 @@ +Function _WordGetLastTable(); +Begin + return TOfficeApi().Get('LastTable'); +End; \ No newline at end of file diff --git a/funcext/TSOffice/word/_WordGetLastTableCellProp.tsf b/funcext/TSOffice/word/_WordGetLastTableCellProp.tsf new file mode 100644 index 0000000..7a5df00 --- /dev/null +++ b/funcext/TSOffice/word/_WordGetLastTableCellProp.tsf @@ -0,0 +1,12 @@ +Function _WordGetLastTableCellProp(row, col, name, value); +Begin + table := TOfficeApi().Get('LastTable'); + if ifnil(table) then return false; + table_cell := table.Cell(row, col); + ctr := _wordCompTable(); + name_ := ctr[lowercase(name)]; + if ifnil(name_) then name_ := name; + str := 'return table_cell.Format.' $ name_ $ '"' $ value $ '"'; + value := eval(&str); + return true; +End; diff --git a/funcext/TSOffice/word/_WordGetLastTableProp.tsf b/funcext/TSOffice/word/_WordGetLastTableProp.tsf new file mode 100644 index 0000000..46b0520 --- /dev/null +++ b/funcext/TSOffice/word/_WordGetLastTableProp.tsf @@ -0,0 +1,11 @@ +Function _WordGetLastTableProp(name, value); +Begin + table := TOfficeApi().Get('LastTable'); + if ifnil(table) then return false; + ctr := _wordCompTable(); + name_ := ctr[lowercase(name)]; + if ifnil(name_) then name_ := name; + str := 'return table.Format.' $ name_ $ '"' $ value $ '"'; + value := eval(&str); + return true; +End; diff --git a/funcext/TSOffice/word/_WordGetRangeProp.tsf b/funcext/TSOffice/word/_WordGetRangeProp.tsf new file mode 100644 index 0000000..40dc9a8 --- /dev/null +++ b/funcext/TSOffice/word/_WordGetRangeProp.tsf @@ -0,0 +1,3 @@ +Function _WordGetRangeProp(name, value); +Begin +End; \ No newline at end of file diff --git a/funcext/TSOffice/word/_WordLastTableMerge.tsf b/funcext/TSOffice/word/_WordLastTableMerge.tsf new file mode 100644 index 0000000..a7abd34 --- /dev/null +++ b/funcext/TSOffice/word/_WordLastTableMerge.tsf @@ -0,0 +1,11 @@ +Function _WordLastTableMerge(row1, col1, row2, col2); +Begin + table := TOfficeApi().Get('LastTable'); + if ifnil(table) then return false; + [err1, beg_cell] := CoordinatesToCellName(col1, row1); + [err2, end_cell] := CoordinatesToCellName(col2, row2); + if err1 or err2 then return false; + table.Merge(beg_cell, end_cell, false); + TOfficeApi().Set('LastTable', table); + return true; +End; diff --git a/funcext/TSOffice/word/_WordLastTableSplit.tsf b/funcext/TSOffice/word/_WordLastTableSplit.tsf new file mode 100644 index 0000000..ca6dd90 --- /dev/null +++ b/funcext/TSOffice/word/_WordLastTableSplit.tsf @@ -0,0 +1,3 @@ +Function _WordLastTableSplit(row, col, rCnt, cCnt); +Begin +End; diff --git a/funcext/TSOffice/word/_WordSetCurrnetRange.tsf b/funcext/TSOffice/word/_WordSetCurrnetRange.tsf new file mode 100644 index 0000000..73678f5 --- /dev/null +++ b/funcext/TSOffice/word/_WordSetCurrnetRange.tsf @@ -0,0 +1,4 @@ +Function _WordSetCurrnetRange(range); +Begin + TOfficeApi().Set('CurrentPosition', range); +End; \ No newline at end of file diff --git a/funcext/TSOffice/word/_WordSetFont.tsf b/funcext/TSOffice/word/_WordSetFont.tsf new file mode 100644 index 0000000..c22bbe1 --- /dev/null +++ b/funcext/TSOffice/word/_WordSetFont.tsf @@ -0,0 +1,8 @@ +Function _WordSetFont(prop, value); +Begin + run := TOfficeApi().GetCurrentRun(); + str := 'run.font.' $ prop $ ' := ' $ '"' $ value $ '"'; + eval(&str); + run.Apply(); + return true; +End; diff --git a/funcext/TSOffice/word/_WordSetLastTableCellProp.tsf b/funcext/TSOffice/word/_WordSetLastTableCellProp.tsf new file mode 100644 index 0000000..3fbe9ac --- /dev/null +++ b/funcext/TSOffice/word/_WordSetLastTableCellProp.tsf @@ -0,0 +1,17 @@ +Function _WordSetLastTableCellProp(row, col, name, value); +Begin + table := TOfficeApi().Get('LastTable'); + if ifnil(table) then return false; + table_cell := table.Cell(row, col); + ctr := _wordCompTable(); + name_ := ctr[lowercase(name)]; + if ifnil(name_) then name_ := name; + str := 'table_cell.Format.' $ name_ $ ' := '; + if ifstring(value) then + str += '"' $ value $ '"'; + else + str = str $ value; + eval(&str); + TOfficeApi().Set('LastTable', table); + return true; +End; diff --git a/funcext/TSOffice/word/_WordSetLastTableProp.tsf b/funcext/TSOffice/word/_WordSetLastTableProp.tsf new file mode 100644 index 0000000..3afd055 --- /dev/null +++ b/funcext/TSOffice/word/_WordSetLastTableProp.tsf @@ -0,0 +1,18 @@ +Function _WordSetLastTableProp(name, value); +Begin + table := TOfficeApi().Get('LastTable'); + if ifnil(table) then return false; + ctr := _wordCompTable(); + name_ := ctr[lowercase(name)]; + if ifnil(name_) then name_ := name; + str := 'table.Format.' $ name_ $ ' := '; + if ifstring(value) then + str += '"' $ value $ '"'; + else + str = str $ value; + println("str = {}", str); + eval(&str); + TOfficeApi().Set('LastTable', table); + return true; +End; + diff --git a/funcext/TSOffice/word/_WordSetRangeProp.tsf b/funcext/TSOffice/word/_WordSetRangeProp.tsf new file mode 100644 index 0000000..e382cc1 --- /dev/null +++ b/funcext/TSOffice/word/_WordSetRangeProp.tsf @@ -0,0 +1,5 @@ +Function _WordSetRangeProp(name, value); +Begin + cur := TOfficeApi().GetCurrentPosition(); + if ifnil(cur) then return nil; +End; diff --git a/funcext/TSOffice/word/_WordTemplate.tsf b/funcext/TSOffice/word/_WordTemplate.tsf new file mode 100644 index 0000000..6cb8ca1 --- /dev/null +++ b/funcext/TSOffice/word/_WordTemplate.tsf @@ -0,0 +1,10 @@ +Function _WordTemplate(alias, fileName); +Begin + docx := new TSDocxFile(); + [err, msg] := docx.OpenFile(alias, fileName); + if err then return false; + docx.ExecInnerTSL(); + [err, msg] := docx.Save(); + if err then return false; + return true; +End; diff --git a/funcext/TSOffice/word/_WordWrite.tsf b/funcext/TSOffice/word/_WordWrite.tsf new file mode 100644 index 0000000..d515d57 --- /dev/null +++ b/funcext/TSOffice/word/_WordWrite.tsf @@ -0,0 +1,17 @@ +Function _WordWrite(); +Begin + docx := TOfficeApi().GetDocument(); + curParagraph := TOfficeApi().GetCurrentParagraph(); + curRun := TOfficeApi().GetCurrentRun(); + for i:=1 to PARAMCOUNT do Begin + argv := params[i]; + if ifstring( argv ) then + curRun.AddText( argv ); + else if ifnumber(argv) then + curRun.AddText('' $ argv); + else if ifarray(argv) then Begin + tbl := docx.CreateTable(argv, false, false); + tbl := docx.InsertTable(tbl, TOfficeApi().GetCurrentPosition()); + End + End +End; \ No newline at end of file diff --git a/funcext/TSOffice/word/_WordWritePicFromFile.tsf b/funcext/TSOffice/word/_WordWritePicFromFile.tsf new file mode 100644 index 0000000..1620f76 --- /dev/null +++ b/funcext/TSOffice/word/_WordWritePicFromFile.tsf @@ -0,0 +1,11 @@ +Function _WordWritePicFromFile(fileName); +Begin + file_size := fileSize('', fileName); + flag := readfile(rwbinary(), '', fileName, 0, file_size, data); + if not flag then return false; + picture := TOfficeObj('TPicture'); + picture.Image := data; + docx := TOfficeApi().GetDocument(); + docx.AddPicture(picture, TOfficeApi().GetCurrentPosition()); + return true; +End; diff --git a/funcext/TSOffice/word/_WordWriteTable.tsf b/funcext/TSOffice/word/_WordWriteTable.tsf new file mode 100644 index 0000000..4cf3581 --- /dev/null +++ b/funcext/TSOffice/word/_WordWriteTable.tsf @@ -0,0 +1,8 @@ +Function _WordWriteTable(table, writeIntIndex, writeIntTitle, incIntIndex); +Begin + docx := TOfficeApi().GetDocument(); + tbl := docx.CreateTable(table, true, writeIntIndex); + table := docx.InsertTable(tbl, TOfficeApi().GetCurrentPosition()); + TOfficeApi().Set('LastTable', table); + return true; +End; diff --git a/funcext/TSOffice/word/_wordCompTable.tsf b/funcext/TSOffice/word/_wordCompTable.tsf new file mode 100644 index 0000000..b58a7ea --- /dev/null +++ b/funcext/TSOffice/word/_wordCompTable.tsf @@ -0,0 +1,10 @@ +Function _wordCompTable(); +Begin + return array( + 'alignment': 'Alignment', + 'shadingcolor': 'Shading.Color', + 'style': 'StyleID', + 'verticalalignment': 'Valign', + 'width': 'Width', + ); +End; diff --git a/funcext/TSOffice/word/create.tsf b/funcext/TSOffice/word/create.tsf new file mode 100644 index 0000000..7af5431 --- /dev/null +++ b/funcext/TSOffice/word/create.tsf @@ -0,0 +1,26 @@ +_WordTemplate(alias, fileName); +_WordCopyFromExcel(excelFileName, excelSheetName, startRow, startCol, endRow, endCol); +_WordCopyPicFromExcel(excelFileName, excelSheetName, startRow, startCol, endRow, endCol, picType); +_ExcelChartCopyPic(excelFileName, excelSheetName, picType); +_WordGetCurrentDocument(); +_WordGetCurrentRange(); +_WordSetCurrnetRange(range); +_WordGetLastRange(); +_WordGetLastTable(); +_WordGetLastShape(); +_WordWrite(); +_WordBr(); +_WordWriteTable(table, writeIntIndex, writeIntTile, incIntIndex); +_WordWritePicFromFile(fileName); +_WordSetFont(prop, value); +_WordGetFont(prop, value); +_WordAddOleObjectFromFile(fileName, width, height); +_WordLastTableSplit(row, col, rCnt, cCnt); +_WordLastTableMerge(row1, col1, row2, col2); +_WordSetRangeProp(name, value); +_WordGetRangeProp(name, value); +_WordSetLastTableProp(name, value); +_WordGetLastTableProp(name, value); +_WordSetLastTableCellProp(row, col, name, value); +_WordGetLastTableCellProp(row, col, name, value); + From c536c4d53154ca482f0ee8da1684f057f855c455 Mon Sep 17 00:00:00 2001 From: csh Date: Wed, 17 May 2023 13:57:13 +0800 Subject: [PATCH 2/7] =?UTF-8?q?excel=20=20`gettable`=E4=B8=AD=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- funcext/TSOffice/worksheet/xlsxWorkBook.tsf | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/funcext/TSOffice/worksheet/xlsxWorkBook.tsf b/funcext/TSOffice/worksheet/xlsxWorkBook.tsf index a1ee763..a73540c 100644 --- a/funcext/TSOffice/worksheet/xlsxWorkBook.tsf +++ b/funcext/TSOffice/worksheet/xlsxWorkBook.tsf @@ -141,7 +141,25 @@ Type xlsxWorkBook = Class Function GetTable(sheet, topLeft, bottomRight); Begin o := GetSheetObj(sheet); - if ifObj(o) then return o.Import(topLeft, bottomRight); + if ifObj(o) then + begin + data := o.Import(topLeft, bottomRight, includeHeader, includeIndex, forceSingle); + if not TOfficeApi().IsUtf8() then + begin + fields := fieldnames(data); + if ifarray(fields) and length(fields) then + begin + map := array(); + for i:=0 to length(fields)-1 do + map[fields[i]] := class(TSXml).Utf8ToCurCodePage(fields[i]); + reindex(data, nil, map); + end + data::begin + if ifstring(mcell) then mcell := class(TSXml).Utf8ToCurCodePage(mcell); + end + end + return data; + end End; ///创建新sheet From 10ef45f1a064b86fcf8f575786922dd90e7fe8a9 Mon Sep 17 00:00:00 2001 From: csh Date: Wed, 17 May 2023 17:25:21 +0800 Subject: [PATCH 3/7] add `TSTag` and wordtemplate --- funcext/TSOffice/TOfficeObj.tsf | 242 +++++++++++++++++++ funcext/TSOffice/TSDocxFile.tsf | 69 ++++++ funcext/TSOffice/TSExcelFile.tsf | 6 +- funcext/TSOffice/document/TDocxChart.tsf | 1 + funcext/TSOffice/document/TSTag.tsf | 49 ++++ funcext/TSOffice/word/_ExcelChartCopyPic.tsf | 5 +- funcext/TSOffice/worksheet/xlsxWorkBook.tsf | 13 +- 7 files changed, 379 insertions(+), 6 deletions(-) create mode 100644 funcext/TSOffice/document/TSTag.tsf diff --git a/funcext/TSOffice/TOfficeObj.tsf b/funcext/TSOffice/TOfficeObj.tsf index 3767698..83d05d8 100644 --- a/funcext/TSOffice/TOfficeObj.tsf +++ b/funcext/TSOffice/TOfficeObj.tsf @@ -1353,6 +1353,7 @@ type TChartImpl=class(NodeInfo) ,("field":"Excel","name":"Excel","obj":Excel,"attrEx":"","nodeType":"","attrName":"", "desc":"disable", "class":"") ,("field":"chartFileName","name":"chartFileName","obj":chartFileName,"attrEx":"","nodeType":"","attrName":"", "desc":"disable", "class":"") ,("field":"excelFileName","name":"excelFileName","obj":excelFileName,"attrEx":"","nodeType":"","attrName":"", "desc":"disable", "class":"") + ,("field":"drawingFileName","name":"drawingFileName","obj":drawingFileName,"attrEx":"","nodeType":"","attrName":"", "desc":"disable", "class":"") ) union ExtNodes; End; @@ -1395,6 +1396,7 @@ type TChartImpl=class(NodeInfo) Excel; chartFileName; excelFileName; + drawingFileName; End; /////////////////////////////////////////////////////////////// @@ -13492,6 +13494,235 @@ Type TDocumentBody = Class(DocObject) return array(length(errArr), tslFuncCount, errArr); End; + Function ExecTsTag(docx, tagName, tagObj); + Begin + //表格 + t := array(); + tslTagCount := 0; + errArr := array(); + tArr := Tables(); + for i:=0 to length(tArr)-1 do Begin + col := tArr[i].Cols(); + row := tArr[i].Rows(); + for r:= 1 to row do Begin + for c:=1 to col do Begin + cell := tArr[i].Cell(r, c); + [err, cnt, err] := cell.ExecTsTag(docx, tagName, tagObj);//递归 + tslTagCount += cnt; + errArr union= err; + End; + End; + End; + + //文本框 + ps := Paragraphs(); + for i:=0 to length(ps)-1 do Begin + boxs := ps[i].TextBoxs(); + for j:=0 to length(boxs)-1 do Begin + [err, cnt, err] := boxs[j].ExecTsTag(docx, tagName, tagObj);//递归 + if cnt then + boxs[j].Apply(); + tslTagCount += cnt; + errArr union= err; + End; + End; + + //页脚、页眉 + sArr := Sections(); + tpArr := array('default','even','first'); + for i:=0 to length(sArr)-1 do Begin + for k, name in tpArr do Begin + h := sArr[i].Header(name); + if ifObj(h) then Begin + [err, cnt, err] := h.ExecTsTag(docx, tagName, tagObj);//递归 + tslTagCount += cnt; + errArr union= err; + End; + + f := sArr[i].Footer(name); + if ifObj(f) then Begin + [err, cnt, err] := f.ExecTsTag(docx, tagName, tagObj);//递归 + tslTagCount += cnt; + errArr union= err; + End; + End; + End; + + [err, cnt, err] := ExecTsTagImpl(docx, tagName, tagObj); + tslTagCount += cnt; + errArr union= err; + return array(length(errArr), tslTagCount, errArr); + End; + + Function ExecTsTagImpl(docx, tagName, tagObj); + Begin + tslTagCount := 0; + errArr := array(); + tagArr := array(); + tArr := TextArray(); + tagAttribute := ''; + tagStr := ''; + tagStatus := '';//array('','head', 'attribute', 'tail'); + tagHead := '[' + tagName; + tagTail := '[/' + tagName; + tmp := array(); + while i < length(tArr) do Begin + txt := ''; + iStep := 1; + if ifObj(tArr[i]['rNode']) then Begin + run := new TRun(tArr[i]['rNode']); + txt := run.Text(); + if class(TSXml).IsUtf8() then + txt := UTF8ToAnsi(txt); + End; + k := 1; + wz := 1; + txtLen := length(txt); + while k <= txtLen do Begin + c := txt[k]; + if c = ']' and (tagStatus = 'head' or tagStatus = 'attribute') and tagStr = tagHead then Begin //TAG头结束标志 + tagStr := ''; + tagArr := tArr[tmp['head-begin-paragraph']:i,:]; + wz++; + tagStatus := 'tail'; + tmp['head-end-paragraph'] := i; + tmp['head-end-pos'] := k++; + tmp['head-end-wz'] := wz; + tmp['head-end-txtlen'] := txtLen; + continue; + End; + case tagStatus of + '': + if c = '[' then Begin + tagStr := '['; + tmp['head-begin-paragraph'] := i; + tmp['head-begin-pos'] := k; + tmp['head-begin-wz'] := wz; + tmp['head-begin-txtlen'] := txtLen; + tagStatus := 'head'; + tagAttribute := ''; + End; + 'head': + if c = ' ' and tagStr = tagHead then Begin //找到TAG属性 + tagStatus := 'attribute'; + End + else if length(tagStr) < length(tagHead) and lowercase(c) = lowercase(tagHead[ length(tagStr) + 1 ]) then Begin + tagStr += tagHead[ length(tagStr) + 1 ]; + End + else //继续寻找TAG开始标志 + tagStatus := ''; + 'attribute': + tagAttribute += c; + 'tail': + if c=']' and tagStr = tagTail then Begin //查找到完整标签 + ind := length(tagArr) - 1; + if tagArr[ind]['pIndex'] <> tArr[i]['pIndex'] or tagArr[ind]['rIndex'] <> tArr[i]['rIndex'] then Begin + ind ++; + tagArr[ind] := tArr[i]; + End; + + //[/tag]后 + if k < txtLen then Begin //函数后面分割为新的w:r + tArr[i]['rNode'] := run._duplicate_r(tArr[i]['rNode']); + run._adjust_r(tArr[i]['rNode'], wz, txtLen); + iStep := 0; + End; + //前[/tag] + tagInd := length(tagArr) - i + tmp['tail-begin-paragraph'] - 1; + if tmp['tail-begin-pos'] > 1 then Begin + nNode := run._duplicate_r(tagArr[tagInd]['rNode']); + run._adjust_r(tagArr[tagInd]['rNode'], 0, tmp['tail-begin-wz'] - 1); + tagArr[tagInd]['pNode'].DeleteChild(nNode); + End + else if tmp['tail-begin-pos'] = 1 then Begin + if _remove_run(tagArr[tagInd]['pNode'], tagArr[tagInd]['rNode']) then + tagArr[tagInd]['pNode'] := nil; + tagArr[tagInd]['rNode'] := nil; + End; + //删除[/TAG]尾部 + for delI := tagInd+1 to length(tagArr)-1 do Begin + if _remove_run(tagArr[delI]['pNode'], tagArr[delI]['rNode']) then + tagArr[delI]['pNode'] := nil; + tagArr[delI]['rNode'] := nil; + End; + + //[tag]后 + firstNode := tagArr[0]['rNode']; + tagInd := length(tagArr) - i + tmp['head-end-paragraph'] - 1; + //println('===============================head-end-pos={},head-end-txtlen={}',tmp['head-end-pos'] , tmp['head-end-txtlen']); + if tmp['head-end-pos'] < tmp['head-end-txtlen'] then Begin + oldNode := tagArr[tagInd]['rNode']; + tagArr[tagInd]['rNode'] := run._duplicate_r(oldNode); + run._adjust_r(tagArr[tagInd]['rNode'], tmp['head-end-wz'] - 1, tmp['head-end-txtlen']); + End + else if tmp['head-end-pos'] = tmp['head-end-txtlen'] and tagInd then Begin + if _remove_run(tagArr[tagInd]['pNode'], tagArr[tagInd]['rNode']) then + tagArr[tagInd]['pNode'] := nil; + tagArr[tagInd]['rNode'] := nil; + End; + //前[tag] + if tmp['head-begin-pos'] > 1 then Begin + run._adjust_r(firstNode, 0, tmp['head-begin-wz'] - 1); + if tmp['head-begin-paragraph'] <> tmp['head-end-paragraph'] then + tagArr[0]['rNode'] := nil; + End + else if tmp['head-begin-pos'] = 1 then Begin + if _remove_run(tagArr[0]['pNode'], firstNode) then + tagArr[0]['pNode'] := nil; + if tmp['head-begin-paragraph'] <> tmp['head-end-paragraph'] then + tagArr[0]['rNode'] := nil; + End; + for delI := 1 to tagInd-1 do Begin + if _remove_run(tagArr[delI]['pNode'], tagArr[delI]['rNode']) then + tagArr[delI]['pNode'] := nil; + tagArr[delI]['rNode'] := nil; + End; + + //执行TAG逻辑 + r := array(); + for nI := 0 to length(tagArr)-1 do Begin + if ifObj(tagArr[nI]['rNode']) then + r[length(r)] := tagArr[nI]; + End; + tagObj.Init(tagName, attribute, r); + tagObj.Apply(); + tslTagCount++; + + tagStatus := ''; + tagArr := array(); + break; + End + else if length(tagStr) < length(tagTail) and lowercase(c) = lowercase(tagTail[ length(tagStr) + 1 ]) then Begin + tagStr += tagTail[ length(tagStr) + 1 ]; + if tagStr = '[' then Begin + tmp['tail-begin-paragraph'] := i; + tmp['tail-begin-pos'] := k; + tmp['tail-begin-wz'] := wz; + tmp['tail-begin-txtlen'] := txtLen; + End; + End + else //继续寻找TAG结束标志 + tagStr := ''; + End; + if Ord(c) > 127 then Begin + k ++; + End + k ++; + wz ++; + End; + if length(tagArr) then Begin + if i and i < length(tArr) and tArr[i]['pIndex'] <> tArr[i+1]['pIndex'] then Begin + endPos ++; + End; + ind := length(tagArr) - 1; + if tagArr[ind]['pIndex'] <> tArr[i]['pIndex'] or tagArr[ind]['rIndex'] <> tArr[i]['rIndex'] then + tagArr[ind + 1] := tArr[i]; + End; + i += iStep; + End; + return array(length(errArr), tslTagCount, errArr); + End; + Function GetHeadingListImpl(docx, posOpt, UpperHeadingLevel, LowerHeadingLevel, numIds, bHeadList); Begin r := array(); @@ -13679,6 +13910,17 @@ Type TDocumentBody = Class(DocObject) End; End; + Function _remove_run(pNode, rNode); + Begin + pNode.DeleteChild(rNode); + node := pNode.FirstChildElement('w:r'); + if not ifObj(node) then Begin + pNode.Parent().DeleteChild(pNode); + return true; + End; + return false; + End; + zipfile_; lastParagraph_; document_; diff --git a/funcext/TSOffice/TSDocxFile.tsf b/funcext/TSOffice/TSDocxFile.tsf index 03f15c0..5ed6ede 100644 --- a/funcext/TSOffice/TSDocxFile.tsf +++ b/funcext/TSOffice/TSDocxFile.tsf @@ -272,6 +272,7 @@ Type TSDocxFile = Class chart.pNode := p.node_; p.Node().InsertEndChild(o.GetInnerXml()); TOfficeApi().Set('CurrentShape', p.node_); + chart.chartFileName := 'word/charts/chart' $ o.ChartId_ $ '.xml'; return chart; End; @@ -293,6 +294,74 @@ Type TSDocxFile = Class return r; End; + ///从Excel中Copy指定的chart图到文档中指定位置 + ///excelFileName:string xlsx文件名 + ///excelSheetName:string sheetname + ///chartName:string or integer,chart图名称或当前sheet中chart图索引号 + ///Width:chart图宽度,单位cm + ///Height:chart图高度,单位cm + ///posOpt: 段落位置,0 在DOCX文件开头;-1 文件尾;N 在第N段之后;XmlNode节点对象或DocObject对象 在posOpt之后新添加图片 + ///返回TChart对象 + Function CopyExcelChart(excelFileName, excelSheetName, chartName, Width, Height, posOpt); + Begin + excel := new TSExcelFile(); + [err, msg] := excel.OpenFile('', excelFileName); + if err then return nil; + [err, charts] := excel.GetCharts(excelSheetName); + if err or length(charts)=0 then return nil; + drawingObj := excel.WorkBook().GetXmlFileObj(charts[0].drawingFileName); + if not ifObj(drawingObj) then return nil; + node := drawingObj.FirstChildElement('xdr:wsDr').FirstChildElement('xdr:twoCellAnchor'); + ind := 0; + chartRid := ''; + while ifObj(node) do Begin + findChart := false; + cNvPr := class(TSXml).GetNode(node, 'xdr:GraphicFrame/xdr:nvGraphicFramePr/xdr:cNvPr'); + name := ifObj(cNvPr) ? cNvPr.GetAttribute('name') : ''; + if ifstring(chartName) then Begin + if name = chartName then + find := true; + End + else if ifInt(chartName) and ind = chartName then + find := true; + if find then Begin + chartNode := class(TSXml).GetNode(node, 'xdr:GraphicFrame/a:graphic/a:graphicData/c:chart'); + if not ifObj(chartNode) then return nil; + chartRid := chartNode.GetAttribute('r:id'); + break; + End; + ind ++; + node := node.NextElement(); + End; + for i:=0 to length(charts)-1 do Begin + if charts[i].Rid = chartRid then Begin + chart := TOfficeObj('TChart'); + chart.Width := Width; + chart.Height := Height; + chart.Name := name; + chart.Type := 'line'; + chart.ShowBubbleSize := false; + chart.ShowPercent := false; + chart.DataTable := false; + chart.AddSeries('test', array('line1'), array(1,2)); + chart := AddChart(chart, getPosNode(posOpt)); + xmlObj := Zip().Get(chart.chartFileName); + xmlObj.Data := charts[i].xmlObj.Data; + return chart; + End; + End; + return nil; + End; + + ///遍历文档中所有[TSTAG][/TSTAG]标签,针对每一个TAG执行tagObj.Apply() + ///tagName:string 标签名称 + ///tagObj:TAG对象方法 + ///返回:[err,tslTagCount,errArr]: err 执行错误TAG次数,tslTagCount TAG总数,errArr 错误信息(array(('code':'代码', 'err':'错误信息'))) + Function ExecTsTag(tagName, tagObj); + Begin + return Body().ExecTsTag(self, tagName, tagObj); + End; + ///文档中全部的批注信息 ///返回:DocComments对象 Function Comments(); diff --git a/funcext/TSOffice/TSExcelFile.tsf b/funcext/TSOffice/TSExcelFile.tsf index 4cb1e79..cbed220 100644 --- a/funcext/TSOffice/TSExcelFile.tsf +++ b/funcext/TSOffice/TSExcelFile.tsf @@ -349,10 +349,12 @@ Type TSExcelFile = Class ///sheet: string,工作表名称 ///topLeft: string,左上角坐标,如: "A4" ///bottomRight: string,右下角坐标,如: "B8",为空获取从topLeft开始的整张表 + ///[IncludeHeader: bool] 是否包括表头,默认FALSE + ///[IncludeIndex: bool] 是否包括索引号,默认FALSE ///返回: table - Function GetTable(sheet, topLeft, bottomRight); + Function GetTable(sheet, topLeft, bottomRight, includeHeader, includeIndex, forceSingle); Begin - return workbook_.GetTable(class(TSXml).CurCodePageToUtf8(sheet), topLeft, bottomRight); + return workbook_.GetTable(class(TSXml).CurCodePageToUtf8(sheet), topLeft, bottomRight, includeHeader, includeIndex, forceSingle); End; ///插入列,在指定列前插入空白列 diff --git a/funcext/TSOffice/document/TDocxChart.tsf b/funcext/TSOffice/document/TDocxChart.tsf index 4f48740..8f6bb42 100644 --- a/funcext/TSOffice/document/TDocxChart.tsf +++ b/funcext/TSOffice/document/TDocxChart.tsf @@ -8,6 +8,7 @@ Type TDocxChart = Class(TSChart) chartId_ := 1 + vselect countof( ['FileName'] ) from docx.Zip().Files() where AnsiStartsText('word/charts/chart', ['FileName']) end; targetFileName := 'charts/chart' $ chartId_ $ '.xml'; chartFile := 'word/' + targetFileName; + chartFileName_ := chartFile; docx.Zip().Add(chartFile, GetDefaultXml()); xmlObj_ := docx.Zip().Get(chartFile); if not chartData_.DisableExcel and istable(chartData.Series) and istable(chartData.Series[0]['Categories']) and istable(chartData.Series[0]['Values']) then Begin diff --git a/funcext/TSOffice/document/TSTag.tsf b/funcext/TSOffice/document/TSTag.tsf new file mode 100644 index 0000000..e642173 --- /dev/null +++ b/funcext/TSOffice/document/TSTag.tsf @@ -0,0 +1,49 @@ +Type TSTag = Class + ///缺省构造函数 + Function Create(); overload; + Begin + End; + + Function Init(tagName, attribute, r); + Begin + tagName_ := tagName; + attribute_ := attribute; + runArr_ := r; + End; + + Function Apply(); virtual; + Begin + case tagName_ of + 'add': + _add(); + 'del': + _del(); + End; + End; + + Function _add(); + Begin + for i:=0 to length(runArr_)-1 do Begin + run := TOfficeObj('TRun'); + run.Init(runArr_[i]['rNode']); + run.Font.Size := 40; + run.Font.Color := 'FF0000'; + run.Font.Bold := true; + run.Apply(); + End; + End; + + Function _del(); + Begin + for i:=0 to length(runArr_)-1 do Begin + runArr_[i]['pNode'].DeleteChild(runArr_[i]['rNode']); + child := runArr_[i]['pNode'].FirstChildElement('w:r'); + if not ifObj(child) then + runArr_[i]['pNode'].Parent().DeleteChild(runArr_[i]['pNode']); + End; + End; + + tagName_:string; + attribute_:string; + runArr_; +End; diff --git a/funcext/TSOffice/word/_ExcelChartCopyPic.tsf b/funcext/TSOffice/word/_ExcelChartCopyPic.tsf index a7446f9..df0734d 100644 --- a/funcext/TSOffice/word/_ExcelChartCopyPic.tsf +++ b/funcext/TSOffice/word/_ExcelChartCopyPic.tsf @@ -1,3 +1,6 @@ -Function _ExcelChartCopyPic(excelFileName, excelSheetName, picType); +Function _ExcelChartCopyPic(excelFileName, excelSheetName, chartName, Width, Height); Begin + docx := TOfficeApi().GetDocument(); + chart := docx.CopyExcelChart(excelFileName, excelSheetName, chartName, Width, Height, TOfficeApi().GetCurrentPosition()); + return ifObj(chart); End; \ No newline at end of file diff --git a/funcext/TSOffice/worksheet/xlsxWorkBook.tsf b/funcext/TSOffice/worksheet/xlsxWorkBook.tsf index a73540c..5e883df 100644 --- a/funcext/TSOffice/worksheet/xlsxWorkBook.tsf +++ b/funcext/TSOffice/worksheet/xlsxWorkBook.tsf @@ -138,7 +138,7 @@ Type xlsxWorkBook = Class return class(ErrorMessage).Fail(); End; - Function GetTable(sheet, topLeft, bottomRight); + Function GetTable(sheet, topLeft, bottomRight, includeHeader, includeIndex, forceSingle); Begin o := GetSheetObj(sheet); if ifObj(o) then @@ -162,8 +162,6 @@ Type xlsxWorkBook = Class end End; - ///创建新sheet - ///sheet: string,工作表名称 Function NewSheet(sheet);overload; Begin lname := LowerCase(sheet); @@ -696,6 +694,7 @@ Type xlsxWorkBook = Class chartFile := ReplaceStr(target, '..', 'xl'); chart := TOfficeObj('TChart'); chart.Rid := node.GetAttribute('Id'); //rid + chart.drawingFileName := drawingFile; setChartInfo(chartFile, chart); charts[i] := chart; i++; @@ -1148,6 +1147,14 @@ Type xlsxWorkBook = Class Function ProtectSheet(sheet, protect); Begin + if protect.AlgorithmName and protect.Password then + begin + protect.SaltValue := nil;//protect.Password; + protect.HashValue := nil;//GetMsgDigest(protect.SaltValue, 6); + protect.SpinCount := nil; + protect.Password := nil; + protect.AlgorithmName := nil; + end sheet_obj := GetSheetXmlfile(sheet); work_node := sheet_obj.FirstChildElement('worksheet'); sheet_protection_node := work_node.FirstChildElement('sheetProtection'); From d08dea6bc97cf0c7b13deab2ff3253850f5ee15d Mon Sep 17 00:00:00 2001 From: csh Date: Fri, 19 May 2023 10:41:46 +0800 Subject: [PATCH 4/7] update `TSTag` --- funcext/TSOffice/TOfficeObj.tsf | 85 +++++++++++++---------------- funcext/TSOffice/document/TSTag.tsf | 51 ++++++++++++----- 2 files changed, 76 insertions(+), 60 deletions(-) diff --git a/funcext/TSOffice/TOfficeObj.tsf b/funcext/TSOffice/TOfficeObj.tsf index 83d05d8..80f869d 100644 --- a/funcext/TSOffice/TOfficeObj.tsf +++ b/funcext/TSOffice/TOfficeObj.tsf @@ -5,6 +5,8 @@ Begin case lowercase(n) of "nodeinfo": return new NodeInfo(""); + "trange": + return new TRange(""); "tfont": return new TFont(); "tcomment": @@ -10156,11 +10158,20 @@ End; ///DOCX文档实现 Type TRange = Class - Function Create(t); + Function Create();overload; + Begin + Create(nil); + End; + + Function Create(t);overload; Begin //array(("pNode":nodeObj, "pIndex":p, "rNode":nodeObj, "rIndex":r)) + Init(t); + End; + + Function Init(t); + Begin RunArr_ := t; - rPr_ := new TwrPr(); End; ///清除全部选中内容 @@ -10172,6 +10183,8 @@ Type TRange = Class Property Font read readFont; Function readFont(); Begin + if ifNil(rPr_) then + rPr_ := new TwrPr(); return rPr_; End; @@ -10193,6 +10206,7 @@ Type TRange = Class ///应用字体样式 Function Apply(); Begin + if not ifObj(rPr_) then return; arr := rPr_.Marshal(); if length(arr['attributes']) or length(arr['children']) then Begin for i:=0 to length(RunArr_)-1 do Begin @@ -10204,11 +10218,9 @@ Type TRange = Class Function _clear(first); Begin - for i:=first to length(RunArr_)-1 do Begin - RunArr_[i]['pNode'].DeleteChild(RunArr_[i]['rNode']); - End; for i:=first to length(RunArr_)-1 do Begin pNode := RunArr_[i]['pNode']; + pNode.DeleteChild(RunArr_[i]['rNode']); rNode := pNode.FirstChildElement('w:r'); if not ifObj(rNode) then pNode.Parent().DeleteChild(pNode); @@ -13622,7 +13634,7 @@ Type TDocumentBody = Class(DocObject) End; //[/tag]后 - if k < txtLen then Begin //函数后面分割为新的w:r + if k < txtLen then Begin //后面分割为新的w:r tArr[i]['rNode'] := run._duplicate_r(tArr[i]['rNode']); run._adjust_r(tArr[i]['rNode'], wz, txtLen); iStep := 0; @@ -13633,58 +13645,50 @@ Type TDocumentBody = Class(DocObject) nNode := run._duplicate_r(tagArr[tagInd]['rNode']); run._adjust_r(tagArr[tagInd]['rNode'], 0, tmp['tail-begin-wz'] - 1); tagArr[tagInd]['pNode'].DeleteChild(nNode); + tmp['tag-end'] := tagInd; End else if tmp['tail-begin-pos'] = 1 then Begin - if _remove_run(tagArr[tagInd]['pNode'], tagArr[tagInd]['rNode']) then - tagArr[tagInd]['pNode'] := nil; - tagArr[tagInd]['rNode'] := nil; + tmp['tag-end'] := tagInd - 1; End; - //删除[/TAG]尾部 - for delI := tagInd+1 to length(tagArr)-1 do Begin - if _remove_run(tagArr[delI]['pNode'], tagArr[delI]['rNode']) then - tagArr[delI]['pNode'] := nil; - tagArr[delI]['rNode'] := nil; - End; - + //[tag]后 firstNode := tagArr[0]['rNode']; tagInd := length(tagArr) - i + tmp['head-end-paragraph'] - 1; - //println('===============================head-end-pos={},head-end-txtlen={}',tmp['head-end-pos'] , tmp['head-end-txtlen']); if tmp['head-end-pos'] < tmp['head-end-txtlen'] then Begin oldNode := tagArr[tagInd]['rNode']; tagArr[tagInd]['rNode'] := run._duplicate_r(oldNode); run._adjust_r(tagArr[tagInd]['rNode'], tmp['head-end-wz'] - 1, tmp['head-end-txtlen']); + tmp['tag-beg'] := tagInd; + if tmp['head-begin-paragraph'] <> tmp['head-end-paragraph'] then + tagArr[tagInd]['pNode'].DeleteChild(oldNode); End else if tmp['head-end-pos'] = tmp['head-end-txtlen'] and tagInd then Begin - if _remove_run(tagArr[tagInd]['pNode'], tagArr[tagInd]['rNode']) then - tagArr[tagInd]['pNode'] := nil; - tagArr[tagInd]['rNode'] := nil; + tmp['tag-beg'] := tagInd + 1; End; //前[tag] if tmp['head-begin-pos'] > 1 then Begin run._adjust_r(firstNode, 0, tmp['head-begin-wz'] - 1); - if tmp['head-begin-paragraph'] <> tmp['head-end-paragraph'] then + if firstNode = tagArr[0]['rNode'] then tagArr[0]['rNode'] := nil; End - else if tmp['head-begin-pos'] = 1 then Begin - if _remove_run(tagArr[0]['pNode'], firstNode) then - tagArr[0]['pNode'] := nil; - if tmp['head-begin-paragraph'] <> tmp['head-end-paragraph'] then - tagArr[0]['rNode'] := nil; - End; - for delI := 1 to tagInd-1 do Begin - if _remove_run(tagArr[delI]['pNode'], tagArr[delI]['rNode']) then - tagArr[delI]['pNode'] := nil; - tagArr[delI]['rNode'] := nil; - End; + else if tagInd=0 and tmp['tag-beg']=0 then + tagArr[0]['pNode'].DeleteChild(firstNode); //执行TAG逻辑 r := array(); for nI := 0 to length(tagArr)-1 do Begin - if ifObj(tagArr[nI]['rNode']) then - r[length(r)] := tagArr[nI]; + if not ifObj(tagArr[nI]['rNode']) then continue; + if nI >= tmp['tag-beg'] and nI <= tmp['tag-end'] then + r[length(r)] := tagArr[nI];//标签中间文字内容 + else Begin //删除标签 + tagArr[nI]['pNode'].DeleteChild(tagArr[nI]['rNode']); + node := tagArr[nI]['pNode'].FirstChildElement('w:r'); + if not ifObj(node) then Begin + tagArr[nI]['pNode'].Parent().DeleteChild(tagArr[nI]['pNode']); + End; + End; End; - tagObj.Init(tagName, attribute, r); + tagObj.Init(tagName, tagAttribute, r); tagObj.Apply(); tslTagCount++; @@ -13910,17 +13914,6 @@ Type TDocumentBody = Class(DocObject) End; End; - Function _remove_run(pNode, rNode); - Begin - pNode.DeleteChild(rNode); - node := pNode.FirstChildElement('w:r'); - if not ifObj(node) then Begin - pNode.Parent().DeleteChild(pNode); - return true; - End; - return false; - End; - zipfile_; lastParagraph_; document_; diff --git a/funcext/TSOffice/document/TSTag.tsf b/funcext/TSOffice/document/TSTag.tsf index e642173..99bda57 100644 --- a/funcext/TSOffice/document/TSTag.tsf +++ b/funcext/TSOffice/document/TSTag.tsf @@ -9,6 +9,36 @@ Type TSTag = Class tagName_ := tagName; attribute_ := attribute; runArr_ := r; + range_ := nil; + map_ := nil; + End; + + Property Range read readRange; + Function readRange(); + Begin + if ifNil(range_) then Begin + range_ := TOfficeObj('TRange'); + range_.Init(runArr_); + End; + return range_; + End; + + ///获取TAG中属性 [font size=12]...[/font] + /// tag.GetAttribute('size'); + ///返回:string + Function GetAttribute(key); + Begin + if not ifArray(map_) then Begin + map_ := array(); + println('attribute={}',attribute_); + arr := Str2Array(attribute_, ' '); + for i := 0 to length(arr)-1 do Begin + kv := Str2Array(arr[i], '='); + if length(kv)=2 then + map_[kv[0]] := kv[1]; + End; + End; + return map_[key]; End; Function Apply(); virtual; @@ -23,27 +53,20 @@ Type TSTag = Class Function _add(); Begin - for i:=0 to length(runArr_)-1 do Begin - run := TOfficeObj('TRun'); - run.Init(runArr_[i]['rNode']); - run.Font.Size := 40; - run.Font.Color := 'FF0000'; - run.Font.Bold := true; - run.Apply(); - End; + Range.Font.Size := 40; + Range.Font.Color := 'FF0000'; + Range.Font.Bold := true; + Range.Apply(); End; Function _del(); Begin - for i:=0 to length(runArr_)-1 do Begin - runArr_[i]['pNode'].DeleteChild(runArr_[i]['rNode']); - child := runArr_[i]['pNode'].FirstChildElement('w:r'); - if not ifObj(child) then - runArr_[i]['pNode'].Parent().DeleteChild(runArr_[i]['pNode']); - End; + Range.Clear(); End; tagName_:string; attribute_:string; runArr_; + range_; + map_; End; From 8f6bdd212b3d654be10faf1ccb96349fbc6aaf8b Mon Sep 17 00:00:00 2001 From: csh Date: Tue, 13 Jun 2023 13:27:59 +0800 Subject: [PATCH 5/7] update two template --- funcext/TSOffice/word/_WordSetLastTableProp.tsf | 1 - funcext/TSOffice/word/_WordTemplate.tsf | 12 ++++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/funcext/TSOffice/word/_WordSetLastTableProp.tsf b/funcext/TSOffice/word/_WordSetLastTableProp.tsf index 3afd055..52df9a0 100644 --- a/funcext/TSOffice/word/_WordSetLastTableProp.tsf +++ b/funcext/TSOffice/word/_WordSetLastTableProp.tsf @@ -10,7 +10,6 @@ Begin str += '"' $ value $ '"'; else str = str $ value; - println("str = {}", str); eval(&str); TOfficeApi().Set('LastTable', table); return true; diff --git a/funcext/TSOffice/word/_WordTemplate.tsf b/funcext/TSOffice/word/_WordTemplate.tsf index 6cb8ca1..bf862a7 100644 --- a/funcext/TSOffice/word/_WordTemplate.tsf +++ b/funcext/TSOffice/word/_WordTemplate.tsf @@ -1,10 +1,14 @@ -Function _WordTemplate(alias, fileName); +Function _WordTemplate(data, template, fileName); Begin + setsysparam('data', data); docx := new TSDocxFile(); - [err, msg] := docx.OpenFile(alias, fileName); + [err, msg] := docx.OpenFile('', template); if err then return false; docx.ExecInnerTSL(); - [err, msg] := docx.Save(); - if err then return false; + if ifstring(fileName) then + begin + [err, msg] := docx.SaveAs('', fileName); + if err then return false; + end return true; End; From 3643be623124bd4675108d3ffe34c38c53a8c212 Mon Sep 17 00:00:00 2001 From: csh Date: Tue, 29 Aug 2023 15:05:06 +0800 Subject: [PATCH 6/7] update --- funcext/TSOffice/TOfficeObj.tsf | 11 +++-------- funcext/TSOffice/word/_WordSetCurrentRange.tsf | 4 ++++ funcext/TSOffice/worksheet/xlsxWorkBook.tsf | 8 -------- 3 files changed, 7 insertions(+), 16 deletions(-) create mode 100644 funcext/TSOffice/word/_WordSetCurrentRange.tsf diff --git a/funcext/TSOffice/TOfficeObj.tsf b/funcext/TSOffice/TOfficeObj.tsf index 7e48236..166b7b1 100644 --- a/funcext/TSOffice/TOfficeObj.tsf +++ b/funcext/TSOffice/TOfficeObj.tsf @@ -13558,14 +13558,9 @@ Type TDocumentBody = Class(DocObject) TOfficeApi().Set('CurrentPosition', tslBegParagraphNode); TOfficeApi().Set('CurrentRun', curRunNode); TOfficeApi().Set('CodePage', 'gbk'); - try - tslFuncCount ++; - if code <> '' then - str := eval(&code); - except - println('run code={},err={}', code, ExceptObject.ErrInfo); - errArr[ length(errArr) ] := array('code':code, 'err':ExceptObject.ErrInfo); - str := ''; + if not RunTslCode(code, err) then Begin + echo 'run code=',code,',err=', err, '\n'; + errArr[ length(errArr) ] := array('code':code, 'err':err); End; tslFuncCount ++; tNode := curRun.node_.FirstChildElement('w:t'); diff --git a/funcext/TSOffice/word/_WordSetCurrentRange.tsf b/funcext/TSOffice/word/_WordSetCurrentRange.tsf new file mode 100644 index 0000000..164e117 --- /dev/null +++ b/funcext/TSOffice/word/_WordSetCurrentRange.tsf @@ -0,0 +1,4 @@ +Function _WordSetCurrentRange(range); +Begin + TOfficeApi().Set('CurrentPosition', range); +End; diff --git a/funcext/TSOffice/worksheet/xlsxWorkBook.tsf b/funcext/TSOffice/worksheet/xlsxWorkBook.tsf index 5e883df..5b9395f 100644 --- a/funcext/TSOffice/worksheet/xlsxWorkBook.tsf +++ b/funcext/TSOffice/worksheet/xlsxWorkBook.tsf @@ -1147,14 +1147,6 @@ Type xlsxWorkBook = Class Function ProtectSheet(sheet, protect); Begin - if protect.AlgorithmName and protect.Password then - begin - protect.SaltValue := nil;//protect.Password; - protect.HashValue := nil;//GetMsgDigest(protect.SaltValue, 6); - protect.SpinCount := nil; - protect.Password := nil; - protect.AlgorithmName := nil; - end sheet_obj := GetSheetXmlfile(sheet); work_node := sheet_obj.FirstChildElement('worksheet'); sheet_protection_node := work_node.FirstChildElement('sheetProtection'); From 15e2cbe6618e727e41d09a04f211d26f9fe73b70 Mon Sep 17 00:00:00 2001 From: csh Date: Thu, 7 Dec 2023 13:41:06 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E6=95=B4=E7=90=86word=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E4=BD=9C=E4=B8=BAunit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../document/TSWordTemplateMethods.tsf | 297 ++++++++++++++++++ funcext/TSOffice/word/_ExcelChartCopyPic.tsf | 6 - .../word/_WordAddOleObjectFromFile.tsf | 3 - funcext/TSOffice/word/_WordBr.tsf | 5 - funcext/TSOffice/word/_WordCopyFromExcel.tsf | 34 -- .../TSOffice/word/_WordCopyPicFromExcel.tsf | 3 - .../TSOffice/word/_WordGetCurrentDocument.tsf | 4 - .../TSOffice/word/_WordGetCurrentRange.tsf | 4 - funcext/TSOffice/word/_WordGetFont.tsf | 10 - funcext/TSOffice/word/_WordGetLastRange.tsf | 4 - funcext/TSOffice/word/_WordGetLastShape.tsf | 16 - funcext/TSOffice/word/_WordGetLastTable.tsf | 4 - .../word/_WordGetLastTableCellProp.tsf | 12 - .../TSOffice/word/_WordGetLastTableProp.tsf | 11 - funcext/TSOffice/word/_WordGetRangeProp.tsf | 3 - funcext/TSOffice/word/_WordLastTableMerge.tsf | 11 - funcext/TSOffice/word/_WordLastTableSplit.tsf | 3 - .../TSOffice/word/_WordSetCurrentRange.tsf | 4 - .../TSOffice/word/_WordSetCurrnetRange.tsf | 4 - funcext/TSOffice/word/_WordSetFont.tsf | 8 - .../word/_WordSetLastTableCellProp.tsf | 17 - .../TSOffice/word/_WordSetLastTableProp.tsf | 17 - funcext/TSOffice/word/_WordSetRangeProp.tsf | 5 - funcext/TSOffice/word/_WordTemplate.tsf | 14 - funcext/TSOffice/word/_WordWrite.tsf | 17 - .../TSOffice/word/_WordWritePicFromFile.tsf | 11 - funcext/TSOffice/word/_WordWriteTable.tsf | 8 - funcext/TSOffice/word/_wordCompTable.tsf | 10 - funcext/TSOffice/word/create.tsf | 26 -- 29 files changed, 297 insertions(+), 274 deletions(-) create mode 100644 funcext/TSOffice/document/TSWordTemplateMethods.tsf delete mode 100644 funcext/TSOffice/word/_ExcelChartCopyPic.tsf delete mode 100644 funcext/TSOffice/word/_WordAddOleObjectFromFile.tsf delete mode 100644 funcext/TSOffice/word/_WordBr.tsf delete mode 100644 funcext/TSOffice/word/_WordCopyFromExcel.tsf delete mode 100644 funcext/TSOffice/word/_WordCopyPicFromExcel.tsf delete mode 100644 funcext/TSOffice/word/_WordGetCurrentDocument.tsf delete mode 100644 funcext/TSOffice/word/_WordGetCurrentRange.tsf delete mode 100644 funcext/TSOffice/word/_WordGetFont.tsf delete mode 100644 funcext/TSOffice/word/_WordGetLastRange.tsf delete mode 100644 funcext/TSOffice/word/_WordGetLastShape.tsf delete mode 100644 funcext/TSOffice/word/_WordGetLastTable.tsf delete mode 100644 funcext/TSOffice/word/_WordGetLastTableCellProp.tsf delete mode 100644 funcext/TSOffice/word/_WordGetLastTableProp.tsf delete mode 100644 funcext/TSOffice/word/_WordGetRangeProp.tsf delete mode 100644 funcext/TSOffice/word/_WordLastTableMerge.tsf delete mode 100644 funcext/TSOffice/word/_WordLastTableSplit.tsf delete mode 100644 funcext/TSOffice/word/_WordSetCurrentRange.tsf delete mode 100644 funcext/TSOffice/word/_WordSetCurrnetRange.tsf delete mode 100644 funcext/TSOffice/word/_WordSetFont.tsf delete mode 100644 funcext/TSOffice/word/_WordSetLastTableCellProp.tsf delete mode 100644 funcext/TSOffice/word/_WordSetLastTableProp.tsf delete mode 100644 funcext/TSOffice/word/_WordSetRangeProp.tsf delete mode 100644 funcext/TSOffice/word/_WordTemplate.tsf delete mode 100644 funcext/TSOffice/word/_WordWrite.tsf delete mode 100644 funcext/TSOffice/word/_WordWritePicFromFile.tsf delete mode 100644 funcext/TSOffice/word/_WordWriteTable.tsf delete mode 100644 funcext/TSOffice/word/_wordCompTable.tsf delete mode 100644 funcext/TSOffice/word/create.tsf diff --git a/funcext/TSOffice/document/TSWordTemplateMethods.tsf b/funcext/TSOffice/document/TSWordTemplateMethods.tsf new file mode 100644 index 0000000..58e032a --- /dev/null +++ b/funcext/TSOffice/document/TSWordTemplateMethods.tsf @@ -0,0 +1,297 @@ +Unit TSWordTemplateMethods; +Interface + Function ExcelChartCopyPic(excelFileName, excelSheetName, chartName, width, height); + Function WordAddOleObjectFromFile(fileName, width, height); + Function WordBr(); + Function WordCopyFromExcel(excelFileName, excelSheetName, startRow, startCol, endRow, endCol); + Function WordGetCurrentDocument(); + Function WordGetCurrentRange(); + Function WordGetFont(prop, value); + Function WordGetLastRange(); + Function WordGetLastShape(); + Function WordGetLastTable(); + Function WordGetLastTableCellProp(row, col, name, value); + Function WordGetLastTableProp(name, value); + Function WordLastTableMerge(row1, col1, row2, col2); + Function WordSetCurrentRange(range); + Function WordSetFont(prop, value); + Function WordSetLastTableCellProp(row, col, name, value); + Function WordSetLastTableProp(name, value); + Function WordSetRangeProp(name, value); + Function WordTemplate(data, template, fileName); + Function WordWrite(); + Function WordWritePicFromFile(fileName); + Function WordWriteTable(table, writeIntIndex, writeIntTitle, incIntIndex); + +Implementation + Function ExcelChartCopyPic(excelFileName, excelSheetName, chartName, width, height); + Begin + docx := TOfficeApi().GetDocument(); + chart := docx.CopyExcelChart(excelFileName, excelSheetName, chartName, width, height, TOfficeApi().GetCurrentPosition()); + return ifObj(chart); + End; + + Function WordBr(); + Begin + TOfficeApi().GetDocument().AddLineBreak(TOfficeApi().Get('CurrentPosition')); + End; + + Function WordCopyFromExcel(excelFileName, excelSheetName, startRow, startCol, endRow, endCol); + Begin + excel := new TSXlsFile(); + [err, msg] := excel.OpenFile('', excelFileName); + if err then return false; + total_row := excel.TotalRows(excelSheetName); + total_col := excel.TotalCols(excelSheetName); + if not total_row or not total_col then return false; + if ifnil(startRow) then + startRow := 1; + if ifnil(startCol) then + startCol := 1; + if ifnil(endRow) then + endRow := total_row; + if ifnil(endCol) then + endCol := total_col; + data := excel.GetTable(excelSheetName, + CoordinatesToCellName(startCol, startRow), + CoordinatesToCellName(endCol, endRow), + false, + false, + false); + if length(data) = 0 then return false; + //println('data={}',data); + docx := TOfficeApi().GetDocument(); + tbl := docx.CreateTable(data, false, false); + tbl.Format.Borders.Top.Val := 'dashed'; + tbl.Format.Borders.Left.Val := 'dashed'; + tbl.Format.Borders.Bottom.Val := 'dashed'; + tbl.Format.Borders.Right.Val := 'dashed'; + tbl.Format.Borders.InsideH.Val := 'dashed'; + tbl.Format.Borders.InsideV.Val := 'dashed'; + tbl := docx.InsertTable(tbl, TOfficeApi().GetCurrentPosition()); + End; + + Function WordGetCurrentDocument(); + Begin + return TOfficeApi().GetDocument(); + End; + + Function WordGetCurrentRange(); + Begin + return TOfficeApi().GetCurrentPosition(); + End; + + Function WordGetFont(prop, value); + Begin + crun := TOfficeApi().GetCurrentRun(); + node := crun.Node().FirstChildElement('w:rPr'); + rPr := TOfficeObj('TwrPr'); + rPr.InitRootNode(node); + value := rPr.Value(prop); + if not ifnil(value) then return true; + return false; + End; + + Function WordGetLastShape(); + Begin + node := TOfficeApi().Get('CurrentShape'); + if not ifObj(node) then return nil; + uri := 'w:r/w:drawing/wp:inline/a:graphic/a:graphicData/c:chart'; + cNode := class(TSXml).GetNode(node, uri); + if ifObj(cNode) then Begin + chart := TOfficeObj('TChart'); + chart.Init(TOfficeApi().GetDocument(), node, cNode); + return chart; + End; + + pic := TOfficeObj('TPicture'); + pic.Init(node); + return pic; + End; + + Function WordGetLastRange(); + Begin + return TOfficeApi().GetCurrentPosition(); + End; + + Function WordGetLastTable(); + Begin + return TOfficeApi().Get('CurrentTable'); + End; + + Function WordGetLastTableCellProp(row, col, name, value); + Begin + table_node := TOfficeApi().Get('CurrentTable'); + if ifnil(table_node) then return false; + table := TOfficeObj("TTable"); + table.Init(table_node); + table_cell := table.Cell(row, col); + ctr := _wordCompTable(); + name_ := ctr[lowercase(name)]; + if ifnil(name_) then name_ := name; + str := 'return table_cell.Format.' $ name_ $ '"' $ value $ '"'; + value := eval(&str); + return true; + End; + + Function WordGetLastTableProp(name, value); + Begin + table_node := TOfficeApi().Get('CurrentTable'); + if ifnil(table_node) then return false; + table := TOfficeObj("TTable"); + table.Init(table_node); + ctr := _wordCompTable(); + name_ := ctr[lowercase(name)]; + if ifnil(name_) then name_ := name; + str := 'return table.Format.' $ name_ $ '"' $ value $ '"'; + value := eval(&str); + return true; + End; + + Function WordLastTableMerge(row1, col1, row2, col2); + Begin + table_node := TOfficeApi().Get('CurrentTable'); + if ifnil(table_node) then return false; + table := TOfficeObj("TTable"); + table.Init(table_node); + [err1, beg_cell] := CoordinatesToCellName(col1, row1); + [err2, end_cell] := CoordinatesToCellName(col2, row2); + if err1 or err2 then return false; + table.Merge(beg_cell, end_cell, false); + return true; + End; + + Function WordSetCurrentRange(range); + Begin + TOfficeApi().Set('CurrentPosition', range); + End; + + Function WordSetFont(prop, value); + Begin + run := TOfficeApi().GetCurrentRun(); + str := 'run.font.' $ prop $ ' := ' $ '"' $ value $ '"'; + eval(&str); + run.Apply(); + return true; + End; + + Function WordSetLastTableCellProp(row, col, name, value); + Begin + table := TOfficeApi().Get('CurrentTable'); + if ifnil(table) then return false; + table_cell := table.Cell(row, col); + ctr := _wordCompTable(); + name_ := ctr[lowercase(name)]; + if ifnil(name_) then name_ := name; + str := 'table_cell.Format.' $ name_ $ ' := '; + if ifstring(value) then + str += '"' $ value $ '"'; + else + str := str $ value; + eval(&str); + return true; + End; + + Function WordSetLastTableProp(name, value); + Begin + table := TOfficeApi().Get('CurrentTable'); + if ifnil(table) then return false; + ctr := _wordCompTable(); + name_ := ctr[lowercase(name)]; + if ifnil(name_) then name_ := name; + str := 'table.Format.' $ name_ $ ' := '; + if ifstring(value) then + str += '"' $ value $ '"'; + else + str := str $ value; + eval(&str); + TOfficeApi().Set('CurrentTable', table); + return true; + End; + + Function WordSetRangeProp(name, value); + Begin + cur := TOfficeApi().GetCurrentPosition(); + if ifnil(cur) then return nil; + End; + + Function WordTemplate(data, template, fileName); + Begin + setsysparam('data', data); + docx := new TSDocxFile(); + [err, msg] := docx.OpenFile('', template); + if err then return false; + docx.ExecInnerTSL(); + if ifstring(fileName) then + begin + [err, msg] := docx.SaveAs('', fileName); + if err then return false; + end + return true; + End; + + Function WordWrite(); + Begin + docx := TOfficeApi().GetDocument(); + curParagraph := TOfficeApi().GetCurrentParagraph(); + curRun := TOfficeApi().GetCurrentRun(); + for i:=1 to PARAMCOUNT do Begin + argv := params[i]; + if ifstring( argv ) then + curRun.AddText( argv ); + else if ifnumber(argv) then + curRun.AddText('' $ argv); + else if ifarray(argv) then Begin + tbl := docx.CreateTable(argv, false, false); + tbl := docx.InsertTable(tbl, TOfficeApi().GetCurrentPosition()); + End + End + End; + + Function WordWritePicFromFile(fileName); + Begin + file_size := fileSize('', fileName); + flag := readfile(rwbinary(), '', fileName, 0, file_size, data); + if not flag then return false; + picture := TOfficeObj('TPicture'); + picture.Image := data; + docx := TOfficeApi().GetDocument(); + docx.AddPicture(picture, TOfficeApi().GetCurrentPosition()); + return true; + End; + + Function WordWriteTable(table, writeIntIndex, writeIntTitle, incIntIndex); + Begin + docx := TOfficeApi().GetDocument(); + tbl := docx.CreateTable(table, true, writeIntIndex); + table := docx.InsertTable(tbl, TOfficeApi().GetCurrentPosition()); + return true; + End; + + Function _wordCompTable(); + Begin + return array( + 'alignment': 'Alignment', + 'shadingcolor': 'Shading.Color', + 'style': 'StyleID', + 'verticalalignment': 'Valign', + 'width': 'Width', + ); + End; + + // TODO:尚未支持 + Function WordAddOleObjectFromFile(fileName, width, height); + Begin + End; + Function WordCopyPicFormatExcel(excelFileName, excelSheetName, startRow, startCol, endRow, endCol, picType); + Begin + End; + Function WordGetRangeProp(name, value); + Begin + End; + Function WordLastTableSplit(row, col, rCnt, cCnt); + Begin + End; + +End. + diff --git a/funcext/TSOffice/word/_ExcelChartCopyPic.tsf b/funcext/TSOffice/word/_ExcelChartCopyPic.tsf deleted file mode 100644 index df0734d..0000000 --- a/funcext/TSOffice/word/_ExcelChartCopyPic.tsf +++ /dev/null @@ -1,6 +0,0 @@ -Function _ExcelChartCopyPic(excelFileName, excelSheetName, chartName, Width, Height); -Begin - docx := TOfficeApi().GetDocument(); - chart := docx.CopyExcelChart(excelFileName, excelSheetName, chartName, Width, Height, TOfficeApi().GetCurrentPosition()); - return ifObj(chart); -End; \ No newline at end of file diff --git a/funcext/TSOffice/word/_WordAddOleObjectFromFile.tsf b/funcext/TSOffice/word/_WordAddOleObjectFromFile.tsf deleted file mode 100644 index 7843725..0000000 --- a/funcext/TSOffice/word/_WordAddOleObjectFromFile.tsf +++ /dev/null @@ -1,3 +0,0 @@ -Function _WordAddOleObjectFromFile(fileName, width, height); -Begin -End; \ No newline at end of file diff --git a/funcext/TSOffice/word/_WordBr.tsf b/funcext/TSOffice/word/_WordBr.tsf deleted file mode 100644 index 162c79b..0000000 --- a/funcext/TSOffice/word/_WordBr.tsf +++ /dev/null @@ -1,5 +0,0 @@ -Function _WordBr(); -Begin - TOfficeApi().GetDocument().AddLineBreak(TOfficeApi().Get('CurrentPosition')); -End; - diff --git a/funcext/TSOffice/word/_WordCopyFromExcel.tsf b/funcext/TSOffice/word/_WordCopyFromExcel.tsf deleted file mode 100644 index c910872..0000000 --- a/funcext/TSOffice/word/_WordCopyFromExcel.tsf +++ /dev/null @@ -1,34 +0,0 @@ -Function _WordCopyFromExcel(excelFileName, excelSheetName, startRow, startCol, endRow, endCol); -Begin - excel := new TSExcelFile(); - [err, msg] := excel.OpenFile('', excelFileName); - if err then return false; - total_row := excel.TotalRows(excelSheetName); - total_col := excel.TotalCols(excelSheetName); - if not total_row or not total_col then return false; - if ifnil(startRow) then - startRow := 1; - if ifnil(startCol) then - startCol := 1; - if ifnil(endRow) then - endRow := total_row; - if ifnil(endCol) then - endCol := total_col; - data := excel.GetTable(excelSheetName, - CoordinatesToCellName(startCol, startRow), - CoordinatesToCellName(endCol, endRow), - false, - false, - false); - if length(data) = 0 then return false; - //println('data={}',data); - docx := TOfficeApi().GetDocument(); - tbl := docx.CreateTable(data, false, false); - tbl.Format.Borders.Top.Val := 'dashed'; - tbl.Format.Borders.Left.Val := 'dashed'; - tbl.Format.Borders.Bottom.Val := 'dashed'; - tbl.Format.Borders.Right.Val := 'dashed'; - tbl.Format.Borders.InsideH.Val := 'dashed'; - tbl.Format.Borders.InsideV.Val := 'dashed'; - tbl := docx.InsertTable(tbl, TOfficeApi().GetCurrentPosition()); -End; diff --git a/funcext/TSOffice/word/_WordCopyPicFromExcel.tsf b/funcext/TSOffice/word/_WordCopyPicFromExcel.tsf deleted file mode 100644 index 80a9ab1..0000000 --- a/funcext/TSOffice/word/_WordCopyPicFromExcel.tsf +++ /dev/null @@ -1,3 +0,0 @@ -Function _WordCopyPicFormatExcel(excelFileName, excelSheetName, startRow, startCol, endRow, endCol, picType); -Begin -End; \ No newline at end of file diff --git a/funcext/TSOffice/word/_WordGetCurrentDocument.tsf b/funcext/TSOffice/word/_WordGetCurrentDocument.tsf deleted file mode 100644 index 2de32b1..0000000 --- a/funcext/TSOffice/word/_WordGetCurrentDocument.tsf +++ /dev/null @@ -1,4 +0,0 @@ -Function _WordGetCurrentDocument(); -Begin - return TOfficeApi().GetDocument(); -End; \ No newline at end of file diff --git a/funcext/TSOffice/word/_WordGetCurrentRange.tsf b/funcext/TSOffice/word/_WordGetCurrentRange.tsf deleted file mode 100644 index 8503ae5..0000000 --- a/funcext/TSOffice/word/_WordGetCurrentRange.tsf +++ /dev/null @@ -1,4 +0,0 @@ -Function _WordGetCurrentRange(); -Begin - return TOfficeApi().GetCurrentPosition(); -End; \ No newline at end of file diff --git a/funcext/TSOffice/word/_WordGetFont.tsf b/funcext/TSOffice/word/_WordGetFont.tsf deleted file mode 100644 index e495c26..0000000 --- a/funcext/TSOffice/word/_WordGetFont.tsf +++ /dev/null @@ -1,10 +0,0 @@ -Function _WordGetFont(prop, value); -Begin - crun := TOfficeApi().GetCurrentRun(); - node := crun.Node().FirstChildElement('w:rPr'); - rPr := TOfficeObj('TwrPr'); - rPr.InitRootNode(node); - value := rPr.Value(prop); - if not ifnil(value) then return true; - return false; -End; diff --git a/funcext/TSOffice/word/_WordGetLastRange.tsf b/funcext/TSOffice/word/_WordGetLastRange.tsf deleted file mode 100644 index 2daa3e5..0000000 --- a/funcext/TSOffice/word/_WordGetLastRange.tsf +++ /dev/null @@ -1,4 +0,0 @@ -Function _WordGetLastRange(); -Begin - return TOfficeApi().GetCurrentPosition(); -End; \ No newline at end of file diff --git a/funcext/TSOffice/word/_WordGetLastShape.tsf b/funcext/TSOffice/word/_WordGetLastShape.tsf deleted file mode 100644 index ea5ab59..0000000 --- a/funcext/TSOffice/word/_WordGetLastShape.tsf +++ /dev/null @@ -1,16 +0,0 @@ -Function _WordGetLastShape(); -Begin - node := TOfficeApi().Get('CurrentShape'); - if not ifObj(node) then return nil; - uri := 'w:r/w:drawing/wp:inline/a:graphic/a:graphicData/c:chart'; - cNode := class(TSXml).GetNode(node, uri); - if ifObj(cNode) then Begin - chart := TOfficeObj('TChart'); - chart.Init(TOfficeApi().GetDocument(), node, cNode); - return chart; - End; - - pic := TOfficeObj('TPicture'); - pic.Init(node); - return pic; -End; \ No newline at end of file diff --git a/funcext/TSOffice/word/_WordGetLastTable.tsf b/funcext/TSOffice/word/_WordGetLastTable.tsf deleted file mode 100644 index cb268cc..0000000 --- a/funcext/TSOffice/word/_WordGetLastTable.tsf +++ /dev/null @@ -1,4 +0,0 @@ -Function _WordGetLastTable(); -Begin - return TOfficeApi().Get('LastTable'); -End; \ No newline at end of file diff --git a/funcext/TSOffice/word/_WordGetLastTableCellProp.tsf b/funcext/TSOffice/word/_WordGetLastTableCellProp.tsf deleted file mode 100644 index 7a5df00..0000000 --- a/funcext/TSOffice/word/_WordGetLastTableCellProp.tsf +++ /dev/null @@ -1,12 +0,0 @@ -Function _WordGetLastTableCellProp(row, col, name, value); -Begin - table := TOfficeApi().Get('LastTable'); - if ifnil(table) then return false; - table_cell := table.Cell(row, col); - ctr := _wordCompTable(); - name_ := ctr[lowercase(name)]; - if ifnil(name_) then name_ := name; - str := 'return table_cell.Format.' $ name_ $ '"' $ value $ '"'; - value := eval(&str); - return true; -End; diff --git a/funcext/TSOffice/word/_WordGetLastTableProp.tsf b/funcext/TSOffice/word/_WordGetLastTableProp.tsf deleted file mode 100644 index 46b0520..0000000 --- a/funcext/TSOffice/word/_WordGetLastTableProp.tsf +++ /dev/null @@ -1,11 +0,0 @@ -Function _WordGetLastTableProp(name, value); -Begin - table := TOfficeApi().Get('LastTable'); - if ifnil(table) then return false; - ctr := _wordCompTable(); - name_ := ctr[lowercase(name)]; - if ifnil(name_) then name_ := name; - str := 'return table.Format.' $ name_ $ '"' $ value $ '"'; - value := eval(&str); - return true; -End; diff --git a/funcext/TSOffice/word/_WordGetRangeProp.tsf b/funcext/TSOffice/word/_WordGetRangeProp.tsf deleted file mode 100644 index 40dc9a8..0000000 --- a/funcext/TSOffice/word/_WordGetRangeProp.tsf +++ /dev/null @@ -1,3 +0,0 @@ -Function _WordGetRangeProp(name, value); -Begin -End; \ No newline at end of file diff --git a/funcext/TSOffice/word/_WordLastTableMerge.tsf b/funcext/TSOffice/word/_WordLastTableMerge.tsf deleted file mode 100644 index a7abd34..0000000 --- a/funcext/TSOffice/word/_WordLastTableMerge.tsf +++ /dev/null @@ -1,11 +0,0 @@ -Function _WordLastTableMerge(row1, col1, row2, col2); -Begin - table := TOfficeApi().Get('LastTable'); - if ifnil(table) then return false; - [err1, beg_cell] := CoordinatesToCellName(col1, row1); - [err2, end_cell] := CoordinatesToCellName(col2, row2); - if err1 or err2 then return false; - table.Merge(beg_cell, end_cell, false); - TOfficeApi().Set('LastTable', table); - return true; -End; diff --git a/funcext/TSOffice/word/_WordLastTableSplit.tsf b/funcext/TSOffice/word/_WordLastTableSplit.tsf deleted file mode 100644 index ca6dd90..0000000 --- a/funcext/TSOffice/word/_WordLastTableSplit.tsf +++ /dev/null @@ -1,3 +0,0 @@ -Function _WordLastTableSplit(row, col, rCnt, cCnt); -Begin -End; diff --git a/funcext/TSOffice/word/_WordSetCurrentRange.tsf b/funcext/TSOffice/word/_WordSetCurrentRange.tsf deleted file mode 100644 index 164e117..0000000 --- a/funcext/TSOffice/word/_WordSetCurrentRange.tsf +++ /dev/null @@ -1,4 +0,0 @@ -Function _WordSetCurrentRange(range); -Begin - TOfficeApi().Set('CurrentPosition', range); -End; diff --git a/funcext/TSOffice/word/_WordSetCurrnetRange.tsf b/funcext/TSOffice/word/_WordSetCurrnetRange.tsf deleted file mode 100644 index 73678f5..0000000 --- a/funcext/TSOffice/word/_WordSetCurrnetRange.tsf +++ /dev/null @@ -1,4 +0,0 @@ -Function _WordSetCurrnetRange(range); -Begin - TOfficeApi().Set('CurrentPosition', range); -End; \ No newline at end of file diff --git a/funcext/TSOffice/word/_WordSetFont.tsf b/funcext/TSOffice/word/_WordSetFont.tsf deleted file mode 100644 index c22bbe1..0000000 --- a/funcext/TSOffice/word/_WordSetFont.tsf +++ /dev/null @@ -1,8 +0,0 @@ -Function _WordSetFont(prop, value); -Begin - run := TOfficeApi().GetCurrentRun(); - str := 'run.font.' $ prop $ ' := ' $ '"' $ value $ '"'; - eval(&str); - run.Apply(); - return true; -End; diff --git a/funcext/TSOffice/word/_WordSetLastTableCellProp.tsf b/funcext/TSOffice/word/_WordSetLastTableCellProp.tsf deleted file mode 100644 index 3fbe9ac..0000000 --- a/funcext/TSOffice/word/_WordSetLastTableCellProp.tsf +++ /dev/null @@ -1,17 +0,0 @@ -Function _WordSetLastTableCellProp(row, col, name, value); -Begin - table := TOfficeApi().Get('LastTable'); - if ifnil(table) then return false; - table_cell := table.Cell(row, col); - ctr := _wordCompTable(); - name_ := ctr[lowercase(name)]; - if ifnil(name_) then name_ := name; - str := 'table_cell.Format.' $ name_ $ ' := '; - if ifstring(value) then - str += '"' $ value $ '"'; - else - str = str $ value; - eval(&str); - TOfficeApi().Set('LastTable', table); - return true; -End; diff --git a/funcext/TSOffice/word/_WordSetLastTableProp.tsf b/funcext/TSOffice/word/_WordSetLastTableProp.tsf deleted file mode 100644 index 52df9a0..0000000 --- a/funcext/TSOffice/word/_WordSetLastTableProp.tsf +++ /dev/null @@ -1,17 +0,0 @@ -Function _WordSetLastTableProp(name, value); -Begin - table := TOfficeApi().Get('LastTable'); - if ifnil(table) then return false; - ctr := _wordCompTable(); - name_ := ctr[lowercase(name)]; - if ifnil(name_) then name_ := name; - str := 'table.Format.' $ name_ $ ' := '; - if ifstring(value) then - str += '"' $ value $ '"'; - else - str = str $ value; - eval(&str); - TOfficeApi().Set('LastTable', table); - return true; -End; - diff --git a/funcext/TSOffice/word/_WordSetRangeProp.tsf b/funcext/TSOffice/word/_WordSetRangeProp.tsf deleted file mode 100644 index e382cc1..0000000 --- a/funcext/TSOffice/word/_WordSetRangeProp.tsf +++ /dev/null @@ -1,5 +0,0 @@ -Function _WordSetRangeProp(name, value); -Begin - cur := TOfficeApi().GetCurrentPosition(); - if ifnil(cur) then return nil; -End; diff --git a/funcext/TSOffice/word/_WordTemplate.tsf b/funcext/TSOffice/word/_WordTemplate.tsf deleted file mode 100644 index bf862a7..0000000 --- a/funcext/TSOffice/word/_WordTemplate.tsf +++ /dev/null @@ -1,14 +0,0 @@ -Function _WordTemplate(data, template, fileName); -Begin - setsysparam('data', data); - docx := new TSDocxFile(); - [err, msg] := docx.OpenFile('', template); - if err then return false; - docx.ExecInnerTSL(); - if ifstring(fileName) then - begin - [err, msg] := docx.SaveAs('', fileName); - if err then return false; - end - return true; -End; diff --git a/funcext/TSOffice/word/_WordWrite.tsf b/funcext/TSOffice/word/_WordWrite.tsf deleted file mode 100644 index d515d57..0000000 --- a/funcext/TSOffice/word/_WordWrite.tsf +++ /dev/null @@ -1,17 +0,0 @@ -Function _WordWrite(); -Begin - docx := TOfficeApi().GetDocument(); - curParagraph := TOfficeApi().GetCurrentParagraph(); - curRun := TOfficeApi().GetCurrentRun(); - for i:=1 to PARAMCOUNT do Begin - argv := params[i]; - if ifstring( argv ) then - curRun.AddText( argv ); - else if ifnumber(argv) then - curRun.AddText('' $ argv); - else if ifarray(argv) then Begin - tbl := docx.CreateTable(argv, false, false); - tbl := docx.InsertTable(tbl, TOfficeApi().GetCurrentPosition()); - End - End -End; \ No newline at end of file diff --git a/funcext/TSOffice/word/_WordWritePicFromFile.tsf b/funcext/TSOffice/word/_WordWritePicFromFile.tsf deleted file mode 100644 index 1620f76..0000000 --- a/funcext/TSOffice/word/_WordWritePicFromFile.tsf +++ /dev/null @@ -1,11 +0,0 @@ -Function _WordWritePicFromFile(fileName); -Begin - file_size := fileSize('', fileName); - flag := readfile(rwbinary(), '', fileName, 0, file_size, data); - if not flag then return false; - picture := TOfficeObj('TPicture'); - picture.Image := data; - docx := TOfficeApi().GetDocument(); - docx.AddPicture(picture, TOfficeApi().GetCurrentPosition()); - return true; -End; diff --git a/funcext/TSOffice/word/_WordWriteTable.tsf b/funcext/TSOffice/word/_WordWriteTable.tsf deleted file mode 100644 index 4cf3581..0000000 --- a/funcext/TSOffice/word/_WordWriteTable.tsf +++ /dev/null @@ -1,8 +0,0 @@ -Function _WordWriteTable(table, writeIntIndex, writeIntTitle, incIntIndex); -Begin - docx := TOfficeApi().GetDocument(); - tbl := docx.CreateTable(table, true, writeIntIndex); - table := docx.InsertTable(tbl, TOfficeApi().GetCurrentPosition()); - TOfficeApi().Set('LastTable', table); - return true; -End; diff --git a/funcext/TSOffice/word/_wordCompTable.tsf b/funcext/TSOffice/word/_wordCompTable.tsf deleted file mode 100644 index b58a7ea..0000000 --- a/funcext/TSOffice/word/_wordCompTable.tsf +++ /dev/null @@ -1,10 +0,0 @@ -Function _wordCompTable(); -Begin - return array( - 'alignment': 'Alignment', - 'shadingcolor': 'Shading.Color', - 'style': 'StyleID', - 'verticalalignment': 'Valign', - 'width': 'Width', - ); -End; diff --git a/funcext/TSOffice/word/create.tsf b/funcext/TSOffice/word/create.tsf deleted file mode 100644 index 7af5431..0000000 --- a/funcext/TSOffice/word/create.tsf +++ /dev/null @@ -1,26 +0,0 @@ -_WordTemplate(alias, fileName); -_WordCopyFromExcel(excelFileName, excelSheetName, startRow, startCol, endRow, endCol); -_WordCopyPicFromExcel(excelFileName, excelSheetName, startRow, startCol, endRow, endCol, picType); -_ExcelChartCopyPic(excelFileName, excelSheetName, picType); -_WordGetCurrentDocument(); -_WordGetCurrentRange(); -_WordSetCurrnetRange(range); -_WordGetLastRange(); -_WordGetLastTable(); -_WordGetLastShape(); -_WordWrite(); -_WordBr(); -_WordWriteTable(table, writeIntIndex, writeIntTile, incIntIndex); -_WordWritePicFromFile(fileName); -_WordSetFont(prop, value); -_WordGetFont(prop, value); -_WordAddOleObjectFromFile(fileName, width, height); -_WordLastTableSplit(row, col, rCnt, cCnt); -_WordLastTableMerge(row1, col1, row2, col2); -_WordSetRangeProp(name, value); -_WordGetRangeProp(name, value); -_WordSetLastTableProp(name, value); -_WordGetLastTableProp(name, value); -_WordSetLastTableCellProp(row, col, name, value); -_WordGetLastTableCellProp(row, col, name, value); -