public static string ExportStaticResult(string fileName, IStatResult result, masExcelDrawStatType drawType, string title, int colOffset, bool hasLegend, string xName, string yName) { try { using (StatResultToChartInExcelFile excelControl = new StatResultToChartInExcelFile()) { excelControl.Init(drawType); excelControl.Add(title, result, true, colOffset, false, xName, yName); if (!fileName.ToUpper().EndsWith(".XLSX")) { fileName += ".XLSX"; } excelControl.SaveFile(fileName); } } catch (Exception) { using (StatResultToTxtFile txtControl = new StatResultToTxtFile()) { if (!fileName.ToUpper().EndsWith(".TXT")) { fileName += ".TXT"; } txtControl.WriteResultToTxt(title + "\n"); txtControl.WriteResultToTxt("统计日期:" + DateTime.Today.Date.ToShortDateString() + "\n"); txtControl.WriteResultToTxt(result); bool isSave = txtControl.SaveFile(fileName); if (!isSave) { return(String.Empty); } } } return(fileName); }
//private string CreatTitleByFileName(string fname) //{ // RasterIdentify id = new RasterIdentify(fname); // string identify = id.SubProductIdentify; // if (string.IsNullOrEmpty(identify)) // return null; // switch (identify) // { // case "NDVI": // return "植被指数NDVI面积统计"; // case "0RVI": // return "植被指数RVI面积统计"; // case "0EVI": // return "植被指数EVI面积统计"; // case "0DVI": // return "植被指数DVI面积统计"; // case "0VCI": // return "植被状态指数面积统计"; // case "CHAZ": // return "植被指数差值面积统计"; // default: // return "植被指数面积统计"; // } //} private bool TryCreatExcelFile(IStatResult StatResult, string productTitle, string outFileName) { try { if (File.Exists(outFileName)) { File.Delete(outFileName); } using (StatResultToExcelFile excelControl = new StatResultToExcelFile()) { excelControl.Init(); excelControl.Add(true, productTitle, StatResult, true, 1); if (!outFileName.ToUpper().EndsWith(".XLSX")) { outFileName += ".XLSX"; } excelControl.SaveFile(outFileName); } return(true); } catch (Exception) { using (StatResultToTxtFile txtControl = new StatResultToTxtFile()) { if (!outFileName.ToUpper().EndsWith(".TXT")) { outFileName += ".TXT"; } txtControl.WriteResultToTxt(productTitle + "\n"); txtControl.WriteResultToTxt("统计日期:" + DateTime.Today.Date.ToShortDateString() + "\n"); txtControl.WriteResultToTxt(StatResult); bool isSave = txtControl.SaveFile(outFileName); if (!isSave) { return(false); } } } return(true); }