WordTemplate.zip

上传者: lockepeng | 上传时间: 2023-03-14 09:59:22 | 文件大小: 11.36MB | 文件类型: ZIP
由于项目需求,需要根据现有的word模板,进行批量生成word报表,为了方便,选用的是 NPOI (NPOI是一个开源的C#读写Excel、WORD等微软OLE2组件文档的项目)来实现。本次用的版本是NPOI 2.3.0.0,版本不同写法会有差别。

思路
NPOI提供操作word文档的方法也比较简单。
替换模板中关键字的实现思路大致是:

获取具有关键字的模板word文档(关键字可以自己定义,需要具有唯一性和可读性);
获取文档中的所有段落Paragraphs(表格中的单元格内容也属于段落);
遍历段落,找到关键字并进行替换(表格需要先遍历单元格,再遍历单元格中的段落);
生成新的文档;
模板实例
本次实例是用VS控制台程序进行测试,需要在项目路径下新建文件夹来存放模板文件和结果文件。
模板文件的存放位置为:…\bin\Debug\Templates,
生成的文件存放位置为:…\bin\Debug\GoalFiles。
实例模板中的关键字有四个:
关键字 说明
{$project} 项目名称
{$Name} 负责人名字
{$Date} 日期
{$Dep} 部门

文件下载

资源详情

[{"title":"( 57 个子文件 11.36MB ) WordTemplate.zip","children":[{"title":"WordTemplate","children":[{"title":"WordTemplate.sln <span style='color:#111;'> 1.11KB </span>","children":null,"spread":false},{"title":".vs","children":[{"title":"WordTemplate","children":[{"title":"v15","children":[{"title":".suo <span style='color:#111;'> 30.50KB </span>","children":null,"spread":false},{"title":"Server","children":[{"title":"sqlite3","children":[{"title":"storage.ide <span style='color:#111;'> 4.00KB </span>","children":null,"spread":false},{"title":"storage.ide-shm <span style='color:#111;'> 32.00KB </span>","children":null,"spread":false},{"title":"db.lock <span style='color:#111;'> 0B </span>","children":null,"spread":false},{"title":"storage.ide-wal <span style='color:#111;'> 1.60MB </span>","children":null,"spread":false}],"spread":true}],"spread":true}],"spread":true}],"spread":true}],"spread":true},{"title":"WordTemplate","children":[{"title":"bin","children":[{"title":"Debug","children":[{"title":"GoalFiles","children":[{"title":"Template1.docx <span style='color:#111;'> 9.79KB </span>","children":null,"spread":false}],"spread":true},{"title":"WordTemplate.pdb <span style='color:#111;'> 21.50KB </span>","children":null,"spread":false},{"title":"ICSharpCode.SharpZipLib.dll <span style='color:#111;'> 196.00KB </span>","children":null,"spread":false},{"title":"Templates","children":[{"title":"Template1.docx <span style='color:#111;'> 12.92KB </span>","children":null,"spread":false}],"spread":true},{"title":"NPOI.dll <span style='color:#111;'> 1.55MB </span>","children":null,"spread":false},{"title":"NPOI.OpenXmlFormats.dll <span style='color:#111;'> 1.98MB </span>","children":null,"spread":false},{"title":"NPOI.OpenXml4Net.dll <span style='color:#111;'> 87.50KB </span>","children":null,"spread":false},{"title":"NPOI.OOXML.dll <span style='color:#111;'> 518.00KB </span>","children":null,"spread":false},{"title":"WordTemplate.exe <span style='color:#111;'> 9.50KB </span>","children":null,"spread":false}],"spread":true}],"spread":true},{"title":"WordTemplateHelper.cs <span style='color:#111;'> 6.66KB </span>","children":null,"spread":false},{"title":"Program.cs <span style='color:#111;'> 1.04KB </span>","children":null,"spread":false},{"title":"obj","children":[{"title":"Debug","children":[{"title":"WordTemplate.pdb <span style='color:#111;'> 21.50KB </span>","children":null,"spread":false},{"title":"WordTemplate.csprojAssemblyReference.cache <span style='color:#111;'> 51.51KB </span>","children":null,"spread":false},{"title":"WordTemplate.csproj.CoreCompileInputs.cache <span style='color:#111;'> 42B </span>","children":null,"spread":false},{"title":"DesignTimeResolveAssemblyReferencesInput.cache <span style='color:#111;'> 6.79KB </span>","children":null,"spread":false},{"title":"TempPE","children":null,"spread":false},{"title":"WordTemplate.csproj.FileListAbsolute.txt <span style='color:#111;'> 1.03KB </span>","children":null,"spread":false},{"title":"WordTemplate.exe <span style='color:#111;'> 9.50KB </span>","children":null,"spread":false},{"title":"WordTemplate.csproj.CopyComplete <span style='color:#111;'> 0B </span>","children":null,"spread":false}],"spread":true}],"spread":true},{"title":"WordTemplate.csproj <span style='color:#111;'> 2.88KB </span>","children":null,"spread":false},{"title":"Properties","children":[{"title":"AssemblyInfo.cs <span style='color:#111;'> 1.29KB </span>","children":null,"spread":false}],"spread":true}],"spread":true},{"title":"packages","children":[{"title":"NPOI.2.4.1","children":[{"title":".signature.p7s <span style='color:#111;'> 9.25KB </span>","children":null,"spread":false},{"title":"logo","children":[{"title":"240_240.png <span style='color:#111;'> 15.04KB </span>","children":null,"spread":false},{"title":"60_60.jpg <span style='color:#111;'> 4.09KB </span>","children":null,"spread":false},{"title":"32_32.jpg <span style='color:#111;'> 1.79KB </span>","children":null,"spread":false},{"title":"120_120.jpg <span style='color:#111;'> 7.95KB </span>","children":null,"spread":false}],"spread":true},{"title":"Read Me.txt <span style='color:#111;'> 4.47KB </span>","children":null,"spread":false},{"title":"LICENSE <span style='color:#111;'> 9.62KB </span>","children":null,"spread":false},{"title":"lib","children":[{"title":"netstandard2.0","children":[{"title":"NPOI.deps.json <span style='color:#111;'> 9.24KB </span>","children":null,"spread":false},{"title":"NPOI.OpenXml4Net.deps.json <span style='color:#111;'> 9.67KB </span>","children":null,"spread":false},{"title":"NPOI.OpenXmlFormats.deps.json <span style='color:#111;'> 10.15KB </span>","children":null,"spread":false},{"title":"NPOI.dll <span style='color:#111;'> 1.59MB </span>","children":null,"spread":false},{"title":"NPOI.OpenXmlFormats.dll <span style='color:#111;'> 1.99MB </span>","children":null,"spread":false},{"title":"NPOI.OpenXml4Net.dll <span style='color:#111;'> 87.50KB </span>","children":null,"spread":false},{"title":"NPOI.OOXML.deps.json <span style='color:#111;'> 10.65KB </span>","children":null,"spread":false},{"title":"NPOI.OOXML.dll <span style='color:#111;'> 520.50KB </span>","children":null,"spread":false}],"spread":true},{"title":"NPOI.xml <span style='color:#111;'> 2.17MB </span>","children":null,"spread":false},{"title":"net45","children":[{"title":"NPOI.dll <span style='color:#111;'> 1.55MB </span>","children":null,"spread":false},{"title":"NPOI.OpenXmlFormats.dll <span style='color:#111;'> 1.98MB </span>","children":null,"spread":false},{"title":"NPOI.OpenXml4Net.dll <span style='color:#111;'> 87.00KB </span>","children":null,"spread":false},{"title":"NPOI.OOXML.dll <span style='color:#111;'> 518.00KB </span>","children":null,"spread":false}],"spread":true},{"title":"net40","children":[{"title":"NPOI.dll <span style='color:#111;'> 1.55MB </span>","children":null,"spread":false},{"title":"NPOI.OpenXmlFormats.dll <span style='color:#111;'> 1.98MB </span>","children":null,"spread":false},{"title":"NPOI.OpenXml4Net.dll <span style='color:#111;'> 87.50KB </span>","children":null,"spread":false},{"title":"NPOI.OOXML.dll <span style='color:#111;'> 518.00KB </span>","children":null,"spread":false}],"spread":false}],"spread":true},{"title":"NPOI.2.4.1.nupkg <span style='color:#111;'> 4.41MB </span>","children":null,"spread":false}],"spread":true},{"title":"SharpZipLib.0.86.0","children":[{"title":"SharpZipLib.0.86.0.nupkg <span style='color:#111;'> 452.73KB </span>","children":null,"spread":false},{"title":".signature.p7s <span style='color:#111;'> 9.25KB </span>","children":null,"spread":false},{"title":"lib","children":[{"title":"SL4","children":[{"title":"SharpZipLib.Silverlight4.dll <span style='color:#111;'> 207.00KB </span>","children":null,"spread":false}],"spread":true},{"title":"SL3","children":[{"title":"SharpZipLib.Silverlight3.dll <span style='color:#111;'> 208.00KB </span>","children":null,"spread":false}],"spread":true},{"title":"20","children":[{"title":"ICSharpCode.SharpZipLib.dll <span style='color:#111;'> 196.00KB </span>","children":null,"spread":false}],"spread":true},{"title":"11","children":[{"title":"ICSharpCode.SharpZipLib.dll <span style='color:#111;'> 204.00KB </span>","children":null,"spread":false}],"spread":true}],"spread":true}],"spread":true}],"spread":true}],"spread":true}],"spread":true}]

评论信息

免责申明

【只为小站】的资源来自网友分享,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,【只为小站】 无法对用户传输的作品、信息、内容的权属或合法性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论 【只为小站】 经营者是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。
本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二条之规定,若资源存在侵权或相关问题请联系本站客服人员,zhiweidada#qq.com,请把#换成@,本站将给予最大的支持与配合,做到及时反馈和处理。关于更多版权及免责申明参见 版权及免责申明