shustone
V2EX  ›  问与答

Java 关于 excel 上传导入到数据库的问题

  •  
  •   shustone · Jan 9, 2019 · 3174 views
    This topic created in 2860 days ago, the information mentioned may be changed or developed.

    想请问一下这个可不可实现:客户在页面上进行 excel 上传导入到数据库表、但是 excel 的模板没有确定,有可能这个月使用的 excel 模板列数只有 50 列上传导入、下个月就有 55 列上传导入到数据库、后端怎么来进行处理、这种表结构好像也要进行改变?

    17 replies  •  2019-01-09 13:35:32 +08:00
    fmumu
    fmumu
    Jan 9, 2019 via Android❤️1
    1
    mongodb,不管什么表结构
    shustone
    shustone
    OP
    Jan 9, 2019
    2
    @fmumu 大佬、我们用的是 oracle。我想问的是这种有不有好的解决方式?
    night98
    night98
    Jan 9, 2019❤️1
    3
    存成 json 或 csv 字符串?
    lhx2008
    lhx2008
    Jan 9, 2019 via Android❤️1
    4
    可以强行用列式数据库的储存方式,不过,不适合再查询修改,只能一次导入或者导出
    shustone
    shustone
    OP
    Jan 9, 2019
    5
    @night98 只能用 excel 来上传
    night98
    night98
    Jan 9, 2019
    6
    @shustone #5 excel 上传完解析成 map 或者其他的,然后转成 json 或者 csv。
    shustone
    shustone
    OP
    Jan 9, 2019
    7
    @lhx2008 这个估计不能、因为这些数据是从其他地方弄过来。然后这边的系统来进行展示
    shustone
    shustone
    OP
    Jan 9, 2019
    8
    @night98 我去研究一下
    zhaogaz
    zhaogaz
    Jan 9, 2019
    9
    需要看入库的东西怎么用。单纯的入库是非常简单的。

    最简单,最差劲的处理办法显然就是每次上传 excel,数据库都建一个表。

    其他思路,的话,可以直接把文件二进制入库。解析读取内容,组织成表结构(上传 id,行号,列号,实际内容)。把 excel 内容读取到,构造成对象,序列化 json 入库。换成 xml 也行。
    auin
    auin
    Jan 9, 2019
    10
    最简单的两种方法:
    整列存,字段为:row,value (逗号隔开或 json 等字符串格式),10 行数据就有 10 条数据
    列转行,字段为:row, column, value(一个单元格的值),10 行 50 列就有 500 条数据

    两种方法各有利弊,自己看吧。
    auin
    auin
    Jan 9, 2019
    11
    @liuxey #10 说错了,第一个是“整行存”
    sonyxperia
    sonyxperia
    Jan 9, 2019
    12
    让用户统一好上传的 excel 格式。
    Done.
    xiaoxinshiwo
    xiaoxinshiwo
    Jan 9, 2019
    13
    json
    dangluren
    dangluren
    Jan 9, 2019
    15
    目前还缺 excel 和模板表入库,不过我已经开发好了,过两天传上去
    yaerda
    yaerda
    Jan 9, 2019 via Android
    16
    模板列数可变的多不多,如果有些基础信息是固定列的话,以这些作为表结构,把可变的部分再单独存到一个字段,前端展示的时候也可以展示基础固定信息,变化的列动态解析展示
    shustone
    shustone
    OP
    Jan 9, 2019
    17
    感谢各位回复
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1427 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 10:22 · PVG 18:22 · LAX 02:22 · JFK 05:22
    ♥ Do have faith in what you're doing.