網(wǎng)站首頁 編程語言 正文
一、JS腳本
window.open("../Ticket/ExportTicket");
二、后臺(tái)實(shí)現(xiàn)代碼
[HttpGet]
public ActionResult ExportTicket(TicketSearch search)
{
if (search != null)
{
search.CurrentPage = 1;
search.PageSize = 0;
}
string[] lstTitles = new string[] { "編號(hào)", "標(biāo)題"};
int TotalCount = 0;
List<TicketData> lstTicketData = ListTicketEntityToData(search, out TotalCount);
List<string[]> lstData = new List<string[]>();
foreach (TicketData itemData in lstTicketData)
{
string[] data = new string[]
{
itemData.Barcode,
itemData.Label,
itemData.SiteId.ToString(),
Helper.Htmlhelper.GetSiteInfo(itemData.SiteId),
itemData.Owner,
string.IsNullOrEmpty(itemData.CardId) ? "" : itemData.CardId,
itemData.StartDate == null ? "" : itemData.StartDate.Value.ToString("yyyy-MM-dd HH:mm"),
itemData.EndDate == null ? "" : itemData.EndDate.Value.ToString("yyyy-MM-dd HH:mm"),
itemData.IsValid.ToString(),
itemData.IsUsed.ToString(),
itemData.CreateTime.ToString("yyyy-MM-dd HH:mm")
};
lstData.Add(data);
}
string ExportFileName = Helper.ImportExport.ExportData(lstTitles, lstData);
return File(new System.IO.FileStream(ExportFileName, System.IO.FileMode.Open), "application/octet-stream", "Ticket" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".csv");
}
public static string ExportData(string[] lstTitles, List<string[]> lstData)
{
try
{
lock (RunningExport)
{
string TemplatePath = AppDomain.CurrentDomain.BaseDirectory + "Export";
string FullFileName = AppDomain.CurrentDomain.BaseDirectory + "Export\\template.csv";
if (Directory.Exists(TemplatePath))
{
if (File.Exists(FullFileName))
File.Delete(FullFileName);
}
else
{
Directory.CreateDirectory(TemplatePath);
}
if (lstTitles.Length <= 0)
{
return null;
}
FileStream fs = new FileStream(FullFileName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
StreamWriter sw = new StreamWriter(fs, Encoding.UTF8);
string data = "";
foreach (string itemTitle in lstTitles)
{
data += itemTitle + ",";
}
sw.WriteLine(data.TrimEnd(','));
foreach (string[] itemData in lstData)
{
data = "";
foreach (string itemChildData in itemData)
{
data += itemChildData + ",";
}
sw.WriteLine(data.TrimEnd(','));
}
sw.Close();
fs.Close();
return FullFileName;
}
}
catch (Exception)
{
return null;
}
}
原文鏈接:https://www.cnblogs.com/wml-it/p/16048927.html
相關(guān)推薦
- 2023-02-04 C語言實(shí)現(xiàn)繪制可愛的橘子鐘表_C 語言
- 2022-10-20 C++?float、double判斷是否等于0問題_C 語言
- 2022-02-20 Android?WebView實(shí)現(xiàn)全屏播放視頻_Android
- 2022-04-21 提升Python編碼能力的3個(gè)重要概念_python
- 2022-06-04 R語言批量讀取某路徑下文件內(nèi)容的方法_R語言
- 2023-04-20 react:理解“為了在回調(diào)中使用 `this`,這個(gè)綁定是必不可少的”
- 2023-03-30 C語言對(duì)結(jié)構(gòu)體數(shù)組按照某項(xiàng)規(guī)則進(jìn)行排序的實(shí)現(xiàn)過程探究_C 語言
- 2022-07-14 python修改包導(dǎo)入時(shí)搜索路徑的方法_python
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支