1 回答
![?](http://img1.sycdn.imooc.com/56fb3e3d0001a10301000100-100-100.jpg)
TA贡献1836条经验 获得超5个赞
分叉存储库并添加所需的代码以在表格单元格内生成超链接
转到 o fficegen/lib/docx/docxtable.js
插入以下代码行
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 }
}
}
}
定义表时,通过插入 targetLink 属性来使用它
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'
}
}
]
]
你也可以在我的 github 上下载分叉的 repo:https ://github.com/eugensunic/officegen
将其包含在您的package.json中,如下所示:
"officegen": "git+https://github.com/eugensunic/officegen.git" 并运行npm install
添加回答
举报