public bool ExportToExcel(string ExcelFileName)
{
try
{
FileOPS.DiskFileName = ExcelFileName;
ExportOptions ExOPS = myReport.ExportOptions;//cr.ExportOptions;
ExOPS.ExportDestinationOptions = FileOPS;
ExOPS.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
ExOPS.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.ExcelRecord;
myReport.Export();//myReport.Export(ExOPS);
System.Web.HttpResponse Response = System.Web.HttpContext.Current.Response;
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;filename=" + ExcelFileName);//下载时要保存的默认文件名
Response.WriteFile(ExcelFileName);
Response.Flush();
Response.Close();
return true;
}
catch (Exception ex)
{
throw ex;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
// 创建Excel文件以及路径
string map = Server.MapPath(@"../ExcelReport");
string url = map + "/MonthReport{0:yyyyMMddHHmmss}.xls";
string ExcelFileName = string.Format(url, DateTime.Now); //字符格式化
bool msg = ExportToExcel(ExcelFileName); //将水晶报表的信息保存到指定文件里
if (msg == true)
{
string URL = "DownLoad.aspx?Path=" + url;
Server.Transfer(URL);
}
}
catch (Exception ex)
{
// ShowMessage(ex.Message);
}
}
有用的EXCEL链接
http://topic.youkuaiyun.com/u/20100428/16/72028ea4-fbab-49f3-b392-12d7524df9d5.html
http://topic.youkuaiyun.com/u/20090707/16/0618de94-4c4b-4186-8d48-f4a8f53117ae.html(完美Excel)
http://www.cnblogs.com/peaceli/archive/2008/04/13/1151520.html
http://topic.youkuaiyun.com/u/20081110/17/5d552cfd-9468-49bb-8767-c6ae80b117b3.html
http://topic.youkuaiyun.com/u/20081110/17/5d552cfd-9468-49bb-8767-c6ae80b117b3.html
水晶报表导出Excel:
http://qianshao.blog.51cto.com/935360/203640