private void btnOptDesign_Click(object sender, EventArgs e) { try { for (int i = 0; i < Config.designer_opt_configs.Count; i++) { Output_designer_config optRequest = Config.designer_opt_configs[i]; Excel.Workbook src_book = new Excel.Workbook(optRequest.src_path); Excel.Worksheet src_sheet = src_book.Worksheets[optRequest.src_sheet]; SheetHeader src_sheet_header = new SheetHeader(); src_sheet_header.readHeader(src_sheet, optRequest.src_head_row); src_sheet_header.readDataWithIndex(optRequest.src_pm_key, optRequest.src_row_beg); Excel.Workbook tar_book = new Excel.Workbook(optRequest.tar_path); Excel.Worksheet tar_sheet = tar_book.Worksheets[optRequest.tar_sheet]; SheetHeader tar_sheet_header = new SheetHeader(); tar_sheet_header.readHeader(tar_sheet, optRequest.tar_head_row); tar_sheet_header.readDataWithIndex(optRequest.tar_pm_key, optRequest.tar_row_beg); ExcelTableConvert.convert(src_sheet_header, tar_sheet_header, optRequest.src_cols, optRequest.tar_cols); tar_book.Save(optRequest.tar_path); } } catch (Exception ex) { Debug.Error(ex.ToString()); } Debug.Info("导出完成"); }
public static void load() { XmlDocument xmlPathDoc = new XmlDocument(); if (!File.Exists("config.xml")) { Debug.Error("配置文件config.xml缺失"); return; } xmlPathDoc.Load("config.xml"); XmlNode xmlroot = xmlPathDoc.SelectSingleNode("root"); //读取策划数据包名 packageName = xmlroot.SelectSingleNode("package").Attributes["name"].Value; //APP设置 //XmlNode appNode = xmlroot.SelectSingleNode("app"); //isRealeace = bool.Parse(appNode.Attributes["isRelease"].Value); //设置策划表路径 XmlNode xmlPathNode = xmlroot.SelectSingleNode("path"); //luaByte输出路径 if (xmlPathNode.Attributes["export"] != null) { export_path = xmlPathNode.Attributes["export"].Value; } excelPath = xmlPathNode.Attributes["excelPath"].Value; var attrNode = xmlPathNode.Attributes["indexPath"]; if (attrNode == null) { bReadIndex = false; } else { indexPath = xmlPathNode.Attributes["indexPath"].Value; if (!File.Exists(indexPath)) { Debug.Error("index路径 \"" + indexPath + "\" 不正确"); return; } } var luaPathNode = xmlPathNode.Attributes["lua_cfg"]; if (luaPathNode != null) { luaCfgPath = xmlPathNode.Attributes["lua_cfg"].Value; bLoadLua = true; } if (xmlPathNode.Attributes["assetPath"] != null) { assetPath = xmlPathNode.Attributes["assetPath"].Value; } //加载导出服务端路径和客户端路径 string strCliPath = xmlPathNode.Attributes["cli"].Value; cliPath = strCliPath.Split('|')[0]; string strSrvPath = xmlPathNode.Attributes["serv"].Value; servPath = strSrvPath.Split('|')[0]; //加载拷贝路径 XmlNode copyNode = xmlroot.SelectSingleNode("copyPath"); if (copyNode != null) { string strCopyCliPath = copyNode.Attributes["cli"].Value; copyCliPath = strCopyCliPath.Split('|'); string strCopySrvPath = copyNode.Attributes["serv"].Value; copyServPath = strCopySrvPath.Split('|'); bCopy = true; } //修正路径 cliPath = __rectify_folder_path(cliPath); servPath = __rectify_folder_path(servPath); if (bCopy) { for (int i = 0; i < copyCliPath.Length; i++) { copyCliPath[i] = __rectify_folder_path(copyCliPath[i]); } for (int i = 0; i < copyServPath.Length; i++) { copyServPath[i] = __rectify_folder_path(copyServPath[i]); } } //检测所配置的路径是否有误 string[] pathes = new string[2 + (bCopy ? copyCliPath.Length + copyServPath.Length:0)]; pathes[0] = cliPath; pathes[1] = servPath; if (bCopy) { Array.Copy(copyCliPath, 0, pathes, 2, copyCliPath.Length); Array.Copy(copyServPath, 0, pathes, 2 + copyCliPath.Length, copyServPath.Length); } for (int i = 0; i < pathes.Length; i++) { if (!Directory.Exists(pathes[i])) { if (i < 2) { Directory.CreateDirectory(pathes[i]); } else { Debug.Exception("没有找到路径{0},请检查配置后重新启动软件", pathes[i]); return; } } } if (assetPath == null || !Directory.Exists(assetPath)) { isTestAssetPath = false; if (assetPath != null) { Debug.Info("没有找到路径: {0},将不会对资源进行检测", assetPath); } } //设置设计表相关路径 XmlNode attrDesignerNode = xmlroot.SelectSingleNode("attrDesigner"); if (attrDesignerNode != null) { attr_designer_Path.path = attrDesignerNode.Attributes["path"].Value; attr_designer_Path.sheets = attrDesignerNode.Attributes["sheets"].Value.Split(';'); } //要导出的表 XmlNode outputFilesNode = xmlroot.SelectSingleNode("outputFiles"); if (outputFilesNode != null) { string root = excelPath; if (outputFilesNode.Attributes["root"] != null) { root = outputFilesNode.Attributes["root"].Value; } if (outputFilesNode.Attributes["srcFile"] != null) { srcWordsFilePath = outputFilesNode.Attributes["srcFile"].Value; } XmlNodeList filesNode = outputFilesNode.ChildNodes; List <string> path = new List <string>(); for (int i = 0; i < filesNode.Count; i++) { XmlNode theFileNode = filesNode.Item(i); string fileInnerText = theFileNode.InnerText; string thePath = root + fileInnerText; if (!Path.HasExtension(thePath)) { thePath += ".xlsx"; } path.Add(thePath); } outputFiles = path.ToArray(); } //导出数据配置 XmlNode xmlOptChildrenNodes = xmlroot.SelectSingleNode("designer_outputs"); if (xmlOptChildrenNodes != null) { designer_opt_configs = new List <Output_designer_config>(); var xmlOptChildNodes = xmlOptChildrenNodes.ChildNodes; for (int i = 0; i < xmlOptChildNodes.Count; i++) { XmlElement childrenNode = (XmlElement)xmlOptChildNodes[i]; if (childrenNode.Name != "output") { continue; } Output_designer_config newConfig = new Output_designer_config(); string[] strSrcPath = childrenNode.Attributes["src_path"].Value.Split('!'); newConfig.src_path = strSrcPath[0]; newConfig.src_sheet = strSrcPath[1]; string[] tarSrcPath = childrenNode.Attributes["tar_path"].Value.Split('!'); newConfig.tar_path = tarSrcPath[0]; newConfig.tar_sheet = tarSrcPath[1]; newConfig.src_pm_key = childrenNode.Attributes["src_pm_key"].Value; newConfig.src_head_row = Convert.ToInt32(childrenNode.Attributes["src_head_row"].Value); newConfig.src_row_beg = Convert.ToInt32(childrenNode.Attributes["src_row_beg"].Value); newConfig.tar_pm_key = childrenNode.Attributes["tar_pm_key"].Value; newConfig.tar_head_row = Convert.ToInt32(childrenNode.Attributes["tar_head_row"].Value); newConfig.tar_row_beg = Convert.ToInt32(childrenNode.Attributes["tar_row_beg"].Value); newConfig.src_cols = childrenNode.Attributes["src_opt_cols"].Value.Split(';'); newConfig.tar_cols = childrenNode.Attributes["tar_opt_cols"].Value.Split(';'); designer_opt_configs.Add(newConfig); } } XmlNode xmlSimulator = xmlroot.SelectSingleNode("simulator"); if (xmlSimulator != null) { if (xmlSimulator.Attributes["src"] != null) { simulator_src = xmlSimulator.Attributes["src"].Value; } else { Debug.Exception("simulator节点没找到src属性"); } if (xmlSimulator.Attributes["opt"] != null) { simulator_tar = xmlSimulator.Attributes["opt"].Value; } else { Debug.Exception("simulator节点没找到opt属性"); } } }
public static void load() { XmlDocument xmlPathDoc = new XmlDocument(); if (!File.Exists("config.xml")) { Debug.Info("配置文件config.xml缺失"); return; } xmlPathDoc.Load("config.xml"); XmlNode xmlroot = xmlPathDoc.SelectSingleNode("root"); //读取策划数据包名 packageName = xmlroot.SelectSingleNode("package").Attributes["name"].Value; //APP设置 XmlNode appNode = xmlroot.SelectSingleNode("app"); isRealeace = bool.Parse(appNode.Attributes["isRelease"].Value); //设置策划表路径 XmlNode xmlPathNode = xmlroot.SelectSingleNode("path"); cliPath = xmlPathNode.Attributes["cli"].Value; servPath = xmlPathNode.Attributes["serv"].Value; export_path = xmlPathNode.Attributes["export"].Value; excelPath = xmlPathNode.Attributes["excelPath"].Value; indexPath = xmlPathNode.Attributes["indexPath"].Value; luaCfgPath = xmlPathNode.Attributes["lua_cfg"].Value; if (!Directory.Exists(cliPath)) { Directory.CreateDirectory(cliPath); Debug.Info("客户端文件夹 {0} 不存在,我创建了他", cliPath); } if (!Directory.Exists(servPath)) { Directory.CreateDirectory(servPath); Debug.Info("服务端文件夹 {0} 不存在,我创建了他", servPath); } if (!Directory.Exists(export_path)) { Directory.CreateDirectory(export_path); Debug.Info("服务端文件夹 {0} 不存在,我创建了他", export_path); } //设置设计表相关路径 XmlNode attrDesignerNode = xmlroot.SelectSingleNode("attrDesigner"); if (attrDesignerNode != null) { attr_designer_Path.path = attrDesignerNode.Attributes["path"].Value; attr_designer_Path.sheets = attrDesignerNode.Attributes["sheets"].Value.Split(';'); } //导出数据配置 XmlNode xmlOptChildrenNodes = xmlroot.SelectSingleNode("designer_outputs"); if (xmlOptChildrenNodes != null) { designer_opt_configs = new List <Output_designer_config>(); var xmlOptChildNodes = xmlOptChildrenNodes.ChildNodes; for (int i = 0; i < xmlOptChildNodes.Count; i++) { XmlElement childrenNode = (XmlElement)xmlOptChildNodes[i]; if (childrenNode.Name != "output") { continue; } Output_designer_config newConfig = new Output_designer_config(); string[] strSrcPath = childrenNode.Attributes["src_path"].Value.Split('!'); newConfig.src_path = strSrcPath[0]; newConfig.src_sheet = strSrcPath[1]; string[] tarSrcPath = childrenNode.Attributes["tar_path"].Value.Split('!'); newConfig.tar_path = tarSrcPath[0]; newConfig.tar_sheet = tarSrcPath[1]; newConfig.src_pm_key = childrenNode.Attributes["src_pm_key"].Value; newConfig.src_head_row = Convert.ToInt32(childrenNode.Attributes["src_head_row"].Value); newConfig.src_row_beg = Convert.ToInt32(childrenNode.Attributes["src_row_beg"].Value); newConfig.tar_pm_key = childrenNode.Attributes["tar_pm_key"].Value; newConfig.tar_head_row = Convert.ToInt32(childrenNode.Attributes["tar_head_row"].Value); newConfig.tar_row_beg = Convert.ToInt32(childrenNode.Attributes["tar_row_beg"].Value); newConfig.src_cols = childrenNode.Attributes["src_opt_cols"].Value.Split(';'); newConfig.tar_cols = childrenNode.Attributes["tar_opt_cols"].Value.Split(';'); designer_opt_configs.Add(newConfig); } } XmlNode xmlSimulator = xmlroot.SelectSingleNode("simulator"); if (xmlSimulator != null) { if (xmlSimulator.Attributes["src"] != null) { simulator_src = xmlSimulator.Attributes["src"].Value; } else { Debug.Exception("simulator节点没找到src属性"); } if (xmlSimulator.Attributes["opt"] != null) { simulator_tar = xmlSimulator.Attributes["opt"].Value; } else { Debug.Exception("simulator节点没找到opt属性"); } } }