public static void GridViewToExcel(DataSet MyData, Hashtable nameList, string ReportTitle) { string FilePath = System.Web.HttpContext.Current.Server.MapPath("../") + "ReportFile\\"; if (!Directory.Exists(FilePath)) { Directory.CreateDirectory(FilePath); } //利用excel对象 DataToExcel dte = new DataToExcel(); string filename = ""; try { if (MyData.Tables[0].Rows.Count > 0) { filename = dte.DataExcel(MyData.Tables[0], ReportTitle, FilePath, nameList); } } catch { } if (filename != "") { System.Web.HttpContext.Current.Response.Redirect("../ReportFile/" + filename, true); } }
//public static void GridViewToExcel(DataSet MyData, Hashtable nameList, string ReportTitle) //{ // string FilePath = System.Web.HttpContext.Current.Server.MapPath("../") + "ReportFile\\"; // //����excel���� // DataToExcel dte = new DataToExcel(); // string filename = ""; // try // { // if (MyData.Tables[0].Rows.Count > 0) // { // filename = dte.DataExcel(MyData.Tables[0], ReportTitle, FilePath, nameList); // } // } // catch (Exception e) // { // throw e; // } // if (filename != "") // { // System.Web.HttpContext.Current.Response.Redirect("../ReportFile/" + filename, false); // } //} public static void GridViewToExcel(DataSet MyData, Hashtable nameList, string ReportTitle) { string FilePath = System.Web.HttpContext.Current.Server.MapPath("../") + "ReportFile\\"; //����excel���� DataToExcel dte = new DataToExcel(); string filename = DateTime.Now.ToString("yyyyMMddHHmmssff") + ".xls"; try { if (MyData.Tables[0].Rows.Count > 0) { dte.DataSetToLocalExcel(MyData, FilePath + filename, true, nameList, ReportTitle); } } catch (Exception e) { throw e; } if (filename != "") { System.Web.HttpContext.Current.Response.Redirect("../ReportFile/" + filename, false); } }
//public static void GridViewToExcel(DataSet MyData, Hashtable nameList, string ReportTitle) //{ // string FilePath = System.Web.HttpContext.Current.Server.MapPath("../") + "ReportFile\\"; // //利用excel对象 // DataToExcel dte = new DataToExcel(); // string filename = ""; // try // { // if (MyData.Tables[0].Rows.Count > 0) // { // filename = dte.DataExcel(MyData.Tables[0], ReportTitle, FilePath, nameList); // } // } // catch (Exception e) // { // throw e; // } // if (filename != "") // { // System.Web.HttpContext.Current.Response.Redirect("../ReportFile/" + filename, false); // } //} public static void GridViewToExcel(DataSet MyData, Hashtable nameList, string ReportTitle) { string FilePath = System.Web.HttpContext.Current.Server.MapPath("../") + "ReportFile\\"; //利用excel对象 DataToExcel dte = new DataToExcel(); string filename = DateTime.Now.ToString("yyyyMMddHHmmssff") + ".xls"; try { if (MyData.Tables[0].Rows.Count > 0) { dte.DataSetToLocalExcel(MyData, FilePath + filename, true, nameList, ReportTitle); } } catch (Exception e) { throw e; } if (filename != "") { System.Web.HttpContext.Current.Response.Redirect("../ReportFile/" + filename, false); } }