如何使用c#将.xlsx文件转换为asp.net中的.Json文件 [英] How to convert .xlsx file to .Json file in asp.net using c#

查看:106
本文介绍了如何使用c#将.xlsx文件转换为asp.net中的.Json文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以告诉我如何通过上传xlsx文件将.xlsx文件转换为.Json文件,然后将其转换为json文件然后下载.json文件

祝你好运

Ali

Hi, can any one tell me how to convert .xlsx file to .Json file by uploading xlsx file converting it into json file and then downloading .json file
Best regards
Ali

推荐答案

按照以下步骤获取所需的输出。



1.阅读.xlsx文件并将所有数据存储在DataTable对象中。

2.创建一个这样的字典对象,例如

Dictionary< string,list>< string>> obj = new Dictionary< string,list>< string>>

3.使用所选列的所有行值填充列表对象

4.第一个参数for Dictionary对象将是键,它将引用excel文件中定义的列名。

5.填充字典对象中的所有值后,使用


Follow these steps to get the required output.

1. Read the .xlsx file and store all the data in DataTable object.
2. Make a dictionary object like this e.g
Dictionary<string,list><string>> obj = new Dictionary<string,list><string>>
3. Fill the list object with all the Rows values for selected column
4. the first parameter for Dictionary object would be the key and it will refer the column name defined in excel file.
5. Once you fill all the values in the dictionary object, generate the output in Json format by using

JsonConvert.SerializeObject(objectToSerialize)





to使用JsonConvert类包含Dll Newtonsoft.Json。



to use JsonConvert class include the Dll Newtonsoft.Json.


这篇关于如何使用c#将.xlsx文件转换为asp.net中的.Json文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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