Skip to content

Lua library to generate word document from docx template file.

License

Notifications You must be signed in to change notification settings

paragasu/lua-docx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

78 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lua-docx

Simple lua library to replace tags in the docx template file.

Usage

local sock_file = '/home/rogon/tmp/exec.sock' 
local tmp_dir = '/home/myhome/tmpdir'

local docx = require 'docx'
local docx_cleaner = require 'docx-cleaner'

local dc = docx_cleaner.new(tmp_dir, sock_file_path)
local cleaned_docx = dc:clean_xml(./tmp/docx-tpl.docx')

local doc  = docx.new(tmp_dir)
local ok, err = doc:replace_tags(cleaned_docx, { 
  ['#matters.name#'] = 'Some name',
  ['#matters.email#'] = 'some@email.com'
})

-- copy docx file to public web directory
local res, err = os.rename(cleaned_docx, '/var/www/public/20170601.docx')

Forward the browser url point to this file eg: https://mydomain.com/20170601.docx

API

new(tmp_file_dir)

  • tmp_file_dir string output file directory

replace_tags(docx_tpl_path, tags)

  • docx_tpl_path string docx file with full path
  • tags table table of tag -> value
  • return boolean, err

Installation

It is important to configure the lua-docx-xml-cleaner in order for lua-docx to work properly.

#luarocks install --server=http://luarocks.org/dev lua-zip
#luarocks install lua-docx-xml-cleaner
#luarocks install lua-docx

About

Lua library to generate word document from docx template file.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages