public DataValidationResult ValidateData(out List<string> errors) { errors = new List<string>(); var dataValidationResult = DataValidationResult.Good; if (_data.MappingFile.Count == 0) { errors.Add("マッピングデータが空です。"); dataValidationResult = DataValidationResult.NotGood; } else { foreach (ExcelToWordMapping.MappingFileRow mappingFileRow in _data.MappingFile) { List<ContentControl> contentsControlList = null; if (!File.Exists(mappingFileRow.WordTemplateFilePath)) { errors.Add(String.Format("MappingFile内のデータID「{0}」においてワードの雛形「{1}」が存在しません。", mappingFileRow.MappingFileID, mappingFileRow.WordTemplateFilePath)); dataValidationResult = DataValidationResult.NotGood; } else { var wordReader = new WordReader(mappingFileRow.WordTemplateFilePath); wordReader.LoadFile(); contentsControlList = wordReader.GetContentControlTitles(); wordReader.Dispose(); } //if (!Directory.Exists(mappingFileRow.OutputDirPath)) //{ // errors.Add(String.Format("MappingFile内のデータID「{0}」のOutputDirPathの値が「{1}」で存在しません。", mappingFileRow.MappingFileID, mappingFileRow.OutputDirPath)); // dataValidationResult = DataValidationResult.NotGood; //} ExcelToWordMapping.RefSheetRow[] refSheetRows = mappingFileRow.GetRefSheetRows(); foreach (ExcelToWordMapping.RefSheetRow refSheetRow in refSheetRows) { if (!SheetExists(refSheetRow.RefSheetName)) { errors.Add(String.Format("RefSheet内のデータID「{0}」においてシート名「{1}」がエクセルブック内に存在しません。", refSheetRow.RefSheetID, refSheetRow.RefSheetName)); dataValidationResult = DataValidationResult.NotGood; continue; } Dictionary<string, int> columnIdList = _excelReader.GetColumnIdList(refSheetRow.ColumnIdRow, refSheetRow.RefSheetName); ExcelToWordMapping.MappingRow[] mappingRows = refSheetRow.GetMappingRows(); foreach (ExcelToWordMapping.MappingRow mappingRow in mappingRows) { if (!columnIdList.ContainsKey(mappingRow.ExcelColumnIdName)) { errors.Add(String.Format("現在開かれているExcelブック「{0}」のシート「{1}」には列名「{2}」が存在しません。", _excelReader.FilePath, refSheetRow.RefSheetName, mappingRow.ExcelColumnIdName)); dataValidationResult = DataValidationResult.NotGood; } bool controlExists = false; foreach (ContentControl c in contentsControlList) { if (mappingRow.WordContentControlTitle == c.Title) { controlExists = true; } } if ((contentsControlList != null) && (!controlExists)) { errors.Add(String.Format("雛形のワードファイル「{0}」にはコンテンツコントロール「{1}」が存在しません。", mappingFileRow.WordTemplateFilePath, mappingRow.WordContentControlTitle)); dataValidationResult = DataValidationResult.Ok; } } } } } return dataValidationResult; }