diff --git a/Demo/ExcelHelp.tsl b/Demo/ExcelHelp.tsl index 1d48eac..548f55d 100644 --- a/Demo/ExcelHelp.tsl +++ b/Demo/ExcelHelp.tsl @@ -125,7 +125,7 @@ Begin row++; hyperlink := TOfficeObj('THyperLink'); - hyperlink.LinkType := "Location"; + hyperlink.LinkType := "location"; hyperlink.LinkUrl := "Functions!" $ c1; file.SetCellHyperLink("ExcelFile", cell1, hyperlink); @@ -693,10 +693,9 @@ style.Protection.Lock := 1; ('ObjName': 'THyperLink', 'Desc': ('THyperLink有以下属性: '), 'AttrInfo': ( - ('attrName': 'LinkType', 'type': 'string', 'desc': '超链接类型', 'value': array('"External": 外部超链接', '"Location"': 内部超链接)), + ('attrName': 'LinkType', 'type': 'string', 'desc': '超链接类型', 'value': array('"external": 外部超链接', '"location"': 内部超链接)), ('attrName': 'LinkUrl', 'type': 'string', 'desc': '超链接地址', 'value': array()), ('attrName': 'Tooltip', 'type': 'string', 'desc': '超链接悬浮提示内容', 'value': array()), - ('attrName': 'Display', 'type': 'string', 'desc': '单元格显示的内容', 'value': array()), ), 'Demo': '', ), diff --git a/Demo/wordHelp.tsl b/Demo/wordHelp.tsl index 50e7f42..3d01418 100644 --- a/Demo/wordHelp.tsl +++ b/Demo/wordHelp.tsl @@ -1,3 +1,4 @@ +///Version:V1.03 ///Create by Tinysoft. ///自动生成 TSDocxFile 帮助文件 mtic; @@ -68,7 +69,7 @@ v := docx.SaveAs('', UTF8ToAnsi('DocxFile使用帮助.docx')); println('Test Over!\n Save {}: {},time={}秒', file, v, mtoc); //info := GetProfilerInfo(true); -//exportfile(ftstream(),'','f:\\temp\\ProfilerInfo.stm',info); +//exportfile(ftstream(),'','\\temp\\ProfilerInfo.stm',info); /////////////////////////////////////////////////////////////////////////////////////////////// ///子函数 @@ -956,8 +957,8 @@ Begin r := select thisrowindex+1 as 'row' from data where [1] = key end; begRow := r[0]['row']; endRow := r[length(r)-1]['row']; - [err, begCell] := xlsx_call("CoordinatesToCellName", 2, begRow); - [err, endCell] := xlsx_call("CoordinatesToCellName", 2, endRow); + [err, begCell] := CoordinatesToCellName(2, begRow); + [err, endCell] := CoordinatesToCellName(2, endRow); tbl.Merge(begCell, endCell, true); //设置合并单元格据中对齐 diff --git a/DocxFile使用帮助.docx b/DocxFile使用帮助.docx index d1a7c2e..0fa8cce 100644 Binary files a/DocxFile使用帮助.docx and b/DocxFile使用帮助.docx differ diff --git a/ExcelFile使用帮助.xlsx b/ExcelFile使用帮助.xlsx index bc64339..6423e22 100644 Binary files a/ExcelFile使用帮助.xlsx and b/ExcelFile使用帮助.xlsx differ diff --git a/Linux-aarch64/libTsXlsx.so b/Linux-aarch64/libTsXlsx.so deleted file mode 100644 index 1ec0439..0000000 Binary files a/Linux-aarch64/libTsXlsx.so and /dev/null differ diff --git a/Linux-aarch64/liboffice_plugin.so b/Linux-aarch64/liboffice_plugin.so index 081ee38..6c4ca59 100644 Binary files a/Linux-aarch64/liboffice_plugin.so and b/Linux-aarch64/liboffice_plugin.so differ diff --git a/Linux-x86_64/libTsXlsx.so b/Linux-x86_64/libTsXlsx.so deleted file mode 100644 index 0cb8079..0000000 Binary files a/Linux-x86_64/libTsXlsx.so and /dev/null differ diff --git a/Linux-x86_64/liboffice_plugin.so b/Linux-x86_64/liboffice_plugin.so index d54aa2f..1c98a02 100644 Binary files a/Linux-x86_64/liboffice_plugin.so and b/Linux-x86_64/liboffice_plugin.so differ diff --git a/README.md b/README.md index 23997eb..b3681b1 100644 --- a/README.md +++ b/README.md @@ -10,14 +10,12 @@ TSOffice 项目:纯 TSL 代码实现 excel、word 文件读写 - `fmt_pubkrnl_plugin` 放入 tsl 安装根目录下 Plugin 文件夹 - `office_plugin` 放入 tsl 安装根目录下 Plugin 文件夹 -- `tsxlsx.dll` 放入 tsl 安装根目录 ### Linux 根据架构选择aarch64或x86版本将对应文件夹内容进行部署 - `liboffice_plugin` 放入 tsl 安装根目录下 Plugin 文件夹 -- `libTsXlsx` 放入 tsl 安装根目录 ## 帮助文档 diff --git a/Windows-X64/office_plugin.dll b/Windows-X64/office_plugin.dll index 58aa296..e69f938 100644 Binary files a/Windows-X64/office_plugin.dll and b/Windows-X64/office_plugin.dll differ diff --git a/Windows-X64/tsxlsx.dll b/Windows-X64/tsxlsx.dll deleted file mode 100644 index 4495967..0000000 Binary files a/Windows-X64/tsxlsx.dll and /dev/null differ diff --git a/funcext/TSOffice/TOfficeObj.tsf b/funcext/TSOffice/TOfficeObj.tsf index 0f8ea38..f9deab7 100644 --- a/funcext/TSOffice/TOfficeObj.tsf +++ b/funcext/TSOffice/TOfficeObj.tsf @@ -1,4 +1,5 @@ -// Version 1.0.4 +// Version 1.0.5 + Function TOfficeObj(n); Begin case lowercase(n) of @@ -410,6 +411,20 @@ type TComment=class(NodeInfo) //TODO... End; + Property Text read readCommentText write writeCommentText; + Function readCommentText(); + Begin + if ifObj(Root()) then + return class(xlsxXml).Utf8ToCurCodePage(Value('CommentText')); + else + return CommentText; + End; + + Function writeCommentText(str); + Begin + CommentText := class(xlsxXml).CurCodePageToUtf8(str); + End; + Function GetAttrs(); override; Begin HandleAttrs(); @@ -420,7 +435,7 @@ type TComment=class(NodeInfo) Begin HandleChildren(); return array(("field":"Font","name":Font.NodeName,"obj":Font,"attrEx":"","nodeType":"","attrName":"", "desc":"", "class":"TFont") - ,("field":"Text","name":"t","obj":Text,"attrEx":"","nodeType":"pcdata","attrName":"", "desc":"", "class":"") + ,("field":"CommentText","name":"t","obj":CommentText,"attrEx":"","nodeType":"pcdata","attrName":"", "desc":"", "class":"") ,("field":"Space","name":"t","obj":Space,"attrEx":"xml:space","nodeType":"","attrName":"", "desc":"", "class":"") ) union ExtNodes; End; @@ -429,7 +444,7 @@ type TComment=class(NodeInfo) //Nodes Font; - Text; + CommentText; Space; End; @@ -3665,10 +3680,38 @@ type THyperLink=class(NodeInfo) //TODO... End; + Property Display read readLinkDisplay write writeLinkDisplay; + Function readLinkDisplay(); + Begin + if ifObj(Root()) then + return class(xlsxXml).Utf8ToCurCodePage(Value('LinkDisplay')); + else + return LinkDisplay; + End; + + Function writeLinkDisplay(str); + Begin + LinkDisplay := class(xlsxXml).CurCodePageToUtf8(str); + End; + + Property Tooltip read readLinkTooltip write writeLinkTooltip; + Function readLinkTooltip(); + Begin + if ifObj(Root()) then + return class(xlsxXml).Utf8ToCurCodePage(Value('LinkTooltip')); + else + return LinkTooltip; + End; + + Function writeLinkTooltip(str); + Begin + LinkTooltip := class(xlsxXml).CurCodePageToUtf8(str); + End; + Function GetAttrs(); override; Begin HandleAttrs(); - return array(("LinkType", "linkType", LinkType, ""),("Url", "linkUrl", Url, ""),("Axis", "ref", Axis, ""),("LinkDisplay", "display", LinkDisplay, ""),("LinkTooltip", "tooltip", LinkTooltip, "")) union ExtAttr; + return array(("LinkType", "linkType", LinkType, ""),("LinkUrl", "linkUrl", LinkUrl, ""),("Axis", "ref", Axis, ""),("LinkDisplay", "display", LinkDisplay, ""),("LinkTooltip", "tooltip", LinkTooltip, ""),("RId", "r:id", RId, ""),("Location", "location", Location, "")) union ExtAttr; End; Function GetChildren(); override; @@ -3677,30 +3720,14 @@ type THyperLink=class(NodeInfo) return ExtNodes; End; - Property LinkUrl read Url write writeUrl; - Function writeUrl(str); - Begin - Url := class(xlsxXml).CurCodePageToUtf8(str); - End; - - Property Display read LinkDisplay write writeLinkDisplay; - Function writeLinkDisplay(str); - Begin - LinkDisplay := class(xlsxXml).CurCodePageToUtf8(str); - End; - - Property Tooltip read LinkTooltip write writeLinkTooltip; - Function writeLinkTooltip(str); - Begin - LinkTooltip := class(xlsxXml).CurCodePageToUtf8(str); - End; - //Attributes LinkType; - Url; + LinkUrl; Axis; LinkDisplay; LinkTooltip; + RId; + Location; //Nodes End; @@ -3815,6 +3842,146 @@ type TAppProperty=class(NodeInfo) //TODO... End; + Property Application read readAppApplication write writeAppApplication; + Function readAppApplication(); + Begin + if ifObj(Root()) then + return class(xlsxXml).Utf8ToCurCodePage(Value('AppApplication')); + else + return AppApplication; + End; + + Function writeAppApplication(str); + Begin + AppApplication := class(xlsxXml).CurCodePageToUtf8(str); + End; + + Property DocSecurity read readAppDocSecurity write writeAppDocSecurity; + Function readAppDocSecurity(); + Begin + if ifObj(Root()) then + return Value('AppDocSecurity'); + else + return AppDocSecurity; + End; + + Function writeAppDocSecurity(str); + Begin + AppDocSecurity := str; + End; + + Property ScaleCrop read readAppScaleCrop write writeAppScaleCrop; + Function readAppScaleCrop(); + Begin + if ifObj(Root()) then + return Value('AppScaleCrop'); + else + return AppScaleCrop; + End; + + Function writeAppScaleCrop(str); + Begin + AppScaleCrop := str; + End; + + Property Manager read readAppManager write writeAppManager; + Function readAppManager(); + Begin + if ifObj(Root()) then + return Value('AppManager'); + else + return AppManager; + End; + + Function writeAppManager(str); + Begin + AppManager := str; + End; + + Property Company read readAppCompany write writeAppCompany; + Function readAppCompany(); + Begin + if ifObj(Root()) then + return Value('AppCompany'); + else + return AppCompany; + End; + + Function writeAppCompany(str); + Begin + AppCompany := str; + End; + + Property LinksUpToDate read readAppLinksUpToDate write writeAppLinksUpToDate; + Function readAppLinksUpToDate(); + Begin + if ifObj(Root()) then + return Value('AppLinksUpToDate'); + else + return AppLinksUpToDate; + End; + + Function writeAppLinksUpToDate(str); + Begin + AppLinksUpToDate := str; + End; + + Property SharedDoc read readAppSharedDoc write writeAppSharedDoc; + Function readAppSharedDoc(); + Begin + if ifObj(Root()) then + return Value('AppSharedDoc'); + else + return AppSharedDoc; + End; + + Function writeAppSharedDoc(str); + Begin + AppSharedDoc := str; + End; + + Property HyperlinkBase read readAppHyperlinkBase write writeAppHyperlinkBase; + Function readAppHyperlinkBase(); + Begin + if ifObj(Root()) then + return class(xlsxXml).Utf8ToCurCodePage(Value('AppHyperlinkBase')); + else + return AppHyperlinkBase; + End; + + Function writeAppHyperlinkBase(str); + Begin + AppHyperlinkBase := class(xlsxXml).CurCodePageToUtf8(str); + End; + + Property HyperlinksChanged read readAppHyperlinksChanged write writeAppHyperlinksChanged; + Function readAppHyperlinksChanged(); + Begin + if ifObj(Root()) then + return Value('AppHyperlinksChanged'); + else + return AppHyperlinksChanged; + End; + + Function writeAppHyperlinksChanged(str); + Begin + AppHyperlinksChanged := str; + End; + + Property Version read readAppVersion write writeAppVersion; + Function readAppVersion(); + Begin + if ifObj(Root()) then + return class(xlsxXml).Utf8ToCurCodePage(Value('AppVersion')); + else + return AppVersion; + End; + + Function writeAppVersion(str); + Begin + AppVersion := class(xlsxXml).CurCodePageToUtf8(str); + End; + Function GetAttrs(); override; Begin HandleAttrs(); @@ -3825,54 +3992,30 @@ type TAppProperty=class(NodeInfo) Begin HandleChildren(); return array(("field":"AppApplication","name":"Application","obj":AppApplication,"attrEx":"","nodeType":"pcdata","attrName":"", "desc":"", "class":"") - ,("field":"DocSecurity","name":"DocSecurity","obj":DocSecurity,"attrEx":"","nodeType":"pcdata","attrName":"", "desc":"", "class":"") - ,("field":"ScaleCrop","name":"ScaleCrop","obj":ScaleCrop,"attrEx":"","nodeType":"pcdata","attrName":"", "desc":"", "class":"") + ,("field":"AppDocSecurity","name":"DocSecurity","obj":AppDocSecurity,"attrEx":"","nodeType":"pcdata","attrName":"", "desc":"", "class":"") + ,("field":"AppScaleCrop","name":"ScaleCrop","obj":AppScaleCrop,"attrEx":"","nodeType":"pcdata","attrName":"", "desc":"", "class":"") ,("field":"AppManager","name":"Manager","obj":AppManager,"attrEx":"","nodeType":"pcdata","attrName":"", "desc":"", "class":"") ,("field":"AppCompany","name":"Company","obj":AppCompany,"attrEx":"","nodeType":"pcdata","attrName":"", "desc":"", "class":"") - ,("field":"LinksUpToDate","name":"LinksUpToDate","obj":LinksUpToDate,"attrEx":"","nodeType":"pcdata","attrName":"", "desc":"", "class":"") - ,("field":"SharedDoc","name":"SharedDoc","obj":SharedDoc,"attrEx":"","nodeType":"pcdata","attrName":"", "desc":"", "class":"") + ,("field":"AppLinksUpToDate","name":"LinksUpToDate","obj":AppLinksUpToDate,"attrEx":"","nodeType":"pcdata","attrName":"", "desc":"", "class":"") + ,("field":"AppSharedDoc","name":"SharedDoc","obj":AppSharedDoc,"attrEx":"","nodeType":"pcdata","attrName":"", "desc":"", "class":"") ,("field":"AppHyperlinkBase","name":"HyperlinkBase","obj":AppHyperlinkBase,"attrEx":"","nodeType":"pcdata","attrName":"", "desc":"", "class":"") - ,("field":"HyperlinksChanged","name":"HyperlinksChanged","obj":HyperlinksChanged,"attrEx":"","nodeType":"pcdata","attrName":"", "desc":"", "class":"") + ,("field":"AppHyperlinksChanged","name":"HyperlinksChanged","obj":AppHyperlinksChanged,"attrEx":"","nodeType":"pcdata","attrName":"", "desc":"", "class":"") ,("field":"AppVersion","name":"AppVersion","obj":AppVersion,"attrEx":"","nodeType":"pcdata","attrName":"", "desc":"", "class":"") ) union ExtNodes; End; - Property Application read AppApplication write writeAppApplication; - Function writeAppApplication(str); - Begin - AppApplication := class(xlsxXml).CurCodePageToUtf8(str); - End; - - Property Manager read AppManager write writeAppManager; - Function writeAppManager(str); - Begin - AppManager := class(xlsxXml).CurCodePageToUtf8(str); - End; - - Property Company read AppCompany write writeAppCompany; - Function writeAppCompany(str); - Begin - AppCompany := class(xlsxXml).CurCodePageToUtf8(str); - End; - - Property HyperlinkBase read AppHyperlinkBase write writeAppHyperlinkBase; - Function writeAppHyperlinkBase(str); - Begin - AppHyperlinkBase := class(xlsxXml).CurCodePageToUtf8(str); - End; - //Attributes //Nodes AppApplication; - DocSecurity; - ScaleCrop; + AppDocSecurity; + AppScaleCrop; AppManager; AppCompany; - LinksUpToDate; - SharedDoc; + AppLinksUpToDate; + AppSharedDoc; AppHyperlinkBase; - HyperlinksChanged; + AppHyperlinksChanged; AppVersion; End; @@ -3896,6 +4039,132 @@ type TCoreProperty=class(NodeInfo) //TODO... End; + Property Title read readCoreTitle write writeCoreTitle; + Function readCoreTitle(); + Begin + if ifObj(Root()) then + return class(xlsxXml).Utf8ToCurCodePage(Value('CoreTitle')); + else + return CoreTitle; + End; + + Function writeCoreTitle(str); + Begin + CoreTitle := class(xlsxXml).CurCodePageToUtf8(str); + End; + + Property Subject read readCoreSubject write writeCoreSubject; + Function readCoreSubject(); + Begin + if ifObj(Root()) then + return class(xlsxXml).Utf8ToCurCodePage(Value('CoreSubject')); + else + return CoreSubject; + End; + + Function writeCoreSubject(str); + Begin + CoreSubject := class(xlsxXml).CurCodePageToUtf8(str); + End; + + Property Creator read readCoreCreator write writeCoreCreator; + Function readCoreCreator(); + Begin + if ifObj(Root()) then + return class(xlsxXml).Utf8ToCurCodePage(Value('CoreCreator')); + else + return CoreCreator; + End; + + Function writeCoreCreator(str); + Begin + CoreCreator := class(xlsxXml).CurCodePageToUtf8(str); + End; + + Property Keywords read readCoreKeywords write writeCoreKeywords; + Function readCoreKeywords(); + Begin + if ifObj(Root()) then + return class(xlsxXml).Utf8ToCurCodePage(Value('CoreKeywords')); + else + return CoreKeywords; + End; + + Function writeCoreKeywords(str); + Begin + CoreKeywords := class(xlsxXml).CurCodePageToUtf8(str); + End; + + Property Description read readCoreDescription write writeCoreDescription; + Function readCoreDescription(); + Begin + if ifObj(Root()) then + return class(xlsxXml).Utf8ToCurCodePage(Value('CoreDescription')); + else + return CoreDescription; + End; + + Function writeCoreDescription(str); + Begin + CoreDescription := class(xlsxXml).CurCodePageToUtf8(str); + End; + + Property LastModifiedBy read readCoreLastModifiedBy write writeCoreLastModifiedBy; + Function readCoreLastModifiedBy(); + Begin + if ifObj(Root()) then + return class(xlsxXml).Utf8ToCurCodePage(Value('CoreLastModifiedBy')); + else + return CoreLastModifiedBy; + End; + + Function writeCoreLastModifiedBy(str); + Begin + CoreLastModifiedBy := class(xlsxXml).CurCodePageToUtf8(str); + End; + + Property LastPrinted read readCoreLastPrinted write writeCoreLastPrinted; + Function readCoreLastPrinted(); + Begin + if ifObj(Root()) then + return class(xlsxXml).Utf8ToCurCodePage(Value('CoreLastPrinted')); + else + return CoreLastPrinted; + End; + + Function writeCoreLastPrinted(str); + Begin + CoreLastPrinted := class(xlsxXml).CurCodePageToUtf8(str); + End; + + Property Category read readCoreCategory write writeCoreCategory; + Function readCoreCategory(); + Begin + if ifObj(Root()) then + return class(xlsxXml).Utf8ToCurCodePage(Value('CoreCategory')); + else + return CoreCategory; + End; + + Function writeCoreCategory(str); + Begin + CoreCategory := class(xlsxXml).CurCodePageToUtf8(str); + End; + + Property ContentStatus read readCoreContentStatus write writeCoreContentStatus; + Function readCoreContentStatus(); + Begin + if ifObj(Root()) then + return class(xlsxXml).Utf8ToCurCodePage(Value('CoreContentStatus')); + else + return CoreContentStatus; + End; + + Function writeCoreContentStatus(str); + Begin + CoreContentStatus := class(xlsxXml).CurCodePageToUtf8(str); + End; + Function GetAttrs(); override; Begin HandleAttrs(); @@ -3917,60 +4186,6 @@ type TCoreProperty=class(NodeInfo) ) union ExtNodes; End; - Property Title read CoreTitle write writeCoreTitle; - Function writeCoreTitle(str); - Begin - CoreTitle := class(xlsxXml).CurCodePageToUtf8(str); - End; - - Property Subject read CoreSubject write writeCoreSubject; - Function writeCoreSubject(str); - Begin - CoreSubject := class(xlsxXml).CurCodePageToUtf8(str); - End; - - Property Creator read CoreCreator write writeCoreCreator; - Function writeCoreCreator(str); - Begin - CoreCreator := class(xlsxXml).CurCodePageToUtf8(str); - End; - - Property Keywords read CoreKeywords write writeCoreKeywords; - Function writeCoreKeywords(str); - Begin - CoreKeywords := class(xlsxXml).CurCodePageToUtf8(str); - End; - - Property Description read CoreDescription write writeCoreDescription; - Function writeCoreDescription(str); - Begin - CoreDescription := class(xlsxXml).CurCodePageToUtf8(str); - End; - - Property LastModifiedBy read CoreLastModifiedBy write writeCoreLastModifiedBy; - Function writeCoreLastModifiedBy(str); - Begin - CoreLastModifiedBy := class(xlsxXml).CurCodePageToUtf8(str); - End; - - Property LastPrinted read CoreLastPrinted write writeCoreLastPrinted; - Function writeCoreLastPrinted(str); - Begin - CoreLastPrinted := class(xlsxXml).CurCodePageToUtf8(str); - End; - - Property Category read CoreCategory write writeCoreCategory; - Function writeCoreCategory(str); - Begin - CoreCategory := class(xlsxXml).CurCodePageToUtf8(str); - End; - - Property ContentStatus read CoreContentStatus write writeCoreContentStatus; - Function writeCoreContentStatus(str); - Begin - CoreContentStatus := class(xlsxXml).CurCodePageToUtf8(str); - End; - //Attributes //Nodes @@ -4269,7 +4484,7 @@ type TwpPr=class(NodeInfo) Begin HandleChildren(); return array(("field":"StyleId","name":"w:pStyle","obj":StyleId,"attrEx":"w:val","nodeType":"","attrName":"", "desc":"段落样式ID", "class":"") - ,("field":"NumPr","name":NumPr.NodeName,"obj":NumPr,"attrEx":"","nodeType":"","attrName":"", "desc":"disable", "class":"TNumPr") + ,("field":"NumPr","name":NumPr.NodeName,"obj":NumPr,"attrEx":"","nodeType":"","attrName":"", "desc":"项目编号、数字编号", "class":"TNumPr") ,("field":"Alignment","name":"w:jc","obj":Alignment,"attrEx":"w:val","nodeType":"","attrName":"", "desc":"左、右、居中和对齐", "class":"") ,("field":"FirstLineChars","name":"w:ind","obj":FirstLineChars,"attrEx":"w:firstLineChars","nodeType":"","attrName":"", "desc":"字符单位中的其他首行缩进", "class":"") ,("field":"FirstLineIndent","name":"w:ind","obj":FirstLineIndent,"attrEx":"w:firstLine","nodeType":"","attrName":"", "desc":"指定段落第一行缩进的相对差异的值", "class":"") @@ -6748,9 +6963,9 @@ type TTableImpl=class(NodeInfo) End; /////////////////////////////////////////////////////////////// -/// TCoreProperties +/// TCorePropertiesImpl /////////////////////////////////////////////////////////////// -type TCoreProperties=class(NodeInfo, CoreProperties) +type TCorePropertiesImpl=class(NodeInfo) Function Create(); overload; Begin Create(nil, 'w:p'); @@ -8966,6 +9181,7 @@ Type TChart = Class(TChartImpl) End; ///显示数据表 + ///b:bool型,是否显示数据表 Function ShowDataTable(b); Begin if not ifObj(ChartNode) then @@ -9409,7 +9625,7 @@ private Val.NumRef.F := data; //excel图表(Sheet1!$C$2:$C$6) else if istable(data) then Begin //word 图表 cnt := length(data); - [err, axis] := xlsx_call("ColumnNumberToName", 2 * ind + 2); + [err, axis] := ColumnNumberToName(2 * ind + 2); Val.NumRef.F := fmt('Sheet1!${}$2:${}${}',axis, axis, cnt+1); Val.NumRef.NumCache.PtCount := cnt; Val.NumRef.NumCache.formatCode := 'General'; @@ -9435,7 +9651,7 @@ private cat.StrRef.F := Categories; //excel图表(Sheet1!$B$2:$B$6) else if istable(Categories) then Begin //word 图表 cnt := length(Categories); - [err, axis] := xlsx_call("ColumnNumberToName", 2 * ind + 1); + [err, axis] := ColumnNumberToName(2 * ind + 1); cat.StrRef.F := fmt('Sheet1!${}$2:${}${}',axis, axis, cnt+1); cat.StrRef.StrCache.PtCount := cnt; for i:=0 to cnt-1 do Begin @@ -11245,8 +11461,8 @@ Type TTable = Class(DocObject, TTableImpl) ///del: bool,是否删除其它单元格内容(只保留左上单元格内容) Function Merge(hCell, vCell, del);overload; Begin - [err1, left, top] := xlsx_call("CellNameToCoordinates", hCell); - [err2, right, bottom] := xlsx_call("CellNameToCoordinates", vCell); + [err1, left, top] := CellNameToCoordinates(hCell); + [err2, right, bottom] := CellNameToCoordinates(vCell); if err1 or err2 then return 'Invalid input Coordinates.'; return Merge(top, left, bottom, right, del); @@ -11334,57 +11550,64 @@ Type TCoreProperties = Class(DocObject) private Function readAuthor(); Begin - return class(xlsxXml).Utf8ToCurCodePage(class(xlsxXml).GetNode(node_, 'dc:creator')); + return propValue('dc:creator'); End; Function readCategory(); Begin - return class(xlsxXml).Utf8ToCurCodePage(class(xlsxXml).GetNode(node_, 'cp:category')); + return propValue('cp:category'); End; Function readDescription(); Begin - return class(xlsxXml).Utf8ToCurCodePage(class(xlsxXml).GetNode(node_, 'dc:description')); + return propValue('dc:description'); End; Function readSubject(); Begin - return class(xlsxXml).Utf8ToCurCodePage(class(xlsxXml).GetNode(node_, 'dc:subject')); + return propValue('dc:subject'); End; Function readTitle(); Begin - return class(xlsxXml).Utf8ToCurCodePage(class(xlsxXml).GetNode(node_, 'dc:title')); + return propValue('dc:title'); End; Function readVersion(); Begin - return class(xlsxXml).Utf8ToCurCodePage(class(xlsxXml).GetNode(node_, 'cp:version')); + return propValue('cp:version'); End; Function readRversion(); Begin - return class(xlsxXml).Utf8ToCurCodePage(class(xlsxXml).GetNode(node_, 'cp:rversion')); + return propValue('cp:rversion'); End; Function readKeyWords(); Begin - return class(xlsxXml).Utf8ToCurCodePage(class(xlsxXml).GetNode(node_, 'cp:keywords')); + return propValue('cp:keywords'); End; Function readLastModifiedBy(); Begin - return class(xlsxXml).Utf8ToCurCodePage(class(xlsxXml).GetNode(node_, 'cp:lastModifiedBy')); + return propValue('cp:lastModifiedBy'); End; Function readCreated(); Begin - return class(xlsxXml).Utf8ToCurCodePage(class(xlsxXml).GetNode(node_, 'dcterms:created')); + return propValue('dcterms:created'); End; Function readModified(); Begin - return class(xlsxXml).Utf8ToCurCodePage(class(xlsxXml).GetNode(node_, 'dcterms:modified')); + return propValue('dcterms:modified'); + End; + + Function propValue(k); + Begin + node := class(xlsxXml).GetNode(node_, k); + if not ifObj(node) then return ''; + return class(xlsxXml).Utf8ToCurCodePage( node.GetText() ); End; Function propNode(k); diff --git a/funcext/TSOffice/TSDocxFile.tsf b/funcext/TSOffice/TSDocxFile.tsf index 84a5fcd..dcb976a 100644 --- a/funcext/TSOffice/TSDocxFile.tsf +++ b/funcext/TSOffice/TSDocxFile.tsf @@ -1,4 +1,4 @@ -// Version 1.0.4 +// Version 1.0.5 Type TSDocxFile = Class ///Version: V1.0 2022-09-20 @@ -157,7 +157,6 @@ Type TSDocxFile = Class return document_.Body().TextArray(); End; - ///返回:Boby对象 Function Body(); Begin return document_.Body(); @@ -317,38 +316,23 @@ Type TSDocxFile = Class ///格式刷:复制段落格式(包括字体格式) ///fromParagraph:源段落 - Function CopyFormat(fromParagraph); - Begin - selectPrargraph_ := fromParagraph; - End; - - ///格式刷:将源段落格式(包括字体格式),刷到目标格式 ///toParagraph:目标段落 - Function PasteFormat(toParagraph); + Function CopyFormat(fromParagraph, toParagraph); Begin - pPr := ifObj(selectPrargraph_) ? selectPrargraph_.node_.FirstChildElement('w:pPr') : nil; - if not ifObj(pPr) then Begin //格式为空,清除目标段落所有格式 - toParagraph.ClearFormat();//清除段落格式、字体格式 - return; - End; - rPr := pPr.node_.FirstChildElement('w:rPr'); - - //复制段落格式 - pPr2 := toParagraph.node_.FirstChildElement('w:pPr'); - if ifObj(pPr2) then - pPr2.DeleteChildren(); - else + toParagraph.ClearFormat();//清除目标段落格式、字体格式 + pPr := ifObj(fromParagraph) ? fromParagraph.node_.FirstChildElement('w:pPr') : nil; + if ifObj(pPr) then Begin //复制段落格式 pPr2 := toParagraph.node_.InsertFirstChild('element', 'w:pPr'); - arr := pPr.Marshal(); - class(xlsxXml).UpdateNode(pPr2, arr[0]['attributes'], arr[0]['children']); - + arr := pPr.Marshal(); + class(xlsxXml).UpdateNode(pPr2, arr[0]['attributes'], arr[0]['children']); + End; //复制字体格式 - if ifObj(rPr) then - toParagraph.SetFormat(rPr, true); - else Begin //清除字体格式 + rPr := ifObj(fromParagraph) ? class(xlsxXml).GetNode(fromParagraph.node_, 'w:r/w:rPr') : nil; + if ifObj(rPr) then Begin + r := rPr.Marshal(); runs := toParagraph.GetRuns(); for i:=0 to length(runs)-1 do - runs[i].ClearFormat(); + toParagraph._copyFormat(runs[i].node_, r, false); End; End; @@ -380,7 +364,7 @@ Type TSDocxFile = Class ///返回:array((("Level":level,"Paragraph":"object","Text":title)); Function GetHeadingList(UpperHeadingLevel, LowerHeadingLevel); Begin - return document_.Body().GetHeadingListImpl(self, UpperHeadingLevel, LowerHeadingLevel, nil, true); + return document_.Body().GetHeadingListImpl(self, nil, UpperHeadingLevel, LowerHeadingLevel, nil, true); End; ///返回Document对象 @@ -420,5 +404,4 @@ private xml_; //xlsxXml对象 styleObj_; numberingObj_; - selectPrargraph_;//被选中的段落 End; diff --git a/funcext/TSOffice/TSExcelFile.tsf b/funcext/TSOffice/TSExcelFile.tsf index 1d86646..e334ffb 100644 --- a/funcext/TSOffice/TSExcelFile.tsf +++ b/funcext/TSOffice/TSExcelFile.tsf @@ -1,4 +1,4 @@ -// Version 1.0.4 +// Version 1.0.5 Type TSExcelFile = Class ///Version: V1.0 2022-08-08 @@ -38,6 +38,7 @@ Type TSExcelFile = Class ///返回: [err, errmsg] Function OpenFile(alias, fname); Begin + init(); if not ifObj(zipfile_) then return array(-1, 'Create ZipFile object fail.'); [err, errmsg] := zipfile_.Open(alias, fname); if err=0 then Begin @@ -426,16 +427,7 @@ Type TSExcelFile = Class ///返回: [err, col:string, row:int],"AK47" -> return array(0, "AK", 47); Function SplitCellName(cell); Begin - return xlsx_call("SplitCellName", cell); - End; - - ///单元格坐标组合 - ///col: string - ///row: int - ///返回 [err, cell:string],参见SplitCellName - Function JoinCellName(col, row); - Begin - return xlsx_call("JoinCellName", col, row); + return SplitCellName(cell); End; ///列名转索引 @@ -443,7 +435,7 @@ Type TSExcelFile = Class ///返回 [err, index:int],"AK" -> return array(0, 37); Function ColumnNameToNumber(name); Begin - return xlsx_call("ColumnNameToNumber", name); + return ColumnNameToNumber(name); End; ///索引转列名 @@ -451,7 +443,7 @@ Type TSExcelFile = Class ///返回 [err, name:string],37 -> return array(0, "AK"); Function ColumnNumberToName(index); Begin - return xlsx_call("ColumnNumberToName", index); + return ColumnNumberToName(index); End; ///单元格坐标转索引 @@ -459,7 +451,7 @@ Type TSExcelFile = Class ///返回 [err, col:int, row: int] "A2" -> [1,2] Function CellNameToCoordinates(cell); Begin - return xlsx_call("CellNameToCoordinates", cell); + return CellNameToCoordinates(cell); End; ///索引转单元格坐标 @@ -469,27 +461,27 @@ Type TSExcelFile = Class ///返回 [err, cell:string] [1,2,true] -> "$A$2" Function CoordinatesToCellName(col, row, abs); Begin - return xlsx_call("CoordinatesToCellName", col, row, abs); + return CoordinatesToCellName(col, row, abs); End; ///RGB与HSL色彩空间色值转换 ///r: int ///g: int ///b: int - ///返回: [err, h:double, s:double, l:double] + ///返回: [h:double, s:double, l:double] Function RGBToHSL(r, g, b); Begin - return xlsx_call("RGBToHSL", r, g, b); + return RGBToHSL(r, g, b); End; ///HSL与RGB色彩空间色值转换 ///h: double ///s: double ///l: double - ///返回: [err, r:int, g:int, b:int] - Function HSLToRGB(sheet, h, s, l); + ///返回: [r:int, g:int, b:int] + Function HSLToRGB(h, s, l); Begin - return xlsx_call("HSLToRGB", h, s, l); + return HSLToRGB(h, s, l); End; ///新建样式对象 diff --git a/funcext/TSOffice/TSUtils/xlsxXml.tsf b/funcext/TSOffice/TSUtils/xlsxXml.tsf index 251946d..9dd9706 100644 --- a/funcext/TSOffice/TSUtils/xlsxXml.tsf +++ b/funcext/TSOffice/TSUtils/xlsxXml.tsf @@ -247,8 +247,8 @@ Type xlsxXml = Class class Function GetWorkSheetPrevNode(workNode, nodeName); Begin - order_arr := array('dimension', 'sheetViews', 'sheetFormatPr', 'cols', 'sheetData', 'phoneticPr', - 'pageMargins', 'headerFooter', 'pageSetup', 'rowBreaks', 'colBreaks', 'drawing', 'legacyDrawing', 'picture'); + order_arr := array('dimension', 'sheetViews', 'sheetFormatPr', 'cols', 'sheetData', 'mergeCells', 'phoneticPr', + 'hyperlinks', 'pageMargins', 'headerFooter', 'pageSetup', 'rowBreaks', 'colBreaks', 'drawing', 'legacyDrawing', 'picture'); for i:=0 to length(order_arr)-1 do begin if order_arr[i] = nodeName then return prev; diff --git a/funcext/TSOffice/document/TNumbering.tsf b/funcext/TSOffice/document/TNumbering.tsf index 875f773..95d97f1 100644 --- a/funcext/TSOffice/document/TNumbering.tsf +++ b/funcext/TSOffice/document/TNumbering.tsf @@ -209,7 +209,7 @@ Type TNumbering = Class Function _setNsId(o); Begin v := RandomRange(1000000000,2000000000); - id := xlsx_call('tohex',v); + id := tohex(v); if hash_[id] then return _setNsId(o); hash_[id] := 1; @@ -232,4 +232,4 @@ private bullet_; numIdMap_; hash_; -End; \ No newline at end of file +End; diff --git a/funcext/TSOffice/worksheet/xlsxHyperLink.tsf b/funcext/TSOffice/worksheet/xlsxHyperLink.tsf index 0a20ae7..a179845 100644 --- a/funcext/TSOffice/worksheet/xlsxHyperLink.tsf +++ b/funcext/TSOffice/worksheet/xlsxHyperLink.tsf @@ -17,16 +17,8 @@ Type xlsxHyperLink = Class work_node := xmlFile_.FirstChildElement('worksheet'); hyperlinks := work_node.FirstChildElement('hyperlinks'); if not ifObj(hyperlinks) then begin - arr := array('phoneticPr', 'mergeCells', 'sheetData'); - for i:=0 to length(arr)-1 do - begin - insert_node := work_node.FirstChildElement(arr[i]); - if ifObj(insert_node) then - begin - hyperlinks := work_node.InsertAfterChild(insert_node, 'element', 'hyperlinks'); - break; - end - end + insert_node := class(xlsxXml).GetWorkSheetPrevNode(work_node, 'hyperlinks'); + hyperlinks := work_node.InsertAfterChild(insert_node, 'element', 'hyperlinks'); end; node := hyperlinks.FirstChildElement('hyperlink'); while ifObj(node) do begin @@ -38,11 +30,14 @@ Type xlsxHyperLink = Class node := node.NextElement(); end; hyperlink.Axis := axis; - marshal := hyperlink.Marshal(); - attrs := marshal['attributes']; - if attrs['linkType'] = "Location" then reindex(attrs, array('linkType': nil, 'linkUrl': 'location')); - else if attrs['linkType'] = "External" then - Begin + if hyperlink.LinkType = "location" then + begin + hyperlink.LinkType := nil; + hyperlink.Location := hyperlink.LinkUrl; + hyperlink.LinkUrl := nil; + end + else if hyperlink.LinkType = 'external' then + begin [rid, commentFileName, sheetFileName, relsfile] := file_.WorkBook().GetRelationshipRid(sheetName_, hyperlink.LinkUrl); if commentFileName = "" then Begin @@ -51,11 +46,9 @@ Type xlsxHyperLink = Class xmlfile := file_.WorkBook().GetXmlFileObj(relsfile); class(xlsxXml).AddRelationshipRid(xmlfile, hyperlink.LinkUrl, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink", ridstr, "External"); End - reindex(attrs, array('linkType': nil, 'linkUrl': nil)); - attrs['r:id'] := 'rId' + inttostr(rid); - End - marshal['attributes'] := attrs; - hyperlinks.InsertEndChild(marshal); + hyperlink.RId := 'rId' + inttostr(rid); + end + hyperlinks.InsertEndChild(hyperlink.marshal()); End; Function GetCellHyperLink(axis); @@ -68,7 +61,20 @@ Type xlsxHyperLink = Class ref := node.GetAttribute('ref'); if ref = axis then begin - link.RootObj := node; + location := node.GetAttribute('location'); + if location then + begin + link.LinkUrl := location; + link.LinkType := 'location'; + end + else begin + link.LinkType := 'external'; + rid := node.GetAttribute('r:id'); + rels_file := file_.WorkBook().GetSheetRelsFile(sheetName_); + target_node := class(xlsxXml).FindRelationship(rels_file, rid); + if ifObj(target_node) then link.LinkUrl := target_node.GetAttribute('Target'); + end + link.Tooltip := node.GetAttribute('tooltip'); break; end node := node.NextElement(); diff --git a/funcext/TSOffice/worksheet/xlsxWorkBook.tsf b/funcext/TSOffice/worksheet/xlsxWorkBook.tsf index d40d8a6..7e72e15 100644 --- a/funcext/TSOffice/worksheet/xlsxWorkBook.tsf +++ b/funcext/TSOffice/worksheet/xlsxWorkBook.tsf @@ -190,9 +190,6 @@ Type xlsxWorkBook = Class SetDefaultSheet(sheet); End; - ///删除sheet - ///sheet: string,工作表名称 - ///返回: [err, info] Function DeleteSheet(sheet); Begin if sheetsCount_ <= 1 then return 'Cant not delete the last sheet.'; @@ -477,7 +474,7 @@ Type xlsxWorkBook = Class is_exists := sheet_obj.RowIsExists(row); if not is_exists then begin - [err, cell] := xlsx_call("CoordinatesToCellName", 1, row); + [err, cell] := CoordinatesToCellName(1, row); sheet_obj.SetCellValue(cell, ''); end sheet_obj.SetAttribute(row, array("hidden": hidden)); @@ -564,7 +561,7 @@ Type xlsxWorkBook = Class Function SetRowHeight(sheet, row, height); Begin obj := GetSheetObj(sheet); - axis := xlsx_call("CoordinatesToCellName", 1, row, False)[1]; + axis := CoordinatesToCellName(1, row, False)[1]; if not obj.CellIsExists(axis) then begin obj.SetCellValue(axis, '', array('t': 's')); @@ -585,8 +582,8 @@ Type xlsxWorkBook = Class Function SetColWidth(sheet, startCol, endCol, width); Begin - startCol := xlsx_call('ColumnNameToNumber', startCol)[1]; - endCol := xlsx_call('ColumnNameToNumber', endCol)[1]; + startCol := ColumnNameToNumber(startCol)[1]; + endCol := ColumnNameToNumber(endCol)[1]; if startCol > endCol then return; sheet_xml_file := GetSheetXmlFile(sheet); work_node := sheet_xml_file.FirstChildElement('worksheet'); @@ -633,7 +630,7 @@ Type xlsxWorkBook = Class default_width := trystrtofloat(default_width, r) ? r: -1; if not ifObj(col_node) then return array(0, default_width); - col := xlsx_call('ColumnNameToNumber', col)[1]; + col := ColumnNameToNumber(col)[1]; node := col_node.FirstChildElement('col'); while ifObj(node) do Begin @@ -684,18 +681,18 @@ Type xlsxWorkBook = Class count := trystrtoint(merge_node.GetAttribute('count'), r) ? r : 0; end node := merge_node.FirstChildElement('mergeCell'); - hcell_ := xlsx_call('SplitCellName', hcell); - vcell_ := xlsx_call('SplitCellName', vcell); - hcell_int := xlsx_call('ColumnNameToNumber', hcell_[1])[1]; - vcell_int := xlsx_call('ColumnNameToNumber', vcell_[1])[1]; + hcell_ := SplitCellName(hcell); + vcell_ := SplitCellName(vcell); + hcell_int := ColumnNameToNumber(hcell_[1])[1]; + vcell_int := ColumnNameToNumber(vcell_[1])[1]; while ifObj(node) do Begin ref := node.GetAttribute('ref'); position := pos(':', ref); - cell1 := xlsx_call('SplitCellName', ref[1:position-1]); - cell2 := xlsx_call('SplitCellName', ref[position+1:]); - cell1_int := xlsx_call('ColumnNameToNumber', cell1[1])[1]; - cell2_int := xlsx_call('ColumnNameToNumber', cell2[1])[1]; + cell1 := SplitCellName(ref[1:position-1]); + cell2 := SplitCellName(ref[position+1:]); + cell1_int := ColumnNameToNumber(cell1[1])[1]; + cell2_int := ColumnNameToNumber(cell2[1])[1]; if (hcell_[2] >= cell1[2] and hcell_[2] <= cell2[2] and hcell_int >= cell1_int and hcell_int <= cell2_int) or (vcell_[2] >= cell1[2] and vcell_[2] <= cell2[2] and vcell_int >= cell1_int and vcell_int <= cell2_int) then Begin @@ -725,14 +722,14 @@ Type xlsxWorkBook = Class node := merge_node.FirstChildElement('mergeCell'); if not ifObj(node) then return ''; count := trystrtoint(merge_node.GetAttribute('count'), r) ? r : 0; - hcell_ := xlsx_call('SplitCellName', hcell); - vcell_ := xlsx_call('SplitCellName', vcell); + hcell_ := SplitCellName(hcell); + vcell_ := SplitCellName(vcell); while ifObj(node) do Begin ref := node.GetAttribute('ref'); position := pos(':', ref); - cell1 := xlsx_call('SplitCellName', ref[1:position-1]); - cell2 := xlsx_call('SplitCellName', ref[position+1:]); + cell1 := SplitCellName(ref[1:position-1]); + cell2 := SplitCellName(ref[position+1:]); if ref[1:position-1] = hcell and ref[position+1:] = vcell then Begin merge_node.DeleteChild(node); @@ -986,7 +983,7 @@ private sr := inttostr(r); for i:=c1 to c2 do Begin - name := xlsx_call('ColumnNumberToName', i); + name := ColumnNumberToName(i); if not name[0] then name := name[1]; name += sr; arr union= array(('type': 'element', 'name': 'r', 'attributes': ('r': name, 's': '1'))); diff --git a/更新日志.md b/更新日志.md index 60afab6..7584cc7 100644 --- a/更新日志.md +++ b/更新日志.md @@ -1,12 +1,33 @@ -# 2022-12-30 +# 更新日志 -## V1.0.4 +## 2023-1-5 -### word +### V1.0.5 + +❗ 部署方式发生变化,简化了环境部署,详见项目[README](./README.md) + +#### word + +1. 修复 Properties执行报错 +2. 修复格式刷 + +#### excel + +1. 移除API `JoinCellName` +2. 修改`RGBToHSL`与`HSLToRGB`返回值 +3. 修复获取超链接`GetCellHyperLink`失败问题 +4. 修复一个对象新建文件,打开文件之后引发的xlsx文件错误问题 +5. 修复`GetCoreProps`,`GetAppProps`失败问题 + +## 2022-12-30 + +### V1.0.4 + +#### word 1. 初步支持中文 -### excel +#### excel 1. 初步支持中文 2. `SetSheetName`,`NewSheet` 返回值不再是`[err, errinfo]` @@ -15,4 +36,4 @@ 5. 修复`SetRowVisible`,`GetRowVisible`,`SetSheetVisible`问题 如何设置字符集(中文支持)? -★用户的脚本可能是UFT8格式,或可能是GBK码格式,系统提供API自动设置当前字符集环境:`class(xlsxXml).CodePage('中文');` 在文件头设置该代码后,系统会自动检测当前的环境字符集 +★用户的脚本可能是UFT8格式,或可能是GBK码格式,系统提供API自动设置当前字符集环境:`class(xlsxXml).CodePage('中文');` 在文件头设置该代码后,系统会自动检测当前的环境字符集 \ No newline at end of file