0
docxtemplater을 사용하여 JSON 데이터를 워드 문서로 변환합니다. 문서가 잘 생성됩니다. docxtemplater로 개행 또는 중단 태그
var sections = {"sections":[{"section_name":"Languages","data":"Tamil\nTelugu\nHindi\nEnglish","key":"8783"},{"section_name":"Skills","data":"JavaScript<br />jQuery<br />CSS<br />","key":"13486"}]};
function loadFile(url,callback){
JSZipUtils.getBinaryContent(url,callback);
}
loadFile("examples/doccc.docx",function(error,content){
if (error) { throw error; };
var zip = new JSZip(content);
var doc=new Docxtemplater().loadZip(zip);
doc.setOptions({nullGetter: function() {
return "";
}});
doc.setData(sections);
try {
// render the document (replace all occurences of {first_name} by John, {last_name} by Doe, ...)
doc.render();
}
catch (error) {
var e = {
message: error.message,
name: error.name,
stack: error.stack,
properties: error.properties,
};
console.log(JSON.stringify({error: e}));
// The error thrown here contains additional information when logged with JSON.stringify (it contains a property object).
throw error;
}
var out=doc.getZip().generate({
type:"blob",
mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
}); //Output the document using Data-URI
saveAs(out,"output.docx");
});
이
내 템플릿{#sections}
{section_name} - {data}
{/sections}
그것은 모든 섹션과 DOCX 파일을 생성하지만 "\ n"새 라인과
태그는 문서에 그대로 인쇄된다.
새 줄을 새 줄로 해석해야합니다.
현재 Word 문서에서
Languages
Tamil\nTelugu\nHindi\nEnglish
Skills
JavaScript<br />jQuery<br />CSS<br />
.. 어떤 도움을
Languages
Tamil
Telugu
Hindi
English
Skills
JavaScript
jQuery
CSS
감사로 인쇄하는 방법을 어떤 생각으로는 인쇄.
을 근무합니다. 감사. 템플릿에서 {@data}를 사용하는 경우 일반 텍스트 인 경우에도 모든 섹션에 사전 및 게시 태그가 있어야합니다. 그렇지 않으면 단어 문서가 열리는 동안 오류가 발생합니다. –
공백 문제에 대한 몇 가지 코드 샘플을 함께 제공하십시오. https://github.com/open-xml-templating/docxtemplater/issues/272 감사합니다. –