ASP.NET导出EXECL字符串01被自动转成1如何解决?
时间:2011-12-28
来源:互联网
private void ExportExcel(System.Data.DataTable dt)
{
System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
System.Web.HttpContext.Current.Response.Buffer = false;
System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
System.Web.HttpContext.Current.Response.ClearHeaders();
System.Web.HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls");
string sep = "";
foreach (DataColumn dc in dt.Columns)
{
System.Web.HttpContext.Current.Response.Write(sep + dc.ColumnName);
sep = "\t";
}
System.Web.HttpContext.Current.Response.Write("\n");
int i;
foreach (DataRow dr in dt.Rows)
{
sep = "";
for (i = 0; i < dt.Columns.Count; i++)
{
string mes = dr[i].ToString();
if (i == 8)
{
mes = " " + dr[i].ToString();
}
System.Web.HttpContext.Current.Response.Write(sep + mes);
sep = "\t";
}
System.Web.HttpContext.Current.Response.Write("\n");
}
System.Web.HttpContext.Current.Response.End();
}
我用此方法进行EXECL的导出。但是DataTable中有一列会出现字符串01。我想导出的execl中就显示01。调试进去
System.Web.HttpContext.Current.Response.Write(sep + mes);
中的mes也是01。
但是导出的EXECL中会被自动转换成1。请问各位大大如何解决这个问题啊。
系统使用
Microsoft.Office.Interop.Excel._Application excel = new ApplicationClass();
时会报
检索 COM 类工厂中 CLSID 为 {00024500-0000-0000-C000-000000000046} 的组件时失败,原因是出现以下错误: 80070005。
不用这个控件有解决方法吗?
{
System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
System.Web.HttpContext.Current.Response.Buffer = false;
System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
System.Web.HttpContext.Current.Response.ClearHeaders();
System.Web.HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls");
string sep = "";
foreach (DataColumn dc in dt.Columns)
{
System.Web.HttpContext.Current.Response.Write(sep + dc.ColumnName);
sep = "\t";
}
System.Web.HttpContext.Current.Response.Write("\n");
int i;
foreach (DataRow dr in dt.Rows)
{
sep = "";
for (i = 0; i < dt.Columns.Count; i++)
{
string mes = dr[i].ToString();
if (i == 8)
{
mes = " " + dr[i].ToString();
}
System.Web.HttpContext.Current.Response.Write(sep + mes);
sep = "\t";
}
System.Web.HttpContext.Current.Response.Write("\n");
}
System.Web.HttpContext.Current.Response.End();
}
我用此方法进行EXECL的导出。但是DataTable中有一列会出现字符串01。我想导出的execl中就显示01。调试进去
System.Web.HttpContext.Current.Response.Write(sep + mes);
中的mes也是01。
但是导出的EXECL中会被自动转换成1。请问各位大大如何解决这个问题啊。
系统使用
Microsoft.Office.Interop.Excel._Application excel = new ApplicationClass();
时会报
检索 COM 类工厂中 CLSID 为 {00024500-0000-0000-C000-000000000046} 的组件时失败,原因是出现以下错误: 80070005。
不用这个控件有解决方法吗?
作者: iceqin34 发布时间: 2011-12-28
设置单元格格式为字符型
作者: liyangfd 发布时间: 2011-12-28
C# code
01./// <summary> 02./// GridView_CheckStat加入行变化样式 03. /// </summary> 04./// <param name="sender"></param> 05./// <param name="e"></param> 06. 07.protected void GridView_CheckStat_RowDataBound(object sender, GridViewRowEventArgs e) 08.{ 09. if (e.Row.RowType == DataControlRowType.DataRow) 10. { 11. //当鼠标在某一行上方时激发 12. e.Row.Attributes.Add("onmouseover", "curColor=this.style.backgroundColor;this.style.backgroundColor='#DDCCAA'"); 13. //当鼠标从某一行上方移开时激发 14. e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=curColor"); 15. //导出Excel时文本化 这就是中点!!!!!!!!!!!!!!!!!!!! 16. //e.Row.Cells[1].Attributes.Add("class", "text"); 17. //这里的[0]代表第一列 18. e.Row.Cells[0].Attributes.Add("style", "vnd.ms-excel.numberformat:@"); 19. } 20.}
作者: ajaxtop 发布时间: 2011-12-28
设置execl单元格的格式为文本型
作者: Net_Java_dram 发布时间: 2011-12-28
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28