Git Product home page Git Product logo

excel2json's Introduction

excel2json

详细帮助文档请见:https://neil3d.github.io/coding/excel2json.html

命令行参数

  • -e, –excel Required. 输入的Excel文件路径.
  • -j, –json 指定输出的json文件路径.
  • -h, –header Required. 表格中有几行是表头.
  • -c, –encoding (Default: utf8-nobom) 指定编码的名称.
  • -l, –lowcase (Default: false) 自动把字段名称转换成小写格式.
  • -a 序列化成数组
  • -d, --date:指定日期格式化字符串,例如:dd / MM / yyy hh: mm:ss
  • -s 序列化时强制带上sheet name,即使只有一个sheet
  • -exclude_prefix: 导出时,排除掉包含指定前缀的表单和列,例如:-exclude_prefix #
  • -cell_json:自动识别单元格中的Json对象和Json数组,Default:false

Excel
GUI
CMd

excel2json's People

Contributors

dantezhu avatar dyc92 avatar neil3d avatar pashcovich avatar thomaszj avatar winhoof avatar wuxian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

excel2json's Issues

对于大量空值的读取缓慢

如图,empty表的name_en字段暂无翻译,所以都暂时留白,这种情况下导表会非常缓慢

P220616-164807

速度如图所示

P220616-164313
经测试,有表头但没有内容的情况就会很慢,任意一行有内容都会使速度恢复正常

测试文件如下:

empty.xlsx
normal.xlsx

发现不方便的几个点,可以的话建议修改下

① 能否增加配置用的 Json 或 xml 文件,该文件中保存了当前表格的读取路径、保存路径,每张表和一个配置文件建立关联、不用每次保存时都手动选择保存路径
② 能否增加以模板文件来生成C#代码能功能呢?譬如想用到自定义类型,但需要命名空间,每生成一次都要手动添加命名空间很麻烦。
③ 可否支持自定义类型
④ 可否支持批量导入

excel表内填的日期会有问题

比如有列数据:
Date_Begin
开启日期
2018/06/05

那么这个日期在object value = row[column];读出来的时候就变成了{2018/6/5 0:00:00}
我不想要后面的时间,我只想要日期,请问要怎么处理呢?

BUG: --cell_json 无效的问题

看了下源码,原因貌似是Program.Options.cs 这个文件中 两个相邻的Option参数cell_json 与 all_string 使用了同一字符 "l",导致严格匹配后将cell_json的值给到了all_string 导致参数值错误
测试将Option 参数cell_json 的字符改成其他 字符 visual studio 重新编译生成后 不再出现此问题

建议或bug反馈,行首字段设置无效了?

以前使用int来标记该列的文本以数字的形式处理,string标记该列的文本是字符串,同时如果是json格式的字符串也可以额外处理。
但是经过测试发现,至少从1.4.2开始,这个标记应该已经无效了,实际是以具体的文本为导向了。
个人以为还是加个判断为好,优先已字段标记,对于可能是json的字符串直接以‘json’标记。

按照字段分组

请问下是否可以通过某个字段进行分组生成头行结构的json呢?

序列化结果问题

以下是序列化的结果
{
"1": {
"id": 1,
"name": "Apple_G",
"scrores": 3
},
"2": {
"id": 2,
"name": "Apple_R",
"scrores": 4
}
}
以下是想要序列化的结果
[
{
"id": 1.0,
"name": "Apple_G",
"scrores": 3.0
},
{
"id": 2.0,
"name": "Apple_R",
"scrores": 4.0
}
]

可以根据第二行来识别字段的格式吗?

image
如图,我有一个字段是string类型的,但是程序根据第一个字段1自动识别成了数字格式,这导致我空的项变成了0.0,请问有办法可以根据第二行来进行字段格式的识别吗?

mac 下用mono命令行调用,生成多余的空数据

"id": 10001, "name": "手枪", "weaponType": "pistol", "system": "reality", "icon": "", "ATT": 1, "attackSpeed": 1, "attackRange": "直线", "distance": 1000, "clip": 15, "recoil": 0, "Column11": "", "Column12": "", "Column13": "", "Column14": "", "Column15": "", "Column16": "", "Column17": "", "Column18": "", "Column19": "", "Column20": "", "Column21": "", "Column22": "", "Column23": "", "Column24": "", "Column25": "", "Column26": "", "Column27": ""
查看了下是Excel库读sheet取到了200多行,27列,
d900e817-0fde-40a5-8dce-cdd57dfb6bbb

使用bat 一次性转换的出现小问题

得到的json
{ "3": { "ID": 3, "Name": "阳", "CharacterStruct": "LR", "Component1": "左耳刀", "Component2": "日", "Type": "Normal", "Function1": "", "Function2": "" }, "4": { "ID": 4, "Name": "石", "CharacterStruct": "None", "Component1": "", "Component2": "", "Type": "Normal", "Function1": "", "Function2": "" }, "5": { "ID": 5, "Name": "卒", "CharacterStruct": "None", "Component1": "", "Component2": "", "Type": "Normal", "Function1": "", "Function2": "" },......

`@SET EXCEL_FOLDER=.\excel
@set JSON_FOLDER=.\json
@set EXE=.\excel2json.exe

@echo Converting excel files in folder %EXCEL_FOLDER% ...
for /f "delims=" %%i in ('dir /b /a-d /s %EXCEL_FOLDER%*.xlsx') do (
@echo processing %%~nxi
@call %EXE% --excel %EXCEL_FOLDER%%%~nxi --json %JSON_FOLDER%%%~ni.json --header 3
)`

我发现GUI工具更改ExportType为array 就可以了 但是bat 中的命令没有看到

--cell_json

这个dos命令无效呢?
image

image

但是用gui勾选
image
这个确实可以用
image

能否加个设置,空的数据不导出。

image
例如excel表内容目前导出是这样:
{
"1": {
"ID": 1,
"name": "铜钱",
"info": "",
"type": 1,
"iconID": 1,
"1": "1"
},
"2": {
"ID": 2,
"name": "元宝",
"info": "暂略",
"type": 0.0,
"iconID": 2,
"2": "2"
},
"3": {
"ID": 3,
"name": "测试武器",
"info": "暂略",
"type": 0.0,
"iconID": 0.0,
"3": "3"
}
}
我希望空数据不要导出来,导出这样的:
{
"1": {
"ID": 1,
"name": "铜钱",
"type": 1,
"iconID": 1,
"1": "1"
},
"2": {
"ID": 2,
"name": "元宝",
"info": "暂略",
"iconID": 2,
"2": "2"
},
"3": {
"ID": 3,
"name": "测试武器",
"info": "暂略",
"3": "3"
}
}

想选取某几列导出,有参数可以传吗?

比如想选取第一列,第三列,排除第二列,需要怎么做呢?
因为同一张表,策划在配置的时候,有些字段是服务器端用到的,有些字段是客户端用到的。不需要用到的字段,不希望生成到文件中去。这个需求要怎么实现?

如果有双索引就更美了

例如表格是
ids typs name
1 1 111
2 1 222
3 2 333
4 2 444
转成json:
第一种
1{
1{
name:111
},
2{
name:222
}
}
或者
1_1{
name:111
},
1_2:
{
name :222
}
这样就更爽了。。有的表需要双重定位。。需求还蛮多的。。

建议:改进对于未填的格子的处理方式,以便更灵活和更精简尺寸

发现当前版本 v1.4 ~ 1.4.3 的处理都是若有未填的格子时:
string 类型自动填为 "" (0长度字符串), number类型自动填为 0.0 , boolean 类型自动填为 false

建议规则改为,若有未填的格子时,无论指定是什么类型,都不如直接 剃除这对 key-value 项。

这样至少有两个明显好处:
1 若是不用这些格数据,可以故意不填,这样处理可以明显减少json文件的尺寸
2 便于使用者自己实现默认值功能,等于是用 undefined作为默认值标记——可以故意不填一些格子,运行时可以代码检测读到的值是否 undefined 然后替换成自己约定的指定默认值

一个文件多个Sheet 添加设置

一个文件多个Sheet 能不能添加一个设置选项.
1是现在的情况所有sheet在同一个json中:{ SheetName: { SheetOBject } }
2是每个sheet单独导出一个json
😘

感谢作者提供的软件,能否提供一个Mac版

在Mac电脑上使用命令运行 mono ./excel2json.exe 程序运行不起来会报错
下面是报错信息

Launch excel2json GUI Mode...
WARNING: The Carbon driver has not been ported to 64bits, and very few parts of Windows.Forms will work properly, or at all
System.EntryPointNotFoundException: GetWindowPort
at (wrapper managed-to-native) System.Drawing.MacSupport.GetWindowPort(intptr)
at System.Drawing.MacSupport.GetCGContextForView (System.IntPtr handle) [0x0007f] in <7beee3dcb66f4c2a8953ef8a786c2e63>:0
at System.Drawing.Graphics.FromHwnd (System.IntPtr hwnd) [0x00042] in <7beee3dcb66f4c2a8953ef8a786c2e63>:0
at System.Windows.Forms.Control.CreateGraphics () [0x00019] in <556a6ba2c0a546f1ad2318c309ce0945>:0
at (wrapper remoting-invoke-with-check) System.Windows.Forms.Control.CreateGraphics()
at System.Windows.Forms.Document.owner_HandleCreated (System.Object sender, System.EventArgs e) [0x00000] in <556a6ba2c0a546f1ad2318c309ce0945>:0
at System.Windows.Forms.Control.OnHandleCreated (System.EventArgs e) [0x00019] in <556a6ba2c0a546f1ad2318c309ce0945>:0
at System.Windows.Forms.TextBoxBase.OnHandleCreated (System.EventArgs e) [0x00000] in <556a6ba2c0a546f1ad2318c309ce0945>:0
at System.Windows.Forms.TextBox.OnHandleCreated (System.EventArgs e) [0x00000] in <556a6ba2c0a546f1ad2318c309ce0945>:0
at System.Windows.Forms.Control.WmCreate (System.Windows.Forms.Message& m) [0x00000] in <556a6ba2c0a546f1ad2318c309ce0945>:0
at System.Windows.Forms.Control.WndProc (System.Windows.Forms.Message& m) [0x0021c] in <556a6ba2c0a546f1ad2318c309ce0945>:0
at System.Windows.Forms.TextBoxBase.WndProc (System.Windows.Forms.Message& m) [0x001c5] in <556a6ba2c0a546f1ad2318c309ce0945>:0
at System.Windows.Forms.TextBox.WndProc (System.Windows.Forms.Message& m) [0x0011c] in <556a6ba2c0a546f1ad2318c309ce0945>:0
at System.Windows.Forms.Control+ControlWindowTarget.OnMessage (System.Windows.Forms.Message& m) [0x00000] in <556a6ba2c0a546f1ad2318c309ce0945>:0
at System.Windows.Forms.Control+ControlNativeWindow.WndProc (System.Windows.Forms.Message& m) [0x0000b] in <556a6ba2c0a546f1ad2318c309ce0945>:0
at System.Windows.Forms.NativeWindow.WndProc (System.IntPtr hWnd, System.Windows.Forms.Msg msg, System.IntPtr wParam, System.IntPtr lParam) [0x00085] in <556a6ba2c0a546f1ad2318c309ce0945>:0

Unhandled Exception:
System.EntryPointNotFoundException: GetWindowPort
at (wrapper managed-to-native) System.Drawing.MacSupport.GetWindowPort(intptr)
at System.Drawing.MacSupport.GetCGContextForView (System.IntPtr handle) [0x0007f] in <7beee3dcb66f4c2a8953ef8a786c2e63>:0
at System.Drawing.Graphics.FromHwnd (System.IntPtr hwnd) [0x00042] in <7beee3dcb66f4c2a8953ef8a786c2e63>:0
at System.Windows.Forms.Control.CreateGraphics () [0x00019] in <556a6ba2c0a546f1ad2318c309ce0945>:0
at (wrapper remoting-invoke-with-check) System.Windows.Forms.Control.CreateGraphics()
at System.Windows.Forms.Document.owner_VisibleChanged (System.Object sender, System.EventArgs e) [0x0000d] in <556a6ba2c0a546f1ad2318c309ce0945>:0
at System.Windows.Forms.Control.OnVisibleChanged (System.EventArgs e) [0x0002f] in <556a6ba2c0a546f1ad2318c309ce0945>:0
at System.Windows.Forms.Control.ChangeParent (System.Windows.Forms.Control new_parent) [0x000c7] in <556a6ba2c0a546f1ad2318c309ce0945>:0
at (wrapper remoting-invoke-with-check) System.Windows.Forms.Control.ChangeParent(System.Windows.Forms.Control)
at System.Windows.Forms.Control+ControlCollection.RemoveImplicit (System.Windows.Forms.Control control) [0x0003d] in <556a6ba2c0a546f1ad2318c309ce0945>:0
at System.Windows.Forms.ComboBox.set_DropDownStyle (System.Windows.Forms.ComboBoxStyle value) [0x0008e] in <556a6ba2c0a546f1ad2318c309ce0945>:0
at (wrapper remoting-invoke-with-check) System.Windows.Forms.ComboBox.set_DropDownStyle(System.Windows.Forms.ComboBoxStyle)
at excel2json.GUI.MainForm.InitializeComponent () [0x00d58] in <39b8e811f05f487b9bd0f6841982eb18>:0
at excel2json.GUI.MainForm..ctor () [0x0003c] in <39b8e811f05f487b9bd0f6841982eb18>:0
at (wrapper remoting-invoke-with-check) excel2json.GUI.MainForm..ctor()
at excel2json.Program.Main (System.String[] args) [0x00019] in <39b8e811f05f487b9bd0f6841982eb18>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.EntryPointNotFoundException: GetWindowPort
at (wrapper managed-to-native) System.Drawing.MacSupport.GetWindowPort(intptr)
at System.Drawing.MacSupport.GetCGContextForView (System.IntPtr handle) [0x0007f] in <7beee3dcb66f4c2a8953ef8a786c2e63>:0
at System.Drawing.Graphics.FromHwnd (System.IntPtr hwnd) [0x00042] in <7beee3dcb66f4c2a8953ef8a786c2e63>:0
at System.Windows.Forms.Control.CreateGraphics () [0x00019] in <556a6ba2c0a546f1ad2318c309ce0945>:0
at (wrapper remoting-invoke-with-check) System.Windows.Forms.Control.CreateGraphics()
at System.Windows.Forms.Document.owner_VisibleChanged (System.Object sender, System.EventArgs e) [0x0000d] in <556a6ba2c0a546f1ad2318c309ce0945>:0
at System.Windows.Forms.Control.OnVisibleChanged (System.EventArgs e) [0x0002f] in <556a6ba2c0a546f1ad2318c309ce0945>:0
at System.Windows.Forms.Control.ChangeParent (System.Windows.Forms.Control new_parent) [0x000c7] in <556a6ba2c0a546f1ad2318c309ce0945>:0
at (wrapper remoting-invoke-with-check) System.Windows.Forms.Control.ChangeParent(System.Windows.Forms.Control)
at System.Windows.Forms.Control+ControlCollection.RemoveImplicit (System.Windows.Forms.Control control) [0x0003d] in <556a6ba2c0a546f1ad2318c309ce0945>:0
at System.Windows.Forms.ComboBox.set_DropDownStyle (System.Windows.Forms.ComboBoxStyle value) [0x0008e] in <556a6ba2c0a546f1ad2318c309ce0945>:0
at (wrapper remoting-invoke-with-check) System.Windows.Forms.ComboBox.set_DropDownStyle(System.Windows.Forms.ComboBoxStyle)
at excel2json.GUI.MainForm.InitializeComponent () [0x00d58] in <39b8e811f05f487b9bd0f6841982eb18>:0
at excel2json.GUI.MainForm..ctor () [0x0003c] in <39b8e811f05f487b9bd0f6841982eb18>:0

mac下使用命令行编译有问题

mono ./excel2json.exe --excel test.xlsx --json test.json --header 3 --array true

报错:Error: Object reference not set to an instance of an object

bug: 命令行运行 cell_json 命令无效

疑似因为 Program.Options.cs 中 cell_json,all_string 与 lowcase 3个命令的缩写 都是 'l' 导致的冲突;
当命令行使用 -cell_json true 参数时,运行结果 变成全是字符串了

GUI 运行无此问题,恳请尽快修复

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.