Net导入导出EXCEL单元格强制换行符转换问题

导出强制换行符转换:
private void OutPutExcel(DataList dl)
{
dl.Visible = true;
Response.Clear();
Response.Buffer = true;
Response.Charset = "GB2312";
Response.AppendHeader("Content-Disposition", "导出文档");
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.ContentType = "application/vnd.ms-excel";
dl.EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
dl.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString().Replace("<br>", "<br style='mso-data-placement:same-cell;'/>"));
Response.End();
}

导入强制换行符转换:
private DataTable GetDataTable(DataSet ds)
{
try
{
DataTable dt = new DataTable();
DataColumn dc = new DataColumn("content");
dt.Columns.Add(dc);
DataRow dr = dt.NewRow();
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
dr = dt.NewRow();
string str = "";
str += "<b>" + ds.Tables[0].Rows[i][1].ToString().Trim().Replace("\n", "<br>") + "</b>";
dr[0] = str;
dt.Rows.Add(dr);
}
return dt;
}
catch
{
return null;
}
}



http://blog.csdn.net/wwgkc/article/details/4837259

你可能感兴趣的:(String,Excel,null,文档,dataset)