跪求导出问题!! 在线等 !!!

popstar018 2007-12-13 10:42:49
导出EXCEL问题
前台代码:<script language="javascript" event="onclick" for="btnexp">
var tbtext = document.all["RepListTable"].innerHTML;
document.Form1.Hidden1.value="export";
document.Form1.Hidden2.value=tbtext;
document.Form1.submit();
</script>
<div id="Div2" style="position: absolute; height: 100%; width: 300%">
<table id="ExpBtnTable" style="background-color: transparent" height="20" width="100%"
align="center">
<tr>
<td bgcolor="lavender">
<input class="button" id="btnexp" style="width: 60px" type="button" value="导出" />  
<asp:HiddenField id="Hidden1" runat ="server" />
<asp:HiddenField id="Hidden2" runat ="server" />
</td>
</tr>
</table>
<asp:Table BorderWidth="0" runat="server" CellPadding="0" GridLines="Both" CssClass="TableClass"
EnableViewState="False" CellSpacing="0" ID="Table1">
</asp:Table>
</div>

后台代码:
if ((this.IsPostBack) && (Hidden1.Value == "export"))
{
string mstr = Hidden2.Value;
Hidden2.Value = "";

string strFile = "nores";
strFile = this.Server.UrlEncode(strFile);

Response.Clear();
Response.Buffer = true;
Response.AddHeader("Content-Disposition", "attachment; filename=" + strFile + ".xls");
Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
EnableViewState = false;
Response.Write(mstr);
Response.End();
}

导出后出现:

<TBODY>
<TR>
<TD class=TableHead style="BORDER-RIGHT: 1px solid; BORDER-TOP: 1px solid; BORDER-LEFT: 1px solid; BORDER-BOTTOM: 1px solid">端口ID</TD>
<TD class=TableHead style="BORDER-RIGHT: 1px solid; BORDER-TOP: 1px solid; BORDER-LEFT: 1px solid; BORDER-BOTTOM: 1px solid">端口号</TD>
问题: 我只想导出数据
他全部都导出来
我该怎么办啊?
...全文
94 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
游陆 2008-01-10
  • 打赏
  • 举报
回复
对了,引用using System.Data.OleDb;
楼主的是在bs下面,bs下面没有openFileDialog1控件,楼主可以用你上面的路径来代替
游陆 2008-01-10
  • 打赏
  • 举报
回复
我给你个导出的例子:
private void btnDaoru_Click(object sender, EventArgs e)
{
this.openFileDialog1.Filter = "Excel文件 (*.xls)| *.xls|文本文件(*.txt)|*.txt|所有文件(*.*)|*.*";
this.openFileDialog1.Multiselect = true;
this.openFileDialog1.Title = "选择你保存的数据文件";
this.openFileDialog1.ShowDialog();

DataTable myDT= new DataTable ();

if (openFileDialog1.FileName != "")
{
string strFileName = openFileDialog1.FileName;
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + strFileName + ";" + "Extended Properties=Excel 8.0;";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
string strExcel = "";
OleDbDataAdapter myCommand = null;
strExcel = "select * from [sheet1$]";
myCommand = new OleDbDataAdapter(strExcel, strConn);
myDT = new DataTable();
myCommand.Fill(myDT);
}

}
这样就把EXCEL中的数据导入到datatable中了,然后你想怎么弄随便了。
bo3235 2008-01-10
  • 打赏
  • 举报
回复
方法很多哈,可以生成EXCEL/WORD文件,然后传给用户.
不要仅抱着一个方法,其他的可以尝试哦.
kemin 2007-12-13
  • 打赏
  • 举报
回复
你只把数据写出来就可以了,其它多余的控件和东西都删掉。
popstar018 2007-12-13
  • 打赏
  • 举报
回复
帮帮忙啊

111,092

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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