c# - 数据错误在 C# 中将 Gridview 导出为 .txt
问题描述
我一直在尝试从带有 sql 查询的 gridview 导出数据。我在gridview中有如下数据
id crédito | código | Fecha | Cliente | Nro Identificación | Municipio | Valor | Saldo
78454 | 82025 |19/03/2011 12:00:00 a. m. | LÓPEZ LÓPEZ JAIRO ALBERTO | 74322514 | ARAUCA | 1860000 | 620000
缺点是当您将它们导出为 .txt 时,您会以这种方式将它们扔掉
换句话说,波浪号不认识我,“ñ”也不认识。
到目前为止,我尝试过的是:
protected void ButtonGenerar_Click(object sender, EventArgs e)
{
string txt = string.Empty;
foreach (TableCell rowtext in GridViewDatos.HeaderRow.Cells)
{
txt += rowtext.Text + ",";
}
txt += "\r\n";
foreach (GridViewRow row in GridViewDatos.Rows)
{
foreach (TableCell datos in row.Cells)
{
txt += datos.Text + ",";
}
txt += "\r\n";
}
Encoding encoding = Encoding.UTF8;
var bytes = encoding.GetBytes(txt);
MemoryStream stream = new MemoryStream(bytes);
StreamReader reader = new StreamReader(stream);
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=namefile_" + DateTime.Now.ToShortDateString() + ".txt");
Response.Charset = "";
Response.ContentType = "application/text";
Response.ContentEncoding = Encoding.Unicode;
Response.Output.Write(reader.ReadToEnd());
Response.Flush();
Response.End();
}
我该如何解决?
解决方案
推荐阅读
- r - 用多行突出显示ggplot中的一行
- c# - 尝试使用 C# 访问联网位置时出现问题
- python-3.x - Imagemagcik 面具
- html - 如果我没有一个
- typescript - TypeScript:如何根据另一个对象的类型有条件地使类型中需要的属性?
- c# - Angular UI 应用程序不调用受 AzureAD 保护的 Asp.net 核心 API
- doctrine-orm - 教义继承映射——在更新时添加级联到 id 字段
- sql - 有没有办法将这三个 SQL 查询合并为一个?
- wordpress - 将 codei-gniter 控制器数据调用到 wordpress 并以 json 显示
- python - Numpy linspace 间距不均匀