nodejs npm libraries to access and modify microsoft word documents

人盡茶涼 提交于 2020-12-29 12:11:59

问题


Do you know if it is possible to search specific text like "xAx" into a Microsoft Word file (.doc or .docx) hosted on a website, replace it with some other text input by the user and make the file available for download using nodejs?

Is there a npm library that can do that?

If not it is possible to manipulate a PDF file instead? Please note that I do not want to create the document but manipulate a template file in the server.

Thank you for your help.


回答1:


There is project https://github.com/open-xml-templating/docxtemplater which serves for replacing {placeholders} in a .docx files.

Also supports loops and images, check out demo (examples) on http://javascript-ninja.fr/docxtemplater/v1/examples/demo.html




回答2:


If odt is an option (these files are open directly by MS Word besides Open and Libre Office and can be set with extension .doc so end users do not freak out) you can use HTML52PDF.

For example something like the following code will replace a string of text by a link:

require_once 'path/to/CreateDocument.inc';
$doc = new Html52pdf\createDocument(array('template' => 'template.odt'));
$format = '.odt';//.pdf, .doc, .docx, .odt, .rtf
//replace natural text
$doc->replace(array('replace me, please' => array('value' => '<a href="http://www.html52pdf.com">external link</a>')), array('format' => array('','')));

$doc->render('replaced_content' . $format); 


来源:https://stackoverflow.com/questions/28996641/nodejs-npm-libraries-to-access-and-modify-microsoft-word-documents

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!