엑셀 to json완료
This commit is contained in:
parent
4359369a91
commit
6b92fea565
|
@ -1,4 +1,5 @@
|
||||||
using Aspose.Cells;
|
using Aspose.Cells;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
using NLog;
|
using NLog;
|
||||||
|
|
||||||
namespace Server.Git
|
namespace Server.Git
|
||||||
|
@ -14,10 +15,10 @@ namespace Server.Git
|
||||||
public List<string> variable { get { return _variable; } }
|
public List<string> variable { get { return _variable; } }
|
||||||
List<string> _type;
|
List<string> _type;
|
||||||
public List<string> type { get { return _type; } }
|
public List<string> type { get { return _type; } }
|
||||||
Dictionary<int, List<object>> _dicViewer;
|
Dictionary<long, Dictionary<string, object>> _dicViewer;
|
||||||
public Dictionary<int, List<object>> dicViewer { get { return _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._name = name;
|
||||||
this._variable = variable;
|
this._variable = variable;
|
||||||
|
@ -58,7 +59,7 @@ namespace Server.Git
|
||||||
List<string> variable = new List<string>();
|
List<string> variable = new List<string>();
|
||||||
//변수 타입
|
//변수 타입
|
||||||
List<string> type = 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];
|
Worksheet worksheet = collection[worksheetIndex];
|
||||||
|
@ -70,33 +71,20 @@ namespace Server.Git
|
||||||
//변수 이름과 타입 삽입
|
//변수 이름과 타입 삽입
|
||||||
for (int n = 0; n <= horizontal; n++)
|
for (int n = 0; n <= horizontal; n++)
|
||||||
{
|
{
|
||||||
// Console.Write(worksheet.Cells[i, j].Value + " | ");
|
|
||||||
variable.Add((string)worksheet.Cells[0, n].Value);
|
variable.Add((string)worksheet.Cells[0, n].Value);
|
||||||
type.Add(((string)worksheet.Cells[2, n].Value).ToLower());
|
type.Add(((string)worksheet.Cells[2, n].Value).ToLower());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isIndex = variable[0] == "index";
|
||||||
|
|
||||||
for (int n = 3; n <= vertical; n++)
|
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++)
|
for (int m = 0; m <= horizontal; m++)
|
||||||
{
|
{
|
||||||
switch (type[m])
|
dataList.Add(variable[m], worksheet.Cells[n, m].Value);
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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);
|
sheet sheet = new sheet(worksheet.Name, variable, type, dicViewer);
|
||||||
_sheets.Add(sheet);
|
_sheets.Add(sheet);
|
||||||
|
@ -111,4 +99,4 @@ namespace Server.Git
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,7 @@
|
||||||
namespace Server.Git
|
using Newtonsoft.Json;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Server.Git
|
||||||
{
|
{
|
||||||
public class XlsxToJson : AbstractGit
|
public class XlsxToJson : AbstractGit
|
||||||
{
|
{
|
||||||
|
@ -14,15 +17,13 @@
|
||||||
if (em.Play())
|
if (em.Play())
|
||||||
{
|
{
|
||||||
List<ExcelManager.sheet> sheets = em.sheets;
|
List<ExcelManager.sheet> sheets = em.sheets;
|
||||||
|
Dictionary<string, Dictionary<long, Dictionary<string, object>>> sheetList = new Dictionary<string, Dictionary<long, Dictionary<string, object>>>();
|
||||||
foreach (KeyValuePair<int, List<object>> sheet in sheets[0].dicViewer)
|
for (int n = 0; n < sheets.Count; n++)
|
||||||
{
|
{
|
||||||
foreach (object obj in sheet.Value)
|
sheetList.Add(sheets[n].name, sheets[n].dicViewer);
|
||||||
{
|
|
||||||
//이것을 기반으로 서버 테이블을 생성뒤 데이터를 세팅
|
|
||||||
//Console.WriteLine(obj);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
string test = JsonConvert.SerializeObject(sheetList);
|
||||||
|
Console.WriteLine(test);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -38,4 +39,4 @@
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue