private static bool ReadExcel() { ExcelPackage package = TableExcelLoader.Load("ExampleData"); if (null == package) { return(false); } ExcelWorksheet sheet = package.Workbook.Worksheets["ExampleData"]; if (null == sheet) { return(false); } int defaultKey = new int(); for (int index = 1; index <= sheet.Dimension.Rows; ++index) { var tableData = new ExampleData(); int innerIndex = 1; { tableData.ID = sheet.Cells[index, innerIndex++].GetValue <int>(); tableData.Name = ExcelTools.GetCellString(sheet.Cells[index, innerIndex++]); tableData.FloatValue = sheet.Cells[index, innerIndex++].GetValue <float>(); try { tableData.EnumValue = (TestEnum)Enum.Parse(typeof(TestEnum), ExcelTools.GetCellString(sheet.Cells[index, innerIndex++])); } catch (System.Exception ex) { Debug.LogException(ex); } int length_FixedList_4 = 5; int count_FixedList_4 = sheet.Cells[index, innerIndex++].GetValue <int>(); tableData.FixedList = new int[count_FixedList_4]; for (int index_FixedList_4 = 0; index_FixedList_4 < length_FixedList_4; ++index_FixedList_4) { if (index_FixedList_4 >= count_FixedList_4) { break; } tableData.FixedList[index_FixedList_4] = sheet.Cells[index, innerIndex++].GetValue <int>(); } int length_AutoList_4 = 5; int count_AutoList_4 = sheet.Cells[index, innerIndex++].GetValue <int>(); tableData.AutoList = new int[count_AutoList_4]; for (int index_AutoList_4 = 0; index_AutoList_4 < length_AutoList_4; ++index_AutoList_4) { if (index_AutoList_4 >= count_AutoList_4) { break; } tableData.AutoList[index_AutoList_4] = sheet.Cells[index, innerIndex++].GetValue <int>(); } ExampleInnerData obj_InnerData_4 = new ExampleInnerData(); { obj_InnerData_4.ID = sheet.Cells[index, innerIndex++].GetValue <int>(); int length_AutoList_5 = 5; int count_AutoList_5 = sheet.Cells[index, innerIndex++].GetValue <int>(); obj_InnerData_4.AutoList = new ExampleInnerInnerData[count_AutoList_5]; for (int index_AutoList_5 = 0; index_AutoList_5 < length_AutoList_5; ++index_AutoList_5) { if (index_AutoList_5 >= count_AutoList_5) { break; } { obj_InnerData_4.AutoList[index_AutoList_5].ID = sheet.Cells[index, innerIndex++].GetValue <int>(); try { obj_InnerData_4.AutoList[index_AutoList_5].EnumValue = (TestEnum)Enum.Parse(typeof(TestEnum), ExcelTools.GetCellString(sheet.Cells[index, innerIndex++])); } catch (System.Exception ex) { Debug.LogException(ex); } } } } tableData.InnerData = obj_InnerData_4; int length_InnerDataList_4 = 5; int count_InnerDataList_4 = sheet.Cells[index, innerIndex++].GetValue <int>(); tableData.InnerDataList = new ExampleInnerData[count_InnerDataList_4]; for (int index_InnerDataList_4 = 0; index_InnerDataList_4 < length_InnerDataList_4; ++index_InnerDataList_4) { if (index_InnerDataList_4 >= count_InnerDataList_4) { break; } { tableData.InnerDataList[index_InnerDataList_4].ID = sheet.Cells[index, innerIndex++].GetValue <int>(); int length_AutoList_6 = 5; int count_AutoList_6 = sheet.Cells[index, innerIndex++].GetValue <int>(); tableData.InnerDataList[index_InnerDataList_4].AutoList = new ExampleInnerInnerData[count_AutoList_6]; for (int index_AutoList_6 = 0; index_AutoList_6 < length_AutoList_6; ++index_AutoList_6) { if (index_AutoList_6 >= count_AutoList_6) { break; } { tableData.InnerDataList[index_InnerDataList_4].AutoList[index_AutoList_6].ID = sheet.Cells[index, innerIndex++].GetValue <int>(); try { tableData.InnerDataList[index_InnerDataList_4].AutoList[index_AutoList_6].EnumValue = (TestEnum)Enum.Parse(typeof(TestEnum), ExcelTools.GetCellString(sheet.Cells[index, innerIndex++])); } catch (System.Exception ex) { Debug.LogException(ex); } } } } } } if (tableData.ID == defaultKey) { continue; } var existKey = m_data.Find(innerItem => innerItem.ID == tableData.ID); if (null != existKey) { Debug.LogWarning(string.Format("Already has the key {0}, replace the old data.", tableData.ID)); m_data.Remove(existKey); } m_data.Add(tableData); } return(true); }
public static bool Load() { byte[] bytes = TableBytesLoader.Load("ExampleData"); if (null == bytes) { return(false); } using (MemoryStream stream = new MemoryStream(bytes)) { using (BinaryReader reader = new BinaryReader(stream)) { m_data = new Dictionary <int, ExampleData>(); int dataCount = reader.ReadInt32(); for (int index = 0; index < dataCount; ++index) { ExampleData tableData = new ExampleData(); { tableData.ID = reader.ReadInt32(); tableData.Name = reader.ReadString(); tableData.FloatValue = reader.ReadSingle(); tableData.EnumValue = (TestEnum)reader.ReadInt32(); int count_FixedList_6 = reader.ReadInt32(); tableData.FixedList = new int[count_FixedList_6]; for (int index_FixedList_6 = 0; index_FixedList_6 < count_FixedList_6; ++index_FixedList_6) { tableData.FixedList[index_FixedList_6] = reader.ReadInt32(); } int count_AutoList_6 = reader.ReadInt32(); tableData.AutoList = new int[count_AutoList_6]; for (int index_AutoList_6 = 0; index_AutoList_6 < count_AutoList_6; ++index_AutoList_6) { tableData.AutoList[index_AutoList_6] = reader.ReadInt32(); } ExampleInnerData obj_InnerData_6 = new ExampleInnerData(); { obj_InnerData_6.ID = reader.ReadInt32(); int count_AutoList_7 = reader.ReadInt32(); obj_InnerData_6.AutoList = new ExampleInnerInnerData[count_AutoList_7]; for (int index_AutoList_7 = 0; index_AutoList_7 < count_AutoList_7; ++index_AutoList_7) { obj_InnerData_6.AutoList[index_AutoList_7].ID = reader.ReadInt32(); obj_InnerData_6.AutoList[index_AutoList_7].EnumValue = (TestEnum)reader.ReadInt32(); } } tableData.InnerData = obj_InnerData_6; int count_InnerDataList_6 = reader.ReadInt32(); tableData.InnerDataList = new ExampleInnerData[count_InnerDataList_6]; for (int index_InnerDataList_6 = 0; index_InnerDataList_6 < count_InnerDataList_6; ++index_InnerDataList_6) { tableData.InnerDataList[index_InnerDataList_6].ID = reader.ReadInt32(); int count_AutoList_7 = reader.ReadInt32(); tableData.InnerDataList[index_InnerDataList_6].AutoList = new ExampleInnerInnerData[count_AutoList_7]; for (int index_AutoList_7 = 0; index_AutoList_7 < count_AutoList_7; ++index_AutoList_7) { tableData.InnerDataList[index_InnerDataList_6].AutoList[index_AutoList_7].ID = reader.ReadInt32(); tableData.InnerDataList[index_InnerDataList_6].AutoList[index_AutoList_7].EnumValue = (TestEnum)reader.ReadInt32(); } } } m_data.Add(tableData.ID, tableData); } } } return(true); }
private static bool ReadExcel() { ExcelPackage package = TableExcelLoader.Load("ExampleData"); if (null == package) { return false; } ExcelWorksheet sheet = package.Workbook.Worksheets["ExampleData"]; if (null == sheet) { return false; } int defaultKey = new int(); for (int index = 1; index <= sheet.Dimension.Rows; ++index) { var tableData = new ExampleData(); int innerIndex = 1; { tableData.ID = sheet.Cells[index, innerIndex++].GetValue<int>(); tableData.Name = sheet.Cells[index, innerIndex++].GetValue<string>(); tableData.FloatValue = sheet.Cells[index, innerIndex++].GetValue<float>(); try { tableData.EnumValue = (TestEnum)Enum.Parse(typeof(TestEnum), sheet.Cells[index, innerIndex++].GetValue<string>()); } catch(System.Exception ex) { Debug.LogException(ex); } int count_FixedList_4 = 5; tableData.FixedList = new int[count_FixedList_4]; for (int index_FixedList_4 = 0; index_FixedList_4 < count_FixedList_4; ++index_FixedList_4) { tableData.FixedList[index_FixedList_4] = sheet.Cells[index, innerIndex++].GetValue<int>(); } int count_AutoList_4 = sheet.Cells[index, innerIndex++].GetValue<int>(); tableData.AutoList = new int[count_AutoList_4]; for (int index_AutoList_4 = 0; index_AutoList_4 < count_AutoList_4; ++index_AutoList_4) { tableData.AutoList[index_AutoList_4] = sheet.Cells[index, innerIndex++].GetValue<int>(); } ExampleInnerData obj_InnerData_4 = new ExampleInnerData(); { obj_InnerData_4.ID = sheet.Cells[index, innerIndex++].GetValue<int>(); int count_AutoList_5 = sheet.Cells[index, innerIndex++].GetValue<int>(); obj_InnerData_4.AutoList = new ExampleInnerInnerData[count_AutoList_5]; for (int index_AutoList_5 = 0; index_AutoList_5 < count_AutoList_5; ++index_AutoList_5) { obj_InnerData_4.AutoList[index_AutoList_5].ID = sheet.Cells[index, innerIndex++].GetValue<int>(); try { obj_InnerData_4.AutoList[index_AutoList_5].EnumValue = (TestEnum)Enum.Parse(typeof(TestEnum), sheet.Cells[index, innerIndex++].GetValue<string>()); } catch(System.Exception ex) { Debug.LogException(ex); } } } tableData.InnerData = obj_InnerData_4; int count_InnerDataList_4 = sheet.Cells[index, innerIndex++].GetValue<int>(); tableData.InnerDataList = new ExampleInnerData[count_InnerDataList_4]; for (int index_InnerDataList_4 = 0; index_InnerDataList_4 < count_InnerDataList_4; ++index_InnerDataList_4) { tableData.InnerDataList[index_InnerDataList_4].ID = sheet.Cells[index, innerIndex++].GetValue<int>(); int count_AutoList_5 = sheet.Cells[index, innerIndex++].GetValue<int>(); tableData.InnerDataList[index_InnerDataList_4].AutoList = new ExampleInnerInnerData[count_AutoList_5]; for (int index_AutoList_5 = 0; index_AutoList_5 < count_AutoList_5; ++index_AutoList_5) { tableData.InnerDataList[index_InnerDataList_4].AutoList[index_AutoList_5].ID = sheet.Cells[index, innerIndex++].GetValue<int>(); try { tableData.InnerDataList[index_InnerDataList_4].AutoList[index_AutoList_5].EnumValue = (TestEnum)Enum.Parse(typeof(TestEnum), sheet.Cells[index, innerIndex++].GetValue<string>()); } catch(System.Exception ex) { Debug.LogException(ex); } } } } if (tableData.ID == defaultKey) { continue; } var existKey = m_data.Find(innerItem => innerItem.ID == tableData.ID); if (null != existKey) { Debug.LogWarning(string.Format("Already has the key {0}, replace the old data.", tableData.ID)); m_data.Remove(existKey); } m_data.Add(tableData); } return true; }