【问题标题】:How to apply style to all columns of exported excel sheet如何将样式应用于导出的 Excel 工作表的所有列
【发布时间】:2020-06-23 18:12:04
【问题描述】:
我想将换行样式应用于从数据表中导出的 Excel 工作表的所有单元格:
$('row c[r^="E"]', sheet).each(function () {
//wrap text
$(this).attr('s', '55');
})
上面的代码只是将样式应用于列E,我想将其应用于25列(从头开始的列范围)而不仅仅是列E怎么做?
【问题讨论】:
标签:
javascript
jquery
regex
excel
datatables
【解决方案1】:
您可以使用 ASCII Codes 来表示大写字母从 65 开始:
/**
* Returns an Array of integers in the range of [min, max] inclusive
*/
function createRange(min, max) {
return new Array(max - min + 1).fill(null).map((_, i) => min + i);
}
const selector = createRange(0, 24)
.map(i => {
// Convert i to a letter (A, B, C...)
const letter = String.fromCharCode(65 + i);
// Return a selector
return 'row c[r^="' + letter + '"]';
})
// Join them together with a comma
.join(',');
console.log(selector);
然后:
$(selector, sheet).each(function (i, column) {
// ...
});