Javascript 如何在Node.js officegen表中插入链接
我正在使用流行的Node.js库生成MS office word文档 下面的代码在中生成一个表, 如果您在表中向val prop提供原始字符串,它将生成文本,但是您将如何提供链接 尝试创建一个段落并将其增强为链接,但没有效果Javascript 如何在Node.js officegen表中插入链接,javascript,node.js,Javascript,Node.js,我正在使用流行的Node.js库生成MS office word文档 下面的代码在中生成一个表, 如果您在表中向val prop提供原始字符串,它将生成文本,但是您将如何提供链接 尝试创建一个段落并将其增强为链接,但没有效果 let pObj = docx.createP(); linkObj = pObj.addText('link', { link: 'http://www.google.com' }); const titleCell = (cellValue) => ({
let pObj = docx.createP();
linkObj = pObj.addText('link', { link: 'http://www.google.com' });
const titleCell = (cellValue) => ({
val: cellValue,
opts: {
cellColWidth: 2500,
b: true,
sz: '12',
fontFamily: 'Times New Roman'
}
})
const table = [
[titleCell('name'), titleCell(linkObj)],
]
分叉repo并添加所需的代码以在表单元格中生成超链接
“officegen”:“git+https://github.com/eugensunic/officegen.git“
并运行npm安装
if (opts.targetLink) {
relsApp.push({
type:
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink',
target: opts.targetLink,
targetMode: 'External'
})
const linkNum = relsApp.length
cellObj['w:tc']['w:p']['w:r'] = {
'@w:rsidRPr': '00722E63',
'w:rPr': {
'w:rFonts': {
'@w:ascii': 'Times New Roman',
'@w:hAnsi': 'Times New Roman'
},
'w:color': {
'@w:val': '0000EE'
},
'w:b': { '@w:val': 0 },
'w:u': { '@w:val': 'single' },
'w:sz': {
'@w:val': '26'
}
},
'w:hyperlink': {
'@r:id': 'rId' + linkNum,
'w:t': { '#text': multiLineBreakObj }
}
}
}
var table = [
[{
val: 'No.',
opts: {
cellColWidth: 4261,
color: '7F7F7F',
b: true,
sz: '14',
fontFamily: 'Arial'
}
},
{
val: 'Title1',
opts: {
targetLink: 'https://www.google.com/',
b: true,
color: '7F7F7F',
align: 'right'
}
}
]
]