跪求导出问题!! 在线等 !!!
导出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>
问题: 我只想导出数据
他全部都导出来
我该怎么办啊?
--------------------编程问答-------------------- 帮帮忙啊 --------------------编程问答-------------------- 你只把数据写出来就可以了,其它多余的控件和东西都删掉。 --------------------编程问答-------------------- 我给你个导出的例子:
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中了,然后你想怎么弄随便了。 --------------------编程问答-------------------- 对了,引用using System.Data.OleDb;
楼主的是在bs下面,bs下面没有openFileDialog1控件,楼主可以用你上面的路径来代替 --------------------编程问答-------------------- 方法很多哈,可以生成EXCEL/WORD文件,然后传给用户.
不要仅抱着一个方法,其他的可以尝试哦.
补充:.NET技术 , C#