public void BtnOutPutToExcel_Click() { using (var xls = new ExcelBase()) { xls.Open(); xls.AddWorkSheet(); int nowRowIndex = 0; foreach (var p in _process) { xls.ExlWorkSheet.Cells[++nowRowIndex, 1] = "进程:" + p.ProcessAliasName + ":" + p.MainWindowTitle + "(" + p.RemarkName + ")"; xls.ExlWorkSheet.Cells[nowRowIndex, 2] = "用户总用时:" + SpyerProcess.GetMillToString(p.SumUsedTime()); // +"ms"; xls.ExlWorkSheet.Cells[++nowRowIndex, 1] = "焦点时间"; xls.ExlWorkSheet.Cells[nowRowIndex, 2] = "失去焦点时间"; xls.ExlWorkSheet.Cells[nowRowIndex, 3] = "间隔时间"; foreach (var r in p) { xls.ExlWorkSheet.Cells[++nowRowIndex, 1] = SpyerProcess.GetMillToString(r.Begin); // r.Begin; xls.ExlWorkSheet.Cells[nowRowIndex, 2] = SpyerProcess.GetMillToString(r.End); xls.ExlWorkSheet.Cells[nowRowIndex, 3] = SpyerProcess.GetMillToString(r.AliveLength); } nowRowIndex++; } xls.SaveAs(Application.StartupPath + string.Format(@"\Inst-{0:D}.xls", DateTime.Today)); } }
// [MenuItem("工具/打包")] // public static void Pack() // { // //打包所有AB // BuildPipeline.BuildAssetBundles(AssetBundleManager.BundleTargetPath, BuildAssetBundleOptions.ChunkBasedCompression, EditorUserBuildSettings.activeBuildTarget); // AssetDatabase.Refresh();//刷新界面 // // GameObject.Instantiate(AssetDatabase.LoadAssetAtPath<GameObject>("Assets/Prefabs/Attack.prefab")) ; // } // [MenuItem("工具/SetXml")] // public static void SetXml() // { // // TestXml test = SetXmlInfo(); // MonsterData test = new MonsterData(); // test.Construction(); // SerializeXml(test); // // SerializeXml(test); //序列化成XML // // SerializeBinary(test); //序列化成二进制 // } // [MenuItem("工具/GetXml")] // public static void GetXml() // { // // TestXml test = DeserializeXml(); //XML反序列化 // // TestXml test = DeserializeBinary(); //二进制反序列化 // // LogTool.Log("ID:",test.ID,"Name:",test.Name,"List:",test.List); // DeserializeAsset(); //Unity的Asset序列化 // } // public static TestXml SetXmlInfo() // { // TestXml test = new TestXml(); // test.ID = 1; // test.Name = "AB"; // test.List = new List<int>(); // test.List.Add(1); // test.List.Add(2); // test.List.Add(3); // return test; // } #region Xml //序列化成XML public static void SerializeXml(ExcelBase test) { FileStream fs = new FileStream(Application.dataPath + "/Script/7-Frame/1-Xml/test.xml", FileMode.Create); StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.UTF8); XmlSerializer xs = new XmlSerializer(test.GetType()); xs.Serialize(sw, test); sw.Close(); fs.Close(); }
/// <summary> /// 查找data /// </summary> /// <param name="path">路径</param> /// <typeparam name="T">ExcelBase类</typeparam> /// <returns></returns> public T FindData <T>(string path) where T : ExcelBase { if (string.IsNullOrEmpty(path)) { return(null); } ExcelBase data = null; if (!m_ExcelDataDic.TryGetValue(path, out data)) { data = LoadData <T>(path); } return(data as T); }
public void btnImport_Click(object sender, EventArgs e) { try { ExcelBase L_ExcelBase = new ExcelBase();//("SYS_MENU_History", mSysMenuHistory); L_ExcelBase.ShowDialog(); if (L_ExcelBase.DialogResult == DialogResult.OK) { L_ExcelBase.Close(); } else { } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void btnImport_Click(object sender, EventArgs e) { try { ExcelBase L_ExcelBase = new ExcelBase(); L_ExcelBase.ShowDialog(); if (L_ExcelBase.DialogResult == DialogResult.OK) { L_ExcelBase.Close(); } else { } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
/// <summary> /// 根据路径查找数据 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="path"></param> /// <returns></returns> public T FindData <T>(string path) where T : ExcelBase { if (string.IsNullOrEmpty(path)) { return(null); } ExcelBase excelBase = null; if (m_AllExcelData.TryGetValue(path, out excelBase)) { return(excelBase as T); } else { excelBase = LoadData <T>(path); } return(null); }
public T FindData <T>(string path) where T : ExcelBase { if (string.IsNullOrEmpty(path)) { Debug.LogError("路径为空"); return(null); } ExcelBase excelBase = null; if (m_AllExcelData.TryGetValue(path, out excelBase)) { return(excelBase as T); } else { //加载 excelBase = LoadData <T>(path); return(excelBase as T); } //return null; }
public string getClientConfigData(string excelFilePath) { StringBuilder sb = new StringBuilder(); char saparator = '\t'; using (ExcelBase h = new ExcelBase(excelFilePath, null)) { var allSheets = h.GetAllSheetNameList(); sb.Append("DataObject").Append(saparator).Append("Alias").AppendLine(); allSheets.ForEach(s => sb.Append(s).Append(saparator).Append(s).AppendLine()); sb.AppendLine(); sb.Append("DataObject").Append(saparator).Append("DataFieldName").Append(saparator).Append("Alias").AppendLine(); foreach (var sheet in allSheets) { var dt = h.GetHeaderRowDataTable(sheet); foreach (DataColumn c in dt.Columns) { sb.Append(sheet).Append(saparator).Append(c.ColumnName).Append(saparator).Append(c.ColumnName).AppendLine(); } } } return(sb.ToString()); }
/* * private void SetAssetBundleFileSeqence(string path , string assetBundle , string debug ) { * try { * foreach (string file in Directory.GetFiles(path)) { * if (Path.GetExtension(file) != ".meta") { * string assetPath = file.Substring(file.IndexOf("Assets")); * AssetImporter.GetAtPath(assetPath).SetAssetBundleNameAndVariant(assetBundle + "/" + Path.GetFileNameWithoutExtension(assetPath), ""); * } * } * Debug.Log("#設定AssetBundle:" + debug +"設定成功"); * } catch { * Debug.Log("#設定AssetBundle:" + debug + "設定失敗"); * } * } * * private void SetAssetBundleDirectorySeqence(string path, string assetBundle, string debug) { * try { * string[] subPath = Directory.GetDirectories(path); * foreach (string filePath in subPath) { * foreach (string file in Directory.GetFiles(filePath)) { * if (Path.GetExtension(file) != ".meta") { * string assetPath = file.Substring(file.IndexOf("Assets")); * AssetImporter assetImporter = AssetImporter.GetAtPath(assetPath); * assetImporter.SetAssetBundleNameAndVariant(assetBundle + "/[" + filePath.Substring(filePath.LastIndexOf(assetBundle) + assetBundle.Length + 1) + "]" + Path.GetFileNameWithoutExtension(assetPath), ""); * if (assetBundle == "Gallery") { * TextureImporter importer = assetImporter as TextureImporter; * TextureImporterSettings texSettings = new TextureImporterSettings(); * * importer.textureType = TextureImporterType.Sprite; * importer.ReadTextureSettings(texSettings); * //importer.SetPlatformTextureSettings(,"Standalone", 2048, TextureImporterFormat.); * //importer.SetPlatformTextureSettings("iPhone", 2048, TextureImporterFormat.PVRTC_RGBA4); * //importer.SetPlatformTextureSettings("Android", 2048, TextureImporterFormat.ETC_RGB4, 1, true); * importer.SetTextureSettings(texSettings); * importer.SaveAndReimport(); * } * } * } * } * Debug.Log("#設定AssetBundle:" + debug + "設定成功"); * } catch { * Debug.Log("#設定AssetBundle:" + debug + "設定失敗"); * } * }*/ private void ReadXLSX <T>(string xmlName, string dataBasePath, string tabName, string dataPath, bool shiftMode = false) where T : BaseType { logList = new List <string>(); ExcelBase xls = new ExcelBase(); try { xls = ExcelHelper.LoadExcel(dataBasePath + xmlName + ".xlsx"); } catch { Debug.LogError("#DatabaseImporter : ReadXLSX Failed : 請確認 Excel 是否關閉..."); } for (int i = 0; i < xls.Tables.Count; i++) { if (xls.Tables[i].TableName == tabName) { Debug.Log("@DatabaseImporter : ReadXLSX Success : " + xls.Tables[i].TableName + "..."); if (!Directory.Exists(PathSetting.resourcesPath + dataPath)) { Directory.CreateDirectory(PathSetting.resourcesPath + dataPath); } for (int row = 3; row <= xls.Tables[i].NumberOfRows; row++) { if (shiftMode && row % 2 == 0) { continue; } T data = CreateInstance <T>(); int id; bool newMode = true; for (int column = 1; column <= xls.Tables[i].NumberOfColumns; column++) { string value = (xls.Tables[i].GetValue(row, column)).ToString(); //必須有ID if (column == 1 && string.IsNullOrEmpty(value.Trim())) { break; } else { //檢查是否有檔案 決定新增或是複寫 if (column == 1) { int.TryParse(value, out id); data = Resources.Load <T>(dataPath + id.ToString("0000")); if (data == null) { data = CreateInstance <T>(); } else { newMode = false; data.ImportReset(); } } //錯誤時中止執行 if (data.GetType() == typeof(Biome)) { if (!BiomeSpawner(data as Biome, column, value.Trim())) { logList.Add("#匯入 Biome 資料第" + row + "行,第" + column + "列格式有誤"); break; } } else if (data.GetType() == typeof(Cterrain)) { if (!CTerrainSpawner(data as Cterrain, column, value.Trim())) { logList.Add("#匯入 Cterrain 資料第" + row + "行,第" + column + "列格式有誤"); break; } } else if (data.GetType() == typeof(Building)) { if (!BuildingSpawner(data as Building, column, value.Trim())) { logList.Add("#匯入 Building 資料第" + row + "行,第" + column + "列格式有誤"); break; } } else if (data.GetType() == typeof(Species)) { if (!SpeciesSpawner(data as Species, column, value.Trim())) { logList.Add("#匯入 Species 資料第" + row + "行,第" + column + "列格式有誤"); break; } } else if (data.GetType() == typeof(WeaponData)) { if (!WeaponsSpawner(data as WeaponData, column, value.Trim())) { logList.Add("#匯入 WeaponDatas 資料第" + row + "行,第" + column + "列格式有誤"); break; } } //新增或複寫 if (column == xls.Tables[i].NumberOfColumns) { if (newMode) { AssetDatabase.CreateAsset(data, PathSetting.resourcesPath + dataPath + data.sID.ToString("0000") + ".asset"); } else { EditorUtility.SetDirty(data); } } } } } break; } /* else if (xls.Tables[i].TableName == "GalleryDatabase" && (importHandler == 0 || importHandler == 2)) { * Debug.Log("@DatabaseImporter : ReadXLSX Success : " + xls.Tables[i].TableName + "..."); * for (int row = 3; row <= xls.Tables[i].NumberOfRows; row++) { * ImageData image = ScriptableObject.CreateInstance<ImageData>(); * * for (int column = 1; column <= xls.Tables[i].NumberOfColumns; column++) { * string value = (xls.Tables[i].GetValue(row, column)).ToString(); * if (column == 1 && string.IsNullOrEmpty(value)) { * break; * * } else if (!ImageSpawner(image, column, value)) { * logList.Add("#匯入資料第" + row + "行,第" + column + "列格式有誤"); * break; * } * } * } * * } else if (xls.Tables[i].TableName == "LangDatabase" && (importHandler == 0 || importHandler == 3)) { * Debug.Log("@DatabaseImporter : ReadXLSX Success : " + xls.Tables[i].TableName + "..."); * LangData lang = ScriptableObject.CreateInstance<LangData>(); * for (int row = 3; row <= xls.Tables[i].NumberOfRows; row++) { * for (int column = 1; column <= xls.Tables[i].NumberOfColumns; column++) { * string value = (xls.Tables[i].GetValue(row, column)).ToString(); * if (column == 1 && string.IsNullOrEmpty(value)) { * break; * * } else if (!LangSpawner(lang, column, value)) { * logList.Add("#匯入資料第" + row + "行,第" + column + "列格式有誤"); * break; * } * } * } * AssetDatabase.CreateAsset(lang, PathSetting.LangDBAssetPath + "LangData.asset"); * }*/ } LogImportInfo(); }