private string GetJsonInfo() { string text = string.Empty; cellInfo numtype = CellInfos[1]; cellInfo numname = CellInfos[2]; for (int i = 3; i < CellInfos.Count; i++) { for (int j = 0; j < CellInfos[i].info.Count; j++) { text += CellInfos[i].info[j].SerializeJson(numname.info[j], numtype.info[j]); if (j < CellInfos[i].info.Count - 1) { text += ","; } } } text = "{" + text + "}"; return(text); }
private string GetClassInfo() { string cinfo = string.Empty; for (int i = 0; i < head.Count; i++) { cinfo += head[i] + "\r\n"; } string text = string.Empty; cellInfo numinfo = CellInfos[0]; cellInfo numtype = CellInfos[1]; cellInfo numname = CellInfos[2]; for (int i = 0; i < numinfo.info.Count; i++) { string info = numinfo.info[i].SerializeClass(numname.info[i], numtype.info[i]); text += info + "\r\n"; } text = string.Format(baseClass, SheetName) + baseClassinfo.Replace("#", text); cinfo += text; return(cinfo); }
public static void Init() { string path = Directory.GetCurrentDirectory(); JsonSavepath = path + JsonSavepath; string[] files = Directory.GetFiles(path); for (int i = 0; i < files.Length; i++) { if (files[i].IndexOf(fliename0) < 0) { continue; } string file = files[i]; ExcelPackage pack = new ExcelPackage(); FileStream streamReader = File.OpenRead(file); pack.Load(streamReader); int index = streamReader.Name.IndexOf(fliename0); string spath = streamReader.Name.Remove(index); if (Directory.Exists(spath)) { Directory.Delete(spath, true); } Directory.CreateDirectory(spath); List <SheetInfo> sheetInfos = new List <SheetInfo>(); foreach (ExcelWorksheet worksheet in pack.Workbook.Worksheets) { int endrow = worksheet.Cells.End.Row; int endcol = worksheet.Cells.End.Column; SheetInfo sheet = new SheetInfo(); sheet.SheetName = worksheet.Name; sheet.Savepath = spath; for (int j = worksheet.Cells.Start.Row; j < endrow; j++) { cellInfo cinfo = new cellInfo(); if (worksheet.Cells[j, 1].Value == null) { break; } for (int k = worksheet.Cells.Start.Column; k < endcol; k++) { if (worksheet.Cells[j, k].Value == null) { break; } else { cinfo.info.Add(worksheet.Cells[j, k].Value.ToString()); } } sheet.CellInfos.Add(cinfo); } sheetInfos.Add(sheet); } for (int j = 0; j < sheetInfos.Count; j++) { sheetInfos[j].SerializeObject(); } } }