supuwoerc
V2EX  ›  问与答

前端大佬们请进~。~

By supuwoerc at 2021 年 3 月 12 日 · 1708 次点击

请教大家两个问题:

  • 1.最近的一个导出 Excel 需求,找了一些诸如 xlsx 和 xlsx-style 的插件,但是不太适用我的场景,直接将 dom 转为 excel 倒是行得通,但是缺少了表格上的背景色,文字居中,换行的样式,不知道有没有大佬有思路或者能实现的方法。

ps:表格全部是动态数据。

  • 2.Element-ui 下递归创建多级表头,如何使用插槽渲染?貌似实现不了? 具体代码如下,想要动态的渲染表格内容,但是自己封装了之后就没法使用官方的插槽了,十分苦恼。
<template>
<el-table-column :prop="'persons_'+cols.remark" :label="cols.title" :width="cols.width?cols.width:150" align="center">
    <template v-if="cols.children">
        <loop-column v-for="(item, index) in cols.children" :key="index" :cols="item">
        </loop-column>
    </template>
</el-table-column>
</template>
<script>
export default {
    name: "loopColumn",
    props: {
        cols: {
            type: Object,
            default: () => {
                return {}
            }
        }

    }
}
<script>
6 条回复  •  2021-03-15 19:31:27 +08:00
murmur
   1
murmur  
   2021 年 3 月 12 日   ❤️ 1
excel 导出都是手写样式,一个单元格一个调,dom 转 excel 玩具都不算

我们是买了第三方报表工具实现的这个功能
toesbieya
   2
toesbieya  
   2021 年 3 月 12 日   ❤️ 1
1. [exceljs]( https://github.com/exceljs/exceljs)

2. render
putaozhenhaochi
   3
putaozhenhaochi  
   2021 年 3 月 12 日   ❤️ 1
推给后端 /逃
supuwoerc
   4
supuwoerc  
OP
   2021 年 3 月 12 日
@toesbieya 感谢! 太长时间没有 render,都快忘记还能这样了,一直在钻用插槽的牛角尖~~
supuwoerc
   5
supuwoerc  
OP
   2021 年 3 月 12 日
@toesbieya
大佬你好,请问 render 具体咋实现呢?我自己实现了一下,报错了。 =。=||
之前没太使用过这种场景,如果方便的话能回答下嘛? =。=||
supuwoerc
   6
supuwoerc  
OP
   2021 年 3 月 15 日
@toesbieya 打扰了,小弟今天重新读了 render 相关的文档,问题已经解决了! 十分感谢
© 2026 V2EX · 28ms · 3.9.8.5