项目作者: erpuno

项目描述 :
💠 DOCX: Template Processor
高级语言: F#
项目地址: git://github.com/erpuno/docx.git
创建时间: 2020-07-14T07:42:14Z
项目社区:https://github.com/erpuno/docx

开源协议:

下载


DOCX Template Processor

Motivation

The goal was to build simple command line DOCX template processor that can be used from other than .NET platforms.

Install .NET Core SDK LTS

On Linix download https://dot.net/v1/dotnet-install.sh and then

  1. $ ./dotnet-install.sh -c 3.1

On Windows and Mac please refer to corresponding packages
from https://dotnet.microsoft.com/download/dotnet-core/3.1

Then put into your ~/.profile the following

  1. export DOTNET_ROOT=$HOME/.dotnet
  2. export PATH=$PATH:$HOME/.dotnet

With test

  1. $ dotnet --list-runtimes
  2. Microsoft.AspNetCore.App 3.1.5 [/home/maxim/.dotnet/shared/Microsoft.AspNetCore.App]
  3. Microsoft.NETCore.App 3.1.5 [/home/maxim/.dotnet/shared/Microsoft.NETCore.App]

Compile and run

Parameters are passed as command line arguments. Table fields are passed as CSV files.

  1. $ cat firestarter.sh
  2. #!/bin/sh
  3. rm -rf bin
  4. rm -rf obj
  5. dotnet build docx.sln
  6. cp Logo.jpg in.docx sample.csv bin/Debug/netcoreapp3.1
  7. cd bin/Debug/netcoreapp3.1
  8. ./docx -vars vector "Table" "sample.csv" , \
  9. zimage "Logo" "Logo.jpg" , \
  10. scalar "ReportDate" "12-22-2222" , \
  11. scalar "Copyright" "SYNRC" , \
  12. scalar 'CompanyName' "SYNRC" \
  13. -in "in.docx" \
  14. -out "out.docx"
  15. ls -l *.docx
  1. $ cat sample.csv
  2. Year,Brand,Model,Desc,Price
  3. 1997,Ford,E350,"ac, abs, moon",3000.00
  4. 1999,Chevy,"Venture ""Extended Edition""",,4900.00
  5. 1996,Jeep,Grand Cherokee,"MUST SELL! air, moon roof, loaded",4799.00

During run you should get out.docx with substituted template parameters.

  1. $ dotnet build docx.sln
  2. $ ./firestarter
  3. Microsoft (R) Build Engine version 16.6.0+5ff7b0c9e for .NET Core
  4. Copyright (C) Microsoft Corporation. All rights reserved.
  5. Determining projects to restore...
  6. Restored /home/maxim/depot/synrc/fsharp/docx/docx.fsproj (in 767 ms).
  7. Docx -> /home/maxim/depot/synrc/fsharp/docx/bin/Debug/netcoreapp3.1/Docx.dll
  8. Successfully created package '/home/maxim/depot/synrc/fsharp/docx/bin/Debug/Docx.1.0.0.nupkg'.
  9. docx -> /home/maxim/depot/synrc/fsharp/docx/bin/Debug/netcoreapp3.1/docx.dll
  10. Build succeeded.
  11. 0 Warning(s)
  12. 0 Error(s)
  13. Time Elapsed 00:00:04.71
  14. Headers: ["Year"; "Brand"; "Model"; "Desc"; "Price"]
  15. Rows: [["1996"; "Jeep"; "Grand Cherokee"; "MUST SELL! air, moon roof, loaded";
  16. "4799.00"]; ["1999"; "Chevy"; "Venture "Extended Edition""; ""; "4900.00"];
  17. ["1997"; "Ford"; "E350"; "ac, abs, moon"; "3000.00"]]
  18. Vars: [TemplateEngine.Docx.TableContent; TemplateEngine.Docx.ImageContent;
  19. TemplateEngine.Docx.FieldContent; TemplateEngine.Docx.FieldContent;
  20. TemplateEngine.Docx.FieldContent]
  21. Template: " in.docx "
  22. Output: " out.docx"
  23. Save Changes
  24. -rw-r--r-- 1 maxim maxim 32979 Jul 14 10:45 in.docx
  25. -rw-r--r-- 1 maxim maxim 39474 Jul 14 10:45 out.docx