我有这个代码:
context.Response.ClearHeaders();
context.Response.AddHeader("content-disposition", "attachment; filename=Clients.csv");
context.Response.ClearContent();
context.Response.ContentType = "application/ms-excel";
context.Response.ContentEncoding = System.Text.Encoding.Unicode;
context.Response.BinaryWrite(System.Text.Encoding.Unicode.GetPreamble());
context.Response.BufferOutput = false;
context.Response.Buffer = false;
foreach (var c in clients)
{
context.Response.Output.WriteLine(string.Format("{0},{1}", c.FirstName, c.LastName));
}
下载的文件看起来不错,除了所有行单元格都合并到一个单元格中。由于 csv/xls 内容中的希伯来语和日语字符,我必须将响应用作 BinaryWrite。如何使用二进制写入写入拆分单元格 csv/xls 文件?