将Excel解析为JSON [英] Parse Excel to JSON

查看:245
本文介绍了将Excel解析为JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以将excel解析为json. 如果可能的话,excel的结构使其成为可能. 有应用程序之类的东西吗?

I would like to know if is posible parse a excel to json. And if is possible which is the structure of the excel to make it possible. There is an application or something??

我有这个JSON结构 http://pastie.org/2760828 而且我必须插入500种产品,我想插入excel并解析它们.

I have this JSON sructure http://pastie.org/2760828 And I have to insert 500 products and i would like insert into excel and parse them.

推荐答案

您可以这样做:
1)首先将您的excelsheet转换为数据表
2)然后将您的数据表转换为json,如下所示:

You can do it like this:
1) First convert your excelsheet to datatable
2) And then convert your datatable to json like below:

1)将Excel工作表转换为数据表

1) conversion excel sheet to datatable

string ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=G:\school pro\schools3.xlsx;
Extended Properties=Excel 5.0";

StringBuilder stbQuery = new StringBuilder();
stbQuery.Append("SELECT top 10 * FROM [A1:M98]");
OleDbDataAdapter adp = new OleDbDataAdapter(stbQuery.ToString(), ConnectionString);

DataTable dtSchools = new DataTable();
adp.Fill(dtSchools);

2)将数据表转换为json

2) conversion datatable to json

Newtonsoft.Json.JsonConvert.SerializeObject(dtSchools)

这篇关于将Excel解析为JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆