导出到excel出现奇怪的东西

yanbinquan 2011-01-06 11:11:50
代码

private void SaveToExcel(DataTable objTable)
{
int CountR = objTable.Rows.Count;//行数
int CountC = objTable.Columns.Count;//列数
Response.Clear();
Response.Buffer = true;

//设置Http的头信息,编码格式
Response.AppendHeader("Content-Disposition", "attachment;filename=result.xls");
Response.ContentType = "application/ms-excel";


//设置编码
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
//写表头
for (int i = 0; i < CountC; i++)
{
Response.Write(objTable.Columns[i].ColumnName + "\t");
}
Response.Write("\n");
//写表内容
for (int RowNo = 0; RowNo <= CountR - 1; RowNo++)
{
string RowContent = "";
for (int CloumnNo = 0; CloumnNo <= CountC - 1; CloumnNo++)
{
RowContent += Convert.ToString(objTable.Rows[RowNo][CloumnNo]) + "\t";
}
RowContent += "\n";
Response.Write(RowContent);
}
Response.End();
}

在excel表中出现

<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<meta content="Word.Document" name="ProgId" />
<meta content="Microsoft Word 11" name="Generator" />
<meta content="Microsoft Word 11" name="Originator" />
<link href="file:///C:\DOKUME~1\eigemann\LOKALE~1\Temp\msohtml1\01\clip_filelist.xml" rel="File-List" /><!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:HyphenationZone>21</w:HyphenationZone>
<w:PunctuationKerning />
<w:ValidateAgainstSchemas />
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:Compatibility>
<w:BreakWrappedTables />
<w:SnapToGridInCell />
<w:WrapTextWithPunct />
<w:UseAsianBreakRules />
<w:DontGrowAutofit />
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
</w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" LatentStyleCount="156">
</w:LatentStyles>
</xml><![endif]--><style type="text/css">
<!--
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";}
@page Section1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 2.0cm 70.85pt;
mso-header-margin:36.0pt;
mso-footer-margin:36.0pt;
mso-paper-source:0;}
div.Section1
{page:Section1;}
-->
</style><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Normale Tabelle";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
</style>
<![endif]-->
<p style="text-indent: 18pt; line-height: 200%;" class="MsoNormal"><span lang="EN-US" style="font-family: Arial;">The allelochemical effect of the polyphenolic tannic acid (TA) on laboratory cultures of the algae species <i style="">Desmodesmus armatus, Scenedesmus vacuolatus</i> <i style="">and Stephanodiscus minutulus</i> was investigated by flow cytometry. So far unstudied modes of action, namely esterase activity, membrane integrity and production of reactive oxygen species (ROS) were tested using specific fluorescent markers. For comparison, the more traditional action modes cell division and photosynthetic yield were evaluated by cell counts and PAM measurements. Experiments were conducted with TA concentrations ranging from 0.6 to 30 µmol L<sup>-1</sup> <span style="color: black;">and controls without TA </span>at exposure times of 3, 14 and 24 hours. <o:p></o:p></span></p>
<span lang="EN-US" style="font-size: 12pt; font-family: Arial;">An inhibition of esterase activity compared to the controls was detected at every time point in all three tested algae species if TA concentrations exceeded 12 µmol L<sup>-1</sup>. At lower TA concentrations, however, esterase activity increased in several treatments independent of species and exposure time. In contrast, membrane integrity and ROS production of the tested phytoplankton species were not significantly affected by TA in our experiments. Cell division was inhibited after 24 h and photosynthetic yield declined after 14 h exposure time. Accordingly, inhibition of esterase activity represents a new mode of action of allelochemicals on phytoplankton which can be detected already after short exposure time and might thus be a suitable tool for future <i style="">in situ</i> investigations.</span></p> Leibniz Institute of Freshwater ecology and Inland fisheries Berlin New modes of action from allelochemicals on phytoplankton Allelochemicals inhibit esterase activity in phytoplankton allelopathy, esterase activity, flow cytometry, PAM measurements, phytoplankton Falk Eigemann, Sabine Hilt and Mechthild Schmitt-Jansen

...全文
160 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
孟子E章 2011-01-06
  • 打赏
  • 举报
回复
下面的代码是Excel另存的时候出现的,你的代码导出肯定不是这样的,你肯定是看的不是导出的文件
Jack2013tong 2011-01-06
  • 打赏
  • 举报
回复
http://blog.csdn.net/huwei2003/archive/2010/05/07/5566235.aspx
楼主看下对你有没有用
lilianjie0426 2011-01-06
  • 打赏
  • 举报
回复
难道是excel版本的问题?不过好像不太可能。。。不过楼主可以试试。。。
lilianjie0426 2011-01-06
  • 打赏
  • 举报
回复
楼主换个表导出一下看看就知道了,我用楼主的代码在我这试了,完全正常!!!
v风雪山神庙v 2011-01-06
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 net_lover 的回复:]
只是excel中间出现了那一段不知道什么的代码

那肯定是数据本身就是那样的吧。

在没有进行调试之前,别说 不是的
[/Quote]
+1
孟子E章 2011-01-06
  • 打赏
  • 举报
回复
只是excel中间出现了那一段不知道什么的代码

那肯定是数据本身就是那样的吧。

在没有进行调试之前,别说 不是的
yanbinquan 2011-01-06
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 bossma 的回复:]

引用 7 楼 yanbinquan 的回复:
引用 5 楼 net_lover 的回复:

打死我也不信 DataTable 能通过Response.Write输出那样的格式。

Response.AppendHeader("Content-Disposition", "attachment;filename=xxxxxxxxxxxxxxxxxx.xls");

你用记事本打开xx……
[/Quote]

不是的
萤火架构 2011-01-06
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 yanbinquan 的回复:]
引用 5 楼 net_lover 的回复:

打死我也不信 DataTable 能通过Response.Write输出那样的格式。

Response.AppendHeader("Content-Disposition", "attachment;filename=xxxxxxxxxxxxxxxxxx.xls");

你用记事本打开xxxxxxxxxxxxxxxxxx.xls会显示
……
[/Quote]

是不是datatable里边的数据
yanbinquan 2011-01-06
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 net_lover 的回复:]

打死我也不信 DataTable 能通过Response.Write输出那样的格式。

Response.AppendHeader("Content-Disposition", "attachment;filename=xxxxxxxxxxxxxxxxxx.xls");

你用记事本打开xxxxxxxxxxxxxxxxxx.xls会显示
……
[/Quote]

用excel打开可以看到正确的数据,只是excel中间出现了那一段不知道什么的代码
萤火架构 2011-01-06
  • 打赏
  • 举报
回复
参考导出Excel的方法:
http://blog.bossma.cn/csharp/csharp_export_excel_summary/
孟子E章 2011-01-06
  • 打赏
  • 举报
回复
打死我也不信 DataTable 能通过Response.Write输出那样的格式。

Response.AppendHeader("Content-Disposition", "attachment;filename=xxxxxxxxxxxxxxxxxx.xls");

你用记事本打开xxxxxxxxxxxxxxxxxx.xls会显示

<meta content="Word.Document" name="ProgId" />
<meta content="Microsoft Word 11" name="Generator" />
<meta content="Microsoft Word 11" name="Originator" />
这样的格式?

你肯定是搞错了,下面的是Word,根本不是excel。不要相信自己的眼睛
yanbinquan 2011-01-06
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 net_lover 的回复:]

下面的代码是Excel另存的时候出现的,你的代码导出肯定不是这样的,你肯定是看的不是导出的文件
[/Quote]

导出来就只有一个excel啊

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧