/// <summary> /// Converts all excel files in the input folder to json and saves them in the output folder. /// Each sheet within an excel file is saved to a separate json file with the same name as the sheet name. /// Files, sheets and columns whose name begin with '~' are ignored. /// </summary> /// <param name="inputPath">Input path.</param> /// <param name="outputPath">Output path.</param> /// <param name="site">The site that the data relates to.</param> public void ConvertExcelFilesToJson(string inputPath, string outputPath, ScenarioSite site) { var excelFiles = GetExcelFileNamesInDirectory(inputPath); Console.WriteLine("Excel To Json Converter: " + excelFiles.Count + " excel files found."); foreach (var file in excelFiles) { if (!ConvertExcelFileToText(file, outputPath, site)) { break; } } }
/// <summary> /// Converts each sheet in the specified excel file to json and saves them in the output folder. /// The name of the processed json file will match the name of the excel sheet. Ignores /// sheets whose name begin with '~'. Also ignores columns whose names begin with '~'. /// </summary> /// <returns><c>true</c>, if excel file was successfully converted to json, <c>false</c> otherwise.</returns> /// <param name="filePath">File path.</param> /// <param name="outputPath">Output path.</param> public bool ConvertExcelFileToText(string filePath, string outputPath, ScenarioSite scenarioSite) { var outputFileName = "ScenarioInformation_" + scenarioSite; Console.WriteLine("Excel To Json Converter: Processing: " + filePath); var excelData = GetExcelDataSet(filePath); if (excelData == null) { Console.WriteLine("Excel To Json Converter: Failed to process file: " + filePath); return(false); } WriteTextToFile(excelData, outputPath + "/" + outputFileName + ".txt"); return(true); }