我有一些用于将数据结果作为 CSV 发送给用户的代码。这适用于 Excel 2013,但在 Excel 2007 中,它不会拆分为列,而是作为仅插入一列的数据。
有没有办法告诉 Excel 如何拆分文本(由 ; 分隔)?这是我的代码:
public async Task ExcelResultList(int id)
{
var asString = await Resolver.Resolve<IHandoutManager>().GetResultListAsStringAsync(id);
var handout = await Resolver.Resolve<IHandoutManager>().GetHandout(id);
var filename = string.Format("{0} registrations - {1:yyyy-MM-dd}.csv", handout.Name, DateTime.Now);
var contenttype = "application/csv";
Response.Clear();
Response.ContentType = contenttype;
Response.AddHeader("content-disposition", "attachment;filename=" + filename);
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentEncoding = Encoding.Unicode;
Response.Write(asString);
Response.End();
}