diff --git a/Demo/ExcelHelp.tsl b/Demo/ExcelHelp.tsl index 044894b..f43688c 100644 --- a/Demo/ExcelHelp.tsl +++ b/Demo/ExcelHelp.tsl @@ -666,7 +666,8 @@ style.Protection.Lock := 1; ('attrName': 'Scale', 'type': 'int', 'desc': '缩放比例(%)', 'value': array()), ('attrName': 'FitToWidth', 'type': 'int', 'desc': '页宽', 'value': array()), ('attrName': 'FitToHeight', 'type': 'int', 'desc': '页高', 'value': array()), - ('attrName': 'FirstPageNumber', 'type': 'int', 'desc': '起始页码', 'value': array()), + ('attrName': 'UseFirstPageNumber', 'type': 'bool', 'desc': '是否启用起始页码', 'value': array()), + ('attrName': 'FirstPageNumber', 'type': 'int', 'desc': '起始页码,{UseFirstPageNumber}为true时有效', 'value': array()), ('attrName': 'Orientation', 'type': 'string', 'desc': '纸张方向', 'value': array('"landscape": 横向', '"portrait": 纵向')), ('attrName': 'PageOrder', 'type': 'string', 'desc': '打印顺序', 'value': array('nil(默认): 先列后行', '"overThenDown": 先行后列')), ('attrName': 'BlackAndWhite', 'type': 'boolean', 'desc': '单色打印', 'value': array()), @@ -766,7 +767,7 @@ style.Protection.Lock := 1; ('attrName': 'RefMode', 'type': 'string', 'desc': 'R1C1引用样式', 'value': array('nil(默认): 不启用', '"R1C1": 启用R1C1引用样式')), ('attrName': 'Iterate', 'type': 'bool', 'desc': '是否启用迭代计算', 'value': array()), ('attrName': 'IterateCount', 'type': 'int', 'desc': '最多迭代次数', 'value': array()), - ('attrName': 'IterateDelta', 'type': 'double', 'desc': '最大误差,需要使用科学计数法,如0.002时为2E-3', 'value': array()), + ('attrName': 'IterateDelta', 'type': 'double', 'desc': '最大误差', 'value': array()), ('attrName': 'CalcOnSave', 'type': 'bool', 'desc': '保存工作簿之前重新计算,{CalcMode}为"manual"时有效', 'value': array()), ('attrName': 'ConCurrentCalc', 'type': 'bool', 'desc': '是否启用多线程计算', 'value': array()), ('attrName': 'ConCurrentManualCount', 'type': 'int', 'desc': '自定义计算线程数', 'value': array()), diff --git a/ExcelFile使用帮助.xlsx b/ExcelFile使用帮助.xlsx index 5bafd2c..981fbfd 100644 Binary files a/ExcelFile使用帮助.xlsx and b/ExcelFile使用帮助.xlsx differ diff --git a/funcext/TSOffice/TOfficeObj.tsf b/funcext/TSOffice/TOfficeObj.tsf index c303d86..1d9981c 100644 --- a/funcext/TSOffice/TOfficeObj.tsf +++ b/funcext/TSOffice/TOfficeObj.tsf @@ -1,4 +1,4 @@ -// Version 1.2.0 +// Version 1.2.1 Function TOfficeObj(n); Begin @@ -1257,7 +1257,6 @@ type TShapeFormat=class(NodeInfo) Function AddText(text); Begin o := new TaP(self, "a:p"); - o.R.T := text; o.R.Rpr.Lang := "en-US"; o.R.Rpr.AltLang := "zh-CN"; o.R.Rpr.SZ := 2400; @@ -4192,12 +4191,6 @@ type TMargins=class(NodeInfo) Function Init(); Begin - left := 0.75; - right := 0.75; - top := 0.75; - bottom := 0.75; - header := 0.5; - footer := 0.5; //TODO... End; @@ -4206,10 +4199,88 @@ type TMargins=class(NodeInfo) RootObj := node; End; + Property Left read readXMLLeft write writeXMLLeft; + Function readXMLLeft(); + Begin + tmpVal := class(TSXml).Utf8ToCurCodePage(Value('Left')); + if not ifNil(tmpVal) then return tmpVal; + return class(TSXml).Utf8ToCurCodePage(XMLLeft); + End; + + Function writeXMLLeft(str); + Begin + XMLLeft := class(TSXml).CurCodePageToUtf8(str); + End; + + Property Right read readXMLRight write writeXMLRight; + Function readXMLRight(); + Begin + tmpVal := class(TSXml).Utf8ToCurCodePage(Value('Right')); + if not ifNil(tmpVal) then return tmpVal; + return class(TSXml).Utf8ToCurCodePage(XMLRight); + End; + + Function writeXMLRight(str); + Begin + XMLRight := class(TSXml).CurCodePageToUtf8(str); + End; + + Property Top read readXMLTop write writeXMLTop; + Function readXMLTop(); + Begin + tmpVal := class(TSXml).Utf8ToCurCodePage(Value('Top')); + if not ifNil(tmpVal) then return tmpVal; + return class(TSXml).Utf8ToCurCodePage(XMLTop); + End; + + Function writeXMLTop(str); + Begin + XMLTop := class(TSXml).CurCodePageToUtf8(str); + End; + + Property Bottom read readXMLBottom write writeXMLBottom; + Function readXMLBottom(); + Begin + tmpVal := class(TSXml).Utf8ToCurCodePage(Value('Bottom')); + if not ifNil(tmpVal) then return tmpVal; + return class(TSXml).Utf8ToCurCodePage(XMLBottom); + End; + + Function writeXMLBottom(str); + Begin + XMLBottom := class(TSXml).CurCodePageToUtf8(str); + End; + + Property Header read readXMLHeader write writeXMLHeader; + Function readXMLHeader(); + Begin + tmpVal := class(TSXml).Utf8ToCurCodePage(Value('Header')); + if not ifNil(tmpVal) then return tmpVal; + return class(TSXml).Utf8ToCurCodePage(XMLHeader); + End; + + Function writeXMLHeader(str); + Begin + XMLHeader := class(TSXml).CurCodePageToUtf8(str); + End; + + Property Footer read readXMLFooter write writeXMLFooter; + Function readXMLFooter(); + Begin + tmpVal := class(TSXml).Utf8ToCurCodePage(Value('Footer')); + if not ifNil(tmpVal) then return tmpVal; + return class(TSXml).Utf8ToCurCodePage(XMLFooter); + End; + + Function writeXMLFooter(str); + Begin + XMLFooter := class(TSXml).CurCodePageToUtf8(str); + End; + Function GetAttrs(); override; Begin HandleAttrs(); - return array(("Left", "left", Left, ""),("Right", "right", Right, ""),("Top", "top", Top, ""),("Bottom", "bottom", Bottom, ""),("Header", "header", Header, ""),("Footer", "footer", Footer, "")) union ExtAttr; + return array(("Left", "left", XMLLeft, ""),("Right", "right", XMLRight, ""),("Top", "top", XMLTop, ""),("Bottom", "bottom", XMLBottom, ""),("Header", "header", XMLHeader, ""),("Footer", "footer", XMLFooter, "")) union ExtAttr; End; Function GetChildren(); override; @@ -4219,12 +4290,12 @@ type TMargins=class(NodeInfo) End; //Attributes - Left; - Right; - Top; - Bottom; - Header; - Footer; + XMLLeft; + XMLRight; + XMLTop; + XMLBottom; + XMLHeader; + XMLFooter; //Nodes End; @@ -14486,4 +14557,3 @@ private End - diff --git a/funcext/TSOffice/TSDocxFile.tsf b/funcext/TSOffice/TSDocxFile.tsf index 601aea6..96635ea 100644 --- a/funcext/TSOffice/TSDocxFile.tsf +++ b/funcext/TSOffice/TSDocxFile.tsf @@ -1,4 +1,4 @@ -// Version 1.2.0 +// Version 1.2.1 Type TSDocxFile = Class ///Version: V1.0 2022-09-20 diff --git a/funcext/TSOffice/TSExcelFile.tsf b/funcext/TSOffice/TSExcelFile.tsf index 7585455..d9dbcab 100644 --- a/funcext/TSOffice/TSExcelFile.tsf +++ b/funcext/TSOffice/TSExcelFile.tsf @@ -1,4 +1,4 @@ -// Version 1.2.0 +// Version 1.2.1 Type TSExcelFile = Class ///Version: V1.0 2022-08-08 @@ -620,8 +620,7 @@ Type TSExcelFile = Class ///margins: TMargins 对象 Function SetPageMargins(sheet, margins); Begin - o := getOj(sheet, 'xlsxMargins'); - if ifObj(o) then o.SetPageMargins(margins); + return workbook_.SetPageMargins(class(TSXml).CurCodePageToUtf8(sheet), margins); End; ///获取工作表页边距 @@ -629,9 +628,7 @@ Type TSExcelFile = Class ///返回: TMargins对象 Function GetPageMargins(sheet); Begin - o := getOj(sheet, 'xlsxMargins'); - if ifObj(o) then return o.GetPageMargins(); - return "sheet error"; + return workbook_.GetPageMargins(class(TSXml).CurCodePageToUtf8(sheet)); End; ///合并单元格 @@ -928,8 +925,6 @@ private return class(xlsxChart).NewObject(sheetname, self);//不缓存xlsxChart对象 'xlsxHeaderFooter': o := class(xlsxHeaderFooter).NewObject(sheetname, self); - 'xlsxMargins': - o := class(xlsxMargins).NewObject(sheetname, self); 'xlsxSheetView': o := class(xlsxSheetView).NewObject(sheetname, self); 'xlsxPageLayout': diff --git a/funcext/TSOffice/worksheet/xlsxHyperLink.tsf b/funcext/TSOffice/worksheet/xlsxHyperLink.tsf index 6184efb..63b8390 100644 --- a/funcext/TSOffice/worksheet/xlsxHyperLink.tsf +++ b/funcext/TSOffice/worksheet/xlsxHyperLink.tsf @@ -24,7 +24,7 @@ Type xlsxHyperLink = Class while ifObj(node) do begin ref := node.GetAttribute('ref'); if ref = axis then begin - node := hyperlinks.DeleteChild(node); + hyperlink_node := node; break; end; node := node.NextElement(); @@ -48,7 +48,14 @@ Type xlsxHyperLink = Class End hyperlink.RId := 'rId' + inttostr(rid); end - hyperlinks.InsertEndChild(hyperlink.marshal()); + if not ifObj(hyperlink_node) then + begin + hyperlinks.InsertEndChild(hyperlink.marshal()); + end + else begin + marshal := hyperlink.Marshal(); + class(TSXml).UpdateNode(node, marshal['attributes'], marshal['children']); + end End; Function GetCellHyperLink(axis); diff --git a/funcext/TSOffice/worksheet/xlsxMargins.tsf b/funcext/TSOffice/worksheet/xlsxMargins.tsf deleted file mode 100644 index 02f26e2..0000000 --- a/funcext/TSOffice/worksheet/xlsxMargins.tsf +++ /dev/null @@ -1,41 +0,0 @@ -Type xlsxMargins = Class - Function Create(sheetobj, file, xml); overload; - Begin - sheet_ := sheetobj; - file_ := file; - xmlFile_ := xml; - End; - - Function SetPageMargins(margins); - Begin - marshal := margins.Marshal(); - work_node := xmlFile_.FirstChild('worksheet'); - node := work_node.FirstChild('pageMargins'); - if ifObj(node) then work_node.DeleteChild(node); - sheet_node := work_node.FirstChild('sheetData'); - phone_node := work_node.FirstChild('phoneticPr'); - prev_node := ifObj(phone_node) ? phone_node : sheet_node; - work_node.InsertAfterChild(prev_node, marshal); - End; - - Function GetPageMargins(); - Begin - node := xmlFile_.FirstChild('worksheet').FirstChild('pageMargins'); - margins := TOfficeObj('tmargins'); - margins.RootObj := node; - return margins; - End - - class Function NewObject(sheetname, file); - Begin - o := file.WorkBook().GetSheetObj(sheetname); - xml := file.WorkBook().GetSheetXmlfile(sheetname); - if not ifObj(o) then return 0; - return new xlsxMargins(o, file, xml); - End; - -private - file_; //TSExcelFile对象 - sheet_;//XmlSheet对象 - xmlFile_; //sheet对应的xml对象 -End; diff --git a/funcext/TSOffice/worksheet/xlsxPageLayout.tsf b/funcext/TSOffice/worksheet/xlsxPageLayout.tsf index b052568..85daa6f 100644 --- a/funcext/TSOffice/worksheet/xlsxPageLayout.tsf +++ b/funcext/TSOffice/worksheet/xlsxPageLayout.tsf @@ -8,28 +8,22 @@ Type xlsxPageLayout = Class Function SetPageLayout(sheet, pageLayout); Begin - if ifint(pageLayout.FirstPageNumber) then pageLayout.UseFirstPageNumber := True; marshal := pageLayout.Marshal(); work_node := xmlFile_.FirstChild('worksheet'); - node := work_node.FirstChild('pageSetUp'); - if ifObj(node) then work_node.DeleteChild(node); - arr := array('sheetData', 'mergeCells', 'phoneticPr', 'pageMargins'); - for i:=length(arr)-1 to 0 do + node := work_node.FirstChild('pageSetup'); + if not ifObj(node) then begin - node := work_node.FirstChild(arr[i]); - if ifObj(node) then - begin - work_node.InsertAfterChild(node, marshal); - flag := 1; - end + prev_node := class(TSXml).GetWorkSheetPrevNode(work_node, 'pageSetup'); + node := work_node.InsertAfterChild(prev_node, marshal); + end + else begin + class(TSXml).UpdateNode(node, marshal['attributes'], marshal['children']); end - if not flag then - work_node.InsertEndChild(marshal); End; Function GetPageLayout(); Begin - node := xmlFile_.FirstChild('worksheet').FirstChild('pageSetUp'); + node := xmlFile_.FirstChild('worksheet').FirstChild('pageSetup'); page_layout := TOfficeObj('TPageLayout'); page_layout.RootObj := node; return page_layout; diff --git a/funcext/TSOffice/worksheet/xlsxSheetView.tsf b/funcext/TSOffice/worksheet/xlsxSheetView.tsf index 8d076fb..26f708e 100644 --- a/funcext/TSOffice/worksheet/xlsxSheetView.tsf +++ b/funcext/TSOffice/worksheet/xlsxSheetView.tsf @@ -15,11 +15,6 @@ Type xlsxSheetView = Class id := sheet_view_node.GetAttribute('workbookViewId'); if trystrtoint(id, r) and r = windowsIndex then Begin - attributes := sheet_view_node.Attributes(); - sheetView.TabSelected := attributes['tabselected']; - sheetView.WorkbookViewId := attributes['workbookViewId']; - sheetView.ZoomScaleNormal := ZoomScale; - for k, v in attributes do sheet_view_node.DeleteAttribute(k); marshal := SheetView.Marshal(); class(TSXml).UpdateNode(sheet_view_node, marshal['attributes'], array()); return ''; diff --git a/funcext/TSOffice/worksheet/xlsxWorkBook.tsf b/funcext/TSOffice/worksheet/xlsxWorkBook.tsf index 8000fff..bf9bbf1 100644 --- a/funcext/TSOffice/worksheet/xlsxWorkBook.tsf +++ b/funcext/TSOffice/worksheet/xlsxWorkBook.tsf @@ -1298,8 +1298,8 @@ Type xlsxWorkBook = Class style_xml := GetXmlFileObj('xl/styles.xml'); fonts_node := style_xml.FirstChildElement('styleSheet').FirstChildElement('fonts'); first_node := fonts_node.FirstChildElement('font'); - fonts_node.DeleteChild(first_node); - fonts_node.InsertFirstChild(font.Marshal()); + marshal := font.Marshal(); + class(TSXml).UpdateNode(first_node, marshal['attributes'], marshal['children']); End; Function GetDefaultFont(); @@ -1317,10 +1317,8 @@ Type xlsxWorkBook = Class workbook_xml := GetXmlFileObj('xl/workbook.xml'); workbook_node := workbook_xml.FirstChildElement('workbook'); calc_node := workbook_node.FirstChildElement('calcPr'); - sheet_node := workbook_node.FirstChildElement('sheets'); - if ifObj(calc_node) then workbook_node.DeleteChild(calc_node); - calcPr.calcId := "191029"; - workbook_node.InsertAfterChild(sheet_node, calcPr.Marshal()); + marshal := calcPr.Marshal(); + class(TSXml).UpdateNode(calc_node, marshal['attributes'], marshal['children']); End; Function GetCalcOptions(); @@ -1332,6 +1330,29 @@ Type xlsxWorkBook = Class return calcPr; End; + Function SetPageMargins(sheet, margins); + Begin + sheet_xml := GetSheetXmlFile(sheet); + work_node := sheet_xml.FirstChild('worksheet'); + node := work_node.FirstChild('pageMargins'); + if not ifObj(node) then + begin + prev_node := class(TSXml).GetWorkSheetPrevNode(work_node, 'pageMargins'); + node := work_node.InsertAfterChild(prev_node, 'element', 'pageMargins'); + end + marshal := margins.Marshal(); + class(TSXml).UpdateNode(node, marshal['attributes'], marshal['children']); + End; + + Function GetPageMargins(sheet); + Begin + sheet_xml := GetSheetXmlFile(sheet); + node := sheet_xml.FirstChild('worksheet').FirstChild('pageMargins'); + margins := TOfficeObj('tmargins'); + margins.RootObj := node; + return margins; + End + private Function generateRow(c1, c2, r); Begin diff --git a/更新日志.md b/更新日志.md index a3f873b..5732bfc 100644 --- a/更新日志.md +++ b/更新日志.md @@ -1,5 +1,13 @@ # 更新日志 +## 2023-2-24 + +### V1.2.1 + +#### excel + +1. Get相关方法重新Set后不再覆盖原有设置,影响方法如下`Set(Get)PageMargins`,`Set(Get)CellHyperLink`,`Set(Get)PageLayout`,`Set(Get)CalcOptions`,`Set(Get)DefaultFont`,`Set(Get)SheetViewOptions` + ## 2023-2-23 ### V1.2.0