From a3df0d5df9ad82f04bcc9af5dbe8f0803406c7ca Mon Sep 17 00:00:00 2001 From: csh Date: Mon, 4 Mar 2024 16:14:03 +0800 Subject: [PATCH] v1.6.5 --- .gitmodules | 3 + README.md | 17 +++- funcext/TSOffice/Extensions/OfficeVba | 1 + funcext/TSOffice/TOfficeObj.tsf | 2 +- funcext/TSOffice/TSDocxFile.tsf | 2 +- funcext/TSOffice/TSPptxFile.tsf | 139 ++++++++++++++++++++++++++ funcext/TSOffice/TSXlsxFile.tsf | 11 +- 更新日志.md | 8 ++ 8 files changed, 169 insertions(+), 14 deletions(-) create mode 100644 .gitmodules create mode 160000 funcext/TSOffice/Extensions/OfficeVba create mode 100644 funcext/TSOffice/TSPptxFile.tsf diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..cfc7add --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "funcext/TSOffice/Extensions/OfficeVba"] + path = funcext/TSOffice/Extensions/OfficeVba + url = https://git.mytsl.cn/tinysoft/OfficeVba.git diff --git a/README.md b/README.md index f4ae376..eedf761 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# OfficePlugin +# TSOffice TSOffice 项目:纯 TSL 代码实现 excel、word 文件读写 @@ -6,19 +6,19 @@ TSOffice 项目:纯 TSL 代码实现 excel、word 文件读写 ### windows -对应文件夹的dll文件按如下要求 +对应文件夹的 dll 文件按如下要求 - `office_plugin` 放入 tsl 安装根目录下 Plugin 文件夹 可选: -- `fmt_pubkrnl_plugin` 放入 tsl 安装根目录下 Plugin 文件夹,若需要执行Demo文件夹下的[XlsxHelp.tsl](./Demo/XlsxHelp.tsl)和[DocxHelp.tsl](./Demo/DocxHelp.tsl),需要部署改动态库 +- `fmt_pubkrnl_plugin` 放入 tsl 安装根目录下 Plugin 文件夹,若需要执行 Demo 文件夹下的[XlsxHelp.tsl](./Demo/XlsxHelp.tsl)和[DocxHelp.tsl](./Demo/DocxHelp.tsl),需要部署改动态库 ### Linux #### Ubuntu-18.04 -根据架构选择aarch64或x86版本将对应文件夹内容进行部署 +根据架构选择 aarch64 或 x86 版本将对应文件夹内容进行部署 - `liboffice_plugin` 放入 tsl 安装根目录下 Plugin 文件夹 @@ -28,7 +28,14 @@ TSOffice 项目:纯 TSL 代码实现 excel、word 文件读写 - [Word 帮助文档](./DocxFile使用帮助.docx) +## 扩展 + +扩展模块的内容需要通过`git submodule update --init --recursive`获取,相关帮助文档在`./funcext/TSOffice/Extensions/模块名`目录下可获取 + +支持的扩展: + +- **OfficeVba**: 可通过类 Vba 方式对 office文件 进行读写操作。 ## Demo -Demo文件夹提供了一些参考的demo +Demo 文件夹提供了一些参考的 demo diff --git a/funcext/TSOffice/Extensions/OfficeVba b/funcext/TSOffice/Extensions/OfficeVba new file mode 160000 index 0000000..a68cfb0 --- /dev/null +++ b/funcext/TSOffice/Extensions/OfficeVba @@ -0,0 +1 @@ +Subproject commit a68cfb01d7f8f722987e7c74a78edc7371c810e5 diff --git a/funcext/TSOffice/TOfficeObj.tsf b/funcext/TSOffice/TOfficeObj.tsf index 382dff7..4f44c1f 100644 --- a/funcext/TSOffice/TOfficeObj.tsf +++ b/funcext/TSOffice/TOfficeObj.tsf @@ -1,4 +1,4 @@ -// Version 1.6.4 +// Version 1.6.5 Function TOfficeObj(n); Begin case lowercase(n) of diff --git a/funcext/TSOffice/TSDocxFile.tsf b/funcext/TSOffice/TSDocxFile.tsf index 1845f2a..1e339ed 100644 --- a/funcext/TSOffice/TSDocxFile.tsf +++ b/funcext/TSOffice/TSDocxFile.tsf @@ -1,4 +1,4 @@ -// Version 1.6.4 +// Version 1.6.5 Type TSDocxFile = Class ///Version: V1.0 2022-09-20 ///适用于 Microsoft Word docx格式文件 diff --git a/funcext/TSOffice/TSPptxFile.tsf b/funcext/TSOffice/TSPptxFile.tsf new file mode 100644 index 0000000..c0ebcc5 --- /dev/null +++ b/funcext/TSOffice/TSPptxFile.tsf @@ -0,0 +1,139 @@ +Type TSPptxFile = Class + ///纯TSL模块实现 + ///PPT文件读写接口 + + ///缺省构造函数 + Function Create();overload; + ///构造函数,打开已经存在的excel文件 + ///alias: string,文件目录别名 + ///fname: string,文件名 + Function Create(alias, fname);overload; + ///构造函数,打开已经存在的excel文件 + ///alias: string,文件目录别名 + ///fname: string,文件名 + ///passwd: string,密码 + Function Create(alias, fname, passwd);overload; + //初始化 + Function init(); + ///打开excel文件 + ///alias: string,文件目录别名 + ///fname: string,文件名 + ///[passwd]: string,密码 + ///返回: [err, errmsg] + Function OpenFile(alias, fname, passwd); + ///新建pptx文件 + ///返回: [err, info] + Function NewFile(); + ///保存文件 + ///返回: [err, info] + Function Save(); + ///设置密码 + Function SetPassword(passwd) + ///打开二进制内容 + ///data: 二进制数据 + ///返回: [err, errmsg] + Function LoadFromMem(data); + ///保存为二进制内容 + ///返回: [err, fileContent] fileContent二进制文件内容 + Function SaveToMem(); + ///另存为 + ///alias: string,文件目录别名 + ///fname: string,文件名 + ///返回: [err, info] + Function SaveAs(alias, fname); + ///真实文件名 + ///返回: string + Function FileName(); + + zipfile_; +End; + +Function TSPptxFile.Create();overload; +Begin + init(); +End; + +Function TSPptxFile.Create(alias, fname);overload; +Begin + init(); + OpenFile(alias, fname, nil); +End; + +Function TSPptxFile.Create(alias, fname, passwd);overload; +Begin + init(); + OpenFile(alias, fname, passwd); +End; + +Function TSPptxFile.init(); +Begin + zipfile_ := new ZipFile(); +End; + +// TODO +Function TSPptxFile.OpenFile(alias, fname, passwd); +Begin + if not ifObj(zipfile_) then return array(-1, 'Create ZipFile object fail.'); + if zipfile_.FilesCount() > 0 then zipfile_ := new ZipFile(); + [err, errmsg] := zipfile_.Open(alias, fname, passwd); + if err=0 then Begin + workbook_ := new xlsxWorkBook(zipfile_); + workbook_.Load(); + End; + return array(err, errmsg); +End; + +//TODO +Function TSPptxFile.NewFile(); +Begin + def := TOfficeTemplate('default.pptx', true); + [err, errmsg] := zipfile_.LoadFromMem(def); + if err = 0 then + begin + workbook_ := new xlsxWorkBook(zipfile_); + workbook_.Load(); + end + return array(err, errmsg); +End; + +Function TSPptxFile.Save(); +Begin + return zipfile_.Save(); +End; + +Function TSPptxFile.SetPassword(passwd) +Begin + zipfile_.Password := passwd; +End; + +Function TSPptxFile.LoadFromMem(data); +Begin + [err, errmsg] := zipfile_.LoadFromMem(data); + if err = 0 then + begin + workbook_ := new xlsxWorkBook(zipfile_); + workbook_.Load(); + end + return array(err, errmsg); +End; + +Function TSPptxFile.SaveToMem(); +Begin + return zipfile_.Save2Mem(); +End; + +Function TSPptxFile.SaveAs(alias, fname); +Begin + return zipfile_.Save(alias, fname); +End; + +Function TSPptxFile.FileName(); +Begin + return zipfile_.FileName(); +End; + +Function TSPptxFile.Zip(); +Begin + return zipfile_; +End; + diff --git a/funcext/TSOffice/TSXlsxFile.tsf b/funcext/TSOffice/TSXlsxFile.tsf index 85f46ce..50dbf99 100644 --- a/funcext/TSOffice/TSXlsxFile.tsf +++ b/funcext/TSOffice/TSXlsxFile.tsf @@ -1,4 +1,4 @@ -// Version 1.6.4 +// Version 1.6.5 Type TSXlsxFile = Class ///Version: V1.0 2022-08-08 ///适用于 Microsoft Excel? 2007 及以上版本创建的电子表格文档。支持 XLSX / XLSM / XLTM / XLTX 等多种文档格式。 @@ -560,8 +560,7 @@ Type TSXlsxFile = Class ///返回: styleid Function NewStyle(style); overload; Begin - styleObj := new xlsxStyles('', self); - return styleObj.GetStyleId(style); + return style_.GetStyleId(style); End; ///新建样式对象,已存在样式的基础上返回新的样式Id @@ -570,16 +569,14 @@ Type TSXlsxFile = Class ///返回: styleid Function NewStyle(style, oldStyleId); overload; Begin - styleObj := new xlsxStyles('', self); - return styleObj.GetStyleId(style, oldStyleId); + return style_.GetStyleId(style, oldStyleId); End; ///获取样式对象 ///返回: TStyle对象 Function GetStyle(styleid); Begin - styleObj := new xlsxStyles('', self); - return styleObj.GetStyle(styleid); + return style_.GetStyle(styleid); End; ///设置单元格样式 diff --git a/更新日志.md b/更新日志.md index f0cf6f4..52cfb41 100644 --- a/更新日志.md +++ b/更新日志.md @@ -2,6 +2,14 @@ ## 2023-3-4 +### V1.6.5 + +支持扩展扩展模块 + +### excel + +1. 样式获取报错问题 + ### V1.6.4 #### word