Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 21-Aug-14 3:03am
v2

1 solution

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 use JsonConvert class include the Dll Newtonsoft.Json.
 
Share this answer
 
Comments
Member 10532069 23-Aug-14 2:25am    
Thanks Sharmanuj
Could you please elaborate the 3rd & 4th step little more.
am not able to understand the point .
If i have n no: of column in excelsheet.
Best regards
Ali
Sharmanuj 4-Dec-14 4:14am    
Hi Ali,

If you have n no of columns in your excel file and want to capture all the columns data in the json file then, your column name would be the key for the dictonary object. And the rows data would be in the list object.

for example if you have 10 rows and 5 columns then list object would contain 10 rows data related to first column and that would get added in dictonary. Similarly for all the columns.

Regards,
Sharmanuj

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900