MemoryStream memStream = designer.Workbook.SaveToStream();
string filename = name + Convert.ToDateTime(DateTime.Now).ToString("yyyyMMddhhmmss") + ".xls";
DateTime now = DateTime.Now;
string path = "~/BalanceTable/" + now.Year + "/" + now.Month + "/" + now.Day + "/";
string filepath = HttpContext.Current.Server.MapPath(path);
//判断文件夹是否存在
if (!Directory.Exists(filepath))
{
Directory.CreateDirectory(filepath);//不存在创建文件夹
}
string filepathall = filepath + filename;
FileStream file = new FileStream(filepathall, FileMode.Create);//新建EXCEL文件
file.Write(memStream.GetBuffer(), 0, memStream.GetBuffer().Length);//将文件流写入到新建的EXCEL
file.Close();//关闭文件
return path + filename ;//返回路径用于添加数据