从模板以编程方式生成libreoffice文本文档

dom*_*ine 8 node.js libreoffice odfdom

我正在尝试找到一种以编程方式从.ott模板生成.odt文档的方法.这应该以编程方式完成.关于如何实现这一点的任何想法?

我找到了一些用Java生成.odt文件的方法(http://incubator.apache.org/odftoolkit/odfdom/index.html),但似乎无法从.ott模板生成文档.

实现语言或多或少不相关,但最好的是Node.js上的JavaScript.

感谢您的帮助.

dio*_*ney 2

你检查过node-odt吗?在我看来它支持你所需要的。

根据其文档:

用于处理 OpenDocument 文本文件的 Node.js 工具。

及其示例之一:

var fs = require('fs')
  , odt = require('odt')
  , template = odt.template
  , createWriteStream = fs.createWriteStream
var doc = 'mytemplate.ott';
var values = { 'subject': 'My subject value' };

// apply values

template(doc)
  .apply(values)
  .on('error', function(err){
    throw err;
  })
  .finalize(function(bytes){
    console.log('The document is ' + bytes + ' bytes large.');
  })
  .pipe(createWriteStream('mydocument.odt'))
  .on('close', function(){
    console.log('document written');
  });
Run Code Online (Sandbox Code Playgroud)

  • 是的,这是我自己的方法。我是这一篇的作者。不幸的是,这是一种非常幼稚的方法,并且不再适用于较新的 libreoffice 版本。 (2认同)