Commit f4562006 by guanzhenshan

调整导出文件方式

parent 27c8b464
...@@ -168,12 +168,19 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers ...@@ -168,12 +168,19 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers
); );
} }
var guid = Guid.NewGuid().ToString();
var filename = platform+"平台费用流水" + DateTime.Now.ToString("yyyyMMddHHmmss"); var filename = platform+"平台费用流水" + DateTime.Now.ToString("yyyyMMddHHmmss");
var filepath = _hostingEnvironment.WebRootPath + "\\Files\\Report\\" + DateTime.Now.ToString("yyyy-MM-dd") + "\\"; var filepath = _hostingEnvironment.WebRootPath + "\\Files\\Report\\" + DateTime.Now.ToString("yyyy-MM-dd") + "\\";
ToCSV(list, colNames, filename, filepath); ToCSV(list, colNames, guid, filepath);
return File("~/Files/Report/" + DateTime.Now.ToString("yyyy-MM-dd") + "/" + filename + ".csv", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", filename + ".csv"); var ms = new System.IO.MemoryStream();
using (var f = new System.IO.FileStream(filepath + guid + ".csv", System.IO.FileMode.Open))
{
f.CopyTo(ms);
}
ms.Position = 0;
return File(ms, "text/csv", filename + ".csv");
} }
#endregion #endregion
...@@ -1081,11 +1088,19 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers ...@@ -1081,11 +1088,19 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers
); );
} }
var guid = Guid.NewGuid().ToString();
var filename = "Ebay所有订单流水" + DateTime.Now.ToString("yyyyMMddHHmmss"); var filename = "Ebay所有订单流水" + DateTime.Now.ToString("yyyyMMddHHmmss");
var filepath = _hostingEnvironment.WebRootPath + "\\Files\\Report\\" + DateTime.Now.ToString("yyyy-MM-dd") + "\\"; var filepath = _hostingEnvironment.WebRootPath + "\\Files\\Report\\" + DateTime.Now.ToString("yyyy-MM-dd") + "\\";
ToCSV(list, colNames, filename, filepath); ToCSV(list, colNames, guid, filepath);
return File("~/Files/Report/" + DateTime.Now.ToString("yyyy-MM-dd") + "/" + filename + ".csv", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", filename + ".csv"); var ms = new System.IO.MemoryStream();
using (var f = new System.IO.FileStream(filepath + guid + ".csv", System.IO.FileMode.Open))
{
f.CopyTo(ms);
}
ms.Position = 0;
return File(ms, "text/csv", filename + ".csv");
} }
/// <summary> /// <summary>
...@@ -1725,12 +1740,20 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers ...@@ -1725,12 +1740,20 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers
); );
} }
var guid = Guid.NewGuid().ToString();
var filename = platform + "订单明细导出" + DateTime.Now.ToString("yyyyMMddHHmmss"); var filename = platform + "订单明细导出" + DateTime.Now.ToString("yyyyMMddHHmmss");
var filepath = _hostingEnvironment.WebRootPath + "\\Files\\Report\\" + DateTime.Now.ToString("yyyy-MM-dd") + "\\"; var filepath = _hostingEnvironment.WebRootPath + "\\Files\\Report\\" + DateTime.Now.ToString("yyyy-MM-dd") + "\\";
ToCSV(listVal, colNames, filename, filepath); ToCSV(listVal, colNames, guid, filepath);
var ms = new System.IO.MemoryStream();
using (var f = new System.IO.FileStream(filepath + guid + ".csv", System.IO.FileMode.Open))
{
f.CopyTo(ms);
}
ms.Position = 0;
return File(ms, "text/csv", filename + ".csv");
return File("~/Files/Report/" + DateTime.Now.ToString("yyyy-MM-dd") + "/" + filename + ".csv", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", filename + ".csv");
} }
/// <summary> /// <summary>
...@@ -2059,12 +2082,19 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers ...@@ -2059,12 +2082,19 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers
); );
} }
var guid = Guid.NewGuid().ToString();
var filename = platform + "平台退款流水导出" + DateTime.Now.ToString("yyyyMMddHHmmss"); var filename = platform + "平台退款流水导出" + DateTime.Now.ToString("yyyyMMddHHmmss");
var filepath = _hostingEnvironment.WebRootPath + "\\Files\\Report\\" + DateTime.Now.ToString("yyyy-MM-dd") + "\\"; var filepath = _hostingEnvironment.WebRootPath + "\\Files\\Report\\" + DateTime.Now.ToString("yyyy-MM-dd") + "\\";
ToCSV(listVal, colNames, filename, filepath); ToCSV(listVal, colNames, guid, filepath);
return File("~/Files/Report/" + DateTime.Now.ToString("yyyy-MM-dd") + "/" + filename + ".csv", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", filename + ".csv"); var ms = new System.IO.MemoryStream();
using (var f = new System.IO.FileStream(filepath + guid + ".csv", System.IO.FileMode.Open))
{
f.CopyTo(ms);
}
ms.Position = 0;
return File(ms, "text/csv", filename + ".csv");
} }
#endregion #endregion
...@@ -2151,12 +2181,19 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers ...@@ -2151,12 +2181,19 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers
); );
} }
var guid = Guid.NewGuid().ToString();
var filename = "亚马逊广告费导出" + DateTime.Now.ToString("yyyyMMddHHmmss"); var filename = "亚马逊广告费导出" + DateTime.Now.ToString("yyyyMMddHHmmss");
var filepath = _hostingEnvironment.WebRootPath + "\\Files\\Report\\" + DateTime.Now.ToString("yyyy-MM-dd") + "\\"; var filepath = _hostingEnvironment.WebRootPath + "\\Files\\Report\\" + DateTime.Now.ToString("yyyy-MM-dd") + "\\";
ToCSV(listVal, colNames, filename, filepath); ToCSV(listVal, colNames, guid, filepath);
return File("~/Files/Report/" + DateTime.Now.ToString("yyyy-MM-dd") + "/" + filename + ".csv", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", filename + ".csv"); var ms = new System.IO.MemoryStream();
using (var f = new System.IO.FileStream(filepath + guid + ".csv", System.IO.FileMode.Open))
{
f.CopyTo(ms);
}
ms.Position = 0;
return File(ms, "text/csv", filename + ".csv");
} }
#endregion #endregion
...@@ -2254,17 +2291,14 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers ...@@ -2254,17 +2291,14 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers
var filepath = _hostingEnvironment.WebRootPath + "\\Files\\Report\\" + DateTime.Now.ToString("yyyy-MM-dd") + "\\"; var filepath = _hostingEnvironment.WebRootPath + "\\Files\\Report\\" + DateTime.Now.ToString("yyyy-MM-dd") + "\\";
ToCSV(listVal, colNames, guid, filepath); ToCSV(listVal, colNames, guid, filepath);
var ms = new System.IO.MemoryStream();
var stream = new System.IO.MemoryStream(); using (var f = new System.IO.FileStream(filepath + guid + ".csv", System.IO.FileMode.Open))
using (System.IO.FileStream fs = new System.IO.FileStream(filepath + filename + ".csv", System.IO.FileMode.OpenOrCreate))
{ {
stream.CopyTo(fs); f.CopyTo(ms);
fs.Flush();
} }
//return File("/Files/Report/" + DateTime.Now.ToString("yyyy-MM-dd") + "/" + guid + ".csv", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", filename + ".csv"); ms.Position = 0;
return File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", filename + ".csv"); return File(ms, "text/csv", filename + ".csv");
} }
#endregion #endregion
......
...@@ -47,6 +47,8 @@ namespace Bailun.DC.Web.Base ...@@ -47,6 +47,8 @@ namespace Bailun.DC.Web.Base
} }
StreamWriter writer = new StreamWriter(filePath + tbName + ".csv", true, System.Text.Encoding.UTF8); StreamWriter writer = new StreamWriter(filePath + tbName + ".csv", true, System.Text.Encoding.UTF8);
writer.AutoFlush = true;
//var ms = new System.IO.MemoryStream();
//添加表头 //添加表头
foreach (var item in columns) foreach (var item in columns)
...@@ -56,6 +58,8 @@ namespace Bailun.DC.Web.Base ...@@ -56,6 +58,8 @@ namespace Bailun.DC.Web.Base
strb.Remove(strb.Length - 1, 1); strb.Remove(strb.Length - 1, 1);
writer.WriteLine(strb.ToString()); writer.WriteLine(strb.ToString());
//ms.Write(System.Text.Encoding.UTF8.GetBytes(strb.ToString()+"\n"));
//添加表内容 //添加表内容
foreach (var item in list) foreach (var item in list)
{ {
...@@ -77,6 +81,7 @@ namespace Bailun.DC.Web.Base ...@@ -77,6 +81,7 @@ namespace Bailun.DC.Web.Base
{ {
strb.Remove(strb.Length - 1, 1); strb.Remove(strb.Length - 1, 1);
writer.WriteLine(strb.ToString()); writer.WriteLine(strb.ToString());
//ms.Write(System.Text.Encoding.UTF8.GetBytes(strb.ToString() + "\n"));
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment