62,243
社区成员




public void GetURL(Reprots reprotsInfo)
{
if (Session["FileName"] != null)
{
string oldfileName = Session["FileName"].ToString();
string oldxlsPath = Server.MapPath("~/DownLoad/" + oldfileName);
//保存Excel单网页格式的文件路径
string oldhtmlPath = oldxlsPath.Replace(".xls", ".mht");
FilePicDelete(oldhtmlPath);
FilePicDelete(oldxlsPath);
}
SpreadsheetGear.IWorkbookSet workbookSet = SpreadsheetGear.Factory.GetWorkbookSet(System.Globalization.CultureInfo.CurrentCulture);
SpreadsheetGear.IWorkbook workbook = workbookSet.Workbooks.OpenFromMemory(reprotsInfo.ReportContent);
SpreadsheetGear.IWorksheet worksheet = workbook.Worksheets[0];
//向Excel中添加单元格和图形的填充数据
GetConfigData(workbook, reprotsInfo.ReportID);
//把当前的Excel转为二进制
Byte[] reportContent = workbook.SaveToMemory(SpreadsheetGear.FileFormat.Excel8);
//保存文件名
string fileName = Session["Account"].ToString() + reprotsInfo.ReportName + DateTime.Now.ToString("yyyyMMddhhmmss") + ".xls";
Session["FileName"] = Session["Account"].ToString() + reprotsInfo.ReportName + DateTime.Now.ToString("yyyyMMddhhmmss") + ".xls"; ;
//保存Excel文件路径
string xlsPath = Server.MapPath("~/DownLoad/" + fileName);
//保存Excel单网页格式的文件路径
string htmlPath = xlsPath.Replace(".xls", ".mht");
//设置当前的Excel的保存路径
FileStream fs = new FileStream(xlsPath, FileMode.Create);
//保存当前Excel文件
fs.Write(reportContent, 0, reportContent.Length);
//清除缓存
fs.Flush();
//关闭Excel文件
fs.Close();
//删除老的Excel单网页文件
FilePicDelete(htmlPath);
//生成新的Excel单网页文件
ExcelConvertToHtml(xlsPath, htmlPath);
//把新的Excel单网页文件显示到页面上
System.IO.FileInfo file = new System.IO.FileInfo(htmlPath);
if (file.Exists)
{
this.Panel2.IFrameUrl = "/DownLoad/" + fileName.Replace(".xls", ".mht");
}
}