//根据XML文件全路径构造路径和配置类对应关系(得到一个xml文件对应的所有excel然后构造config对象存放到configs中) private void AddConfigsByXmlFullName(string xmlFullName) { string excelDirectory = MyFilleBase.GetDirectoryByFullName(xmlFullName);//根据路径取得对应的目录 Config config=null; FileSearch.InitFileInfoList(); List<string> excelFullNames = FileSearch.GetFileInfo(MyFilleBase.GetFileNameWithoutExtension(xmlFullName), excelDirectory, true, true);//根据xml的名称搜索包含此名称的文件 if (excelFullNames.Count >= 1) { foreach (string excelFullName in excelFullNames) { if (excelFullNames.IndexOf(".xls") != -1)//必须是excel文件(排除xml文件) { config = new Config(xmlFullName); configs.Add(excelFullName, config); } } } else { throw new Exception("所指定模板不包含对应的Excel文件,请重新指定!"); } }
//根据XML文件全路径构造路径和配置类对应关系(此种情况由于只有一个xml,必然对应一个或多个excel文件,所以只需要查找excel文件即可) private void AddConfigsByXmlFullNameHasNothingToExcelname(string xmlFullName) { Config config = null; string excelDirectory=MyFilleBase.GetDirectoryByFullName(xmlFullName); FileSearch.InitFileInfoList(); List<string> excelFullNames = FileSearch.GetFileInfo(".xls", excelDirectory, true, true); if (excelFullNames.Count >= 1) { foreach (string excelFullName in excelFullNames) { config = new Config(xmlFullName); configs.Add(excelFullName, config); } } else { throw new Exception("所指定模板不包含对应的Excel文件,请重新指定!"); } }
//根据Excel全路径构造路径和配置类对应关系(主要用于指导Excel全路径的情况) private void AddConfigByExcelFullName(string excelFullName) { string excelConfigFileFullName = MyFilleBase.GetDirectoryByFullName(excelFullName) + "\\" + MyFilleBase.GetFileNameWithoutExtension(excelFullName) + ".xml"; Config config=null; if (MyFilleBase.FileBeing(excelConfigFileFullName)) { config = new Config(excelConfigFileFullName);//创建配置(Config)对象 configs.Add(excelFullName, config); } else { throw new Exception("所指定文件没有对应的配置文件,请重新指定!"); } }