前些天发的博文在本机测试的时候没有问题,经发布后,程序地址发生变化,导致不能正常完成导出,现修改程序如下:
前端:
function ExportOut() {
window.open('/StoreManage/Export');
};
后端代码:(当然是在Controllers中)
public FileContentResult Export()
{
System.IO.MemoryStream output = new System.IO.MemoryStream();
string excelstr = "title,address,longitude,latitude,coord_type,,AreaHead,StoreCorde,StoreRemarks,StoreDescription,StoreClass,StoreHead,StoreTel" + "\n";
var list = storeServices.LoadEntites(o =>o.IsDelete==false).ToList();
//输出内容
foreach (Store items in list)
{
string StoreAddress = string.IsNullOrEmpty(items.StoreAddress) ? "" : items.StoreAddress.Trim();
string StoreName = string.IsNullOrEmpty(items.StoreName) ? "" : items.StoreName.Trim();
string StoreTel1 = string.IsNullOrEmpty(items.StoreTel1) ? "" : items.StoreTel1.Trim();
excelstr +=
StoreName + "," +
StoreAddress + "," +
items.StoreLongitude + "," +
items.StoreLatitude + "," +
"3,," + //3:百度地理坐标加密方式
items.AreaHead + "," +
items.StoreCode + "," +
items.StoreRemarks + "," +
items.StoreDescription + "," +
items.StoreClass + "," +
items.StoreHead + "," +
StoreTel1 + "\n";
}
try
{
byte[] fileContent = System.Text.Encoding.GetEncoding("GB2312").GetBytes(excelstr);
return File(fileContent, "application/octet-stream", "门店信息.csv");
}
catch (Exception ex)
{
throw ex;
}
}
说明:要注意引用 IO空间
前端:
function ExportOut() {
window.open('/StoreManage/Export');
};
后端代码:(当然是在Controllers中)
public FileContentResult Export()
{
System.IO.MemoryStream output = new System.IO.MemoryStream();
string excelstr = "title,address,longitude,latitude,coord_type,,AreaHead,StoreCorde,StoreRemarks,StoreDescription,StoreClass,StoreHead,StoreTel" + "\n";
var list = storeServices.LoadEntites(o =>o.IsDelete==false).ToList();
//输出内容
foreach (Store items in list)
{
string StoreAddress = string.IsNullOrEmpty(items.StoreAddress) ? "" : items.StoreAddress.Trim();
string StoreName = string.IsNullOrEmpty(items.StoreName) ? "" : items.StoreName.Trim();
string StoreTel1 = string.IsNullOrEmpty(items.StoreTel1) ? "" : items.StoreTel1.Trim();
excelstr +=
StoreName + "," +
StoreAddress + "," +
items.StoreLongitude + "," +
items.StoreLatitude + "," +
"3,," + //3:百度地理坐标加密方式
items.AreaHead + "," +
items.StoreCode + "," +
items.StoreRemarks + "," +
items.StoreDescription + "," +
items.StoreClass + "," +
items.StoreHead + "," +
StoreTel1 + "\n";
}
try
{
byte[] fileContent = System.Text.Encoding.GetEncoding("GB2312").GetBytes(excelstr);
return File(fileContent, "application/octet-stream", "门店信息.csv");
}
catch (Exception ex)
{
throw ex;
}
}
说明:要注意引用 IO空间