Giter VIP home page Giter VIP logo

lua-docx's Introduction

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#'] = '[email protected]'
})

-- 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

lua-docx's People

Contributors

paragasu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

lua-docx's Issues

Move the xml cleaning part to separate repository

We are currently using libreoffice running as service in server to clean up dirty xml tags produced by Ms. Word. In the future, we might want to use a better way to cleanup the XML tags using lua xml parser.

Improve doc

Make the documentation more clear and easier to read

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.