如何删除 Docxtemplater 中字符串之间的空格?
How to remove spaces between a string in Docxtemplater?
{#form}{importantFacts}{/form}
问题是字符串占满了整行
例如:
1. This is test
2. This is a longer string so spacing is generated less
然而,如果我提供更长的字符串,它工作正常,基本上行为是它覆盖了整行..如何删除这些空白
如果需要显示更多代码,请告诉我。
正在生成文档文件
const tempFileName = `output-${new Date().getTime()}.docx`;
const content = fs.readFileSync(path.resolve(__dirname, formPath), 'binary');
const zip = new PizZip(content);
const doc = new Docxtemplater(zip, {nullGetter: () => " ", linebreaks: true});
doc.setData(data);
doc.render()
const buf = doc.getZip().generate({type: 'nodebuffer'});
fs.writeFileSync(path.resolve(__dirname, tempFileName), buf);
用于打印字符串数组的函数
function formatArrayLines(lines: string[]) {
let outputString = '';
let i = 1;
for (const line of lines) {
outputString += `${i}. ${line}\n\n`
i++;
}
return outputString;
}
所以这个问题的解决方法与源码无关,而是文档中的对齐方式
{#form}{importantFacts}{/form}
So selecting this and setting text align left solved the problem.
{#form}{importantFacts}{/form}
问题是字符串占满了整行
例如:
1. This is test
2. This is a longer string so spacing is generated less
然而,如果我提供更长的字符串,它工作正常,基本上行为是它覆盖了整行..如何删除这些空白
如果需要显示更多代码,请告诉我。
正在生成文档文件
const tempFileName = `output-${new Date().getTime()}.docx`;
const content = fs.readFileSync(path.resolve(__dirname, formPath), 'binary');
const zip = new PizZip(content);
const doc = new Docxtemplater(zip, {nullGetter: () => " ", linebreaks: true});
doc.setData(data);
doc.render()
const buf = doc.getZip().generate({type: 'nodebuffer'});
fs.writeFileSync(path.resolve(__dirname, tempFileName), buf);
用于打印字符串数组的函数
function formatArrayLines(lines: string[]) {
let outputString = '';
let i = 1;
for (const line of lines) {
outputString += `${i}. ${line}\n\n`
i++;
}
return outputString;
}
所以这个问题的解决方法与源码无关,而是文档中的对齐方式
{#form}{importantFacts}{/form}
So selecting this and setting text align left solved the problem.