如何在将表导出到excel时保持单元格的格式

时间:2017-11-14 15:17:05

标签: php html excel format styles

我通过执行以下操作将html表导出到新的excel文件:

<script>
function s2ab(s) {
    if(typeof ArrayBuffer !== 'undefined') {
        var buf = new ArrayBuffer(s.length);
        var view = new Uint8Array(buf);
        for(var i=0; i!=s.length; ++i) view[i]=s.charCodeAt(i) & 0xFF;
        return buf;
    } else {
        var buf = new Array(s.length);
        for (var i=0; i!=s.length; ++i) buf[i] = s.charCodeAt(i) & 0xFF;
        return buf;
    }
}
function exportTable(id, type, fn) {
    var wb = XLSX.utils.table_to_book(document.getElementById(id), {sheet:"Sheet1"});
    var wbout = XLSX.write(wb, {bookType: type, bookSST:true, type: 'binary'});
    var fname = fn || 'FET_Changes.' + type;
    try {
        saveAs(new Blob([s2ab(wbout)], {type:"application/octet-stream"}), fname);
    } catch(e) { if(typeof console != 'undefined') console.log(e, wbout);}
    return wbout;
}
function doit(type, fn) {return exportTable('Info', type || 'xlsx', fn);}
</script>

它导出每个单元格中的文本,但不是因为某种原因我在PHP中格式化的突出显示:

echo'<td class="Test", style="background-color:#FFFF00">'.$info['ColOne'].' </td>'.PHP_EOL;

我有没有办法让背景颜色显示在Excel中?

0 个答案:

没有答案