엑셀 to json완료

This commit is contained in:
김판돌 2023-11-20 21:14:38 +09:00
parent 4359369a91
commit 6b92fea565
6 changed files with 21 additions and 32 deletions

View File

@ -1,4 +1,5 @@
using Aspose.Cells;
using Microsoft.AspNetCore.Http;
using NLog;
namespace Server.Git
@ -14,10 +15,10 @@ namespace Server.Git
public List<string> variable { get { return _variable; } }
List<string> _type;
public List<string> type { get { return _type; } }
Dictionary<int, List<object>> _dicViewer;
public Dictionary<int, List<object>> dicViewer { get { return _dicViewer; } }
Dictionary<long, Dictionary<string, object>> _dicViewer;
public Dictionary<long, Dictionary<string, object>> dicViewer { get { return _dicViewer; } }
public sheet(string name, List<string> variable, List<string> type, Dictionary<int, List<object>> dicViewer)
public sheet(string name, List<string> variable, List<string> type, Dictionary<long, Dictionary<string, object>> dicViewer)
{
this._name = name;
this._variable = variable;
@ -58,7 +59,7 @@ namespace Server.Git
List<string> variable = new List<string>();
//변수 타입
List<string> type = new List<string>();
Dictionary<int, List<object>> dicViewer = new Dictionary<int, List<object>>();
Dictionary<long, Dictionary<string, object>> dicViewer = new Dictionary<long, Dictionary<string, object>>();
// 인덱스를 사용하여 워크시트 가져오기
Worksheet worksheet = collection[worksheetIndex];
@ -70,33 +71,20 @@ namespace Server.Git
//변수 이름과 타입 삽입
for (int n = 0; n <= horizontal; n++)
{
// Console.Write(worksheet.Cells[i, j].Value + " | ");
variable.Add((string)worksheet.Cells[0, n].Value);
type.Add(((string)worksheet.Cells[2, n].Value).ToLower());
}
bool isIndex = variable[0] == "index";
for (int n = 3; n <= vertical; n++)
{
List<object> dataList = new List<object>();
Dictionary<string, object> dataList = new Dictionary<string, object>();
for (int m = 0; m <= horizontal; m++)
{
switch (type[m])
{
case "enum":
case "int":
dataList.Add(worksheet.Cells[n, m].Value);
break;
case "string":
case "text":
case "time":
dataList.Add(worksheet.Cells[n, m].Value);
break;
default:
Console.WriteLine("알수없는 타입의 메세지 입니다.");
break;
}
dataList.Add(variable[m], worksheet.Cells[n, m].Value);
}
dicViewer.Add(n, dataList);
dicViewer.Add((int)(isIndex ? worksheet.Cells[n, 0].Value : n - 3), dataList);
}
sheet sheet = new sheet(worksheet.Name, variable, type, dicViewer);
_sheets.Add(sheet);

View File

@ -1,4 +1,7 @@
namespace Server.Git
using Newtonsoft.Json;
using System.Collections.Generic;
namespace Server.Git
{
public class XlsxToJson : AbstractGit
{
@ -14,15 +17,13 @@
if (em.Play())
{
List<ExcelManager.sheet> sheets = em.sheets;
foreach (KeyValuePair<int, List<object>> sheet in sheets[0].dicViewer)
Dictionary<string, Dictionary<long, Dictionary<string, object>>> sheetList = new Dictionary<string, Dictionary<long, Dictionary<string, object>>>();
for (int n = 0; n < sheets.Count; n++)
{
foreach (object obj in sheet.Value)
{
//이것을 기반으로 서버 테이블을 생성뒤 데이터를 세팅
//Console.WriteLine(obj);
}
sheetList.Add(sheets[n].name, sheets[n].dicViewer);
}
string test = JsonConvert.SerializeObject(sheetList);
Console.WriteLine(test);
}
else
{

Binary file not shown.

Binary file not shown.