uniapp中我使用xlsl导出excel表,但是我明明设置了全部居中,但是导出的excel并没有显示这些样式这是为什么

uniapp中我使用xlsl导出excel表,但是我明明设置了全部居中,并且是黑色边框,但是导出的excel并没有显示这些样式这是为什么

    // 创建工作簿和工作表
                const wb = XLSX.utils.book_new()
                const ws = XLSX.utils.json_to_sheet([])
                // 创建单元格样式
                const cellStyle = {
                    alignment: {
                        horizontal: 'center'
                    },
                    border: {
                        style: 'thin',
                        color: '000000'
                    }
                };

                ws['!cols'] = [{
                    wpx: 80,
                    alignment: {
                        horizontal: "center"
                    }
                }];
                // 设置单元格样式
                const style = {
                    alignment: {
                        vertical: 'center', // 垂直居中
                        horizontal: 'center' // 水平居中
                    },
                    border: {
                        top: {
                            style: 'thin',
                            color: {
                                rgb: '00000000'
                            } // 黑色边框
                        },
                        bottom: {
                            style: 'thin',
                            color: {
                                rgb: '00000000'
                            }
                        },
                        left: {
                            style: 'thin',
                            color: {
                                rgb: '00000000'
                            }
                        },
                        right: {
                            style: 'thin',
                            color: {
                                rgb: '00000000'
                            }
                        }
                    }
                }
                // 设置第一行为空数据
                ws['A1'] = {
                    v: '',
                    s: style
                }

                // 设置大标题并合并单元格
                ws['A2'] = {
                    v: '库存明细表',
                    s: style
                }
                ws['A2'].s = {
                    font: {
                        bold: true
                    },
                    alignment: {
                        horizontal: "center"
                    },
                    border: {
                        color: {
                            rgb: "ffc092"
                        },
                        style: 'thin'
                    } // 黑色边框
                }; // 设置样式
                ws['!merges'] = [{
                    s: {
                        r: 1,
                        c: 0
                    },
                    e: {
                        r: 1,
                        c: 4
                    }
                }]
                // 设置第三行第二个单元格为'哈哈'
                ws['B3'] = {
                    v: '哈哈',
                    t: 's'
                }
                // 将列表数据写入工作表(从第五行开始)
                const listData = [{
                    name: '张三',
                    age: 20
                }, {
                    name: '李四',
                    age: 30
                }]
                XLSX.utils.sheet_add_json(ws, this.list2, { //标签栏
                    skipHeader: true,
                    origin: 'A5'
                })
                XLSX.utils.sheet_add_json(ws, this.list, {
                    skipHeader: true,
                    origin: 'A6'
                })
                
                // 将工作表添加到工作簿
                XLSX.utils.book_append_sheet(wb, ws, 'Sheet1')

                // 将工作簿保存为Excel文件
                XLSX.writeFile(wb, 'output.xlsx')

普通版的XLSX库不支持样式哦 ,仅支持单元格合并

【相关推荐】




如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^