那位有导出到EXCEL的源码,急用!能行立刻结贴!
那位有导出到EXCEL的源码,急用!能行立刻结贴! 问题点数:100、回复次数:4Top
1 楼foxtoo(阿里巴巴和四十大盗)回复于 2005-04-02 01:18:32 得分 100
string fileName;
fileName = Server.MapPath(".")+"\\gcfbqk.xls";
object o = System.Reflection.Missing.Value;
Excel.Application oXL = new Excel.ApplicationClass();
//Response.Write("<script>alert("+fileName+")</script>");
Excel.Workbook oWB = oXL.Workbooks.Open(fileName,o,o,o,o,o,o,o,o,o,o,o,o);
Excel.Worksheet oSheet = (Excel.Worksheet)oWB.Worksheets[1];
oXL.Visible = true;
oSheet.Cells[3,6]= "从" + str_rq1 +"到"+ str_rq2;
SqlDataAdapter MyCommand = new SqlDataAdapter("select zbbh,gcmc,zbdw,fbdw,sfjsdwzd,djbm,djrq from mFBBA where djrq >= '"+ str_rq1 + "' and djrq <= '"+ str_rq2 + "' order by djrq ",MyConn);
DataSet ds = new DataSet();
MyCommand.Fill(ds);
DataTable MyTable = ds.Tables[0];Top
2 楼foxtoo(阿里巴巴和四十大盗)回复于 2005-04-02 01:18:52 得分 0
if(MyTable.Rows.Count != 0)
{
for (int i = 0;i<MyTable.Rows.Count;i++)
{
DataRow MyRow = MyTable.Rows[i];
oSheet.Cells[i+5,1] = i+1;
oSheet.Cells[i+5,2] = MyRow[0].ToString().Trim();
oSheet.Cells[i+5,3] = MyRow[1].ToString().Trim();
oSheet.Cells[i+5,4] = MyRow[2].ToString().Trim();
oSheet.Cells[i+5,5] = MyRow[3].ToString().Trim();
string str_sfjsdwzd = MyRow[4].ToString().Trim();
if( str_sfjsdwzd == "0")
{
str_sfjsdwzd = "否";
}
if(str_sfjsdwzd == "1")
{
str_sfjsdwzd = "是";
}
oSheet.Cells[i+5,6] = str_sfjsdwzd;
oSheet.Cells[i+5,7] = MyRow[5].ToString().Trim();
string str_djrq = MyRow[6].ToString().Trim();
if(str_djrq.Length !=0)
{
str_djrq = System.Convert.ToDateTime(str_djrq).ToShortDateString().Trim();
}
oSheet.Cells[i+5,8] = str_djrq;
}
}Top
3 楼foxtoo(阿里巴巴和四十大盗)回复于 2005-04-02 01:19:13 得分 0
Random nRandom = new Random();
string strXls = nRandom.Next().ToString()+".xls";
//fileName = "";
fileName = Server.MapPath(".")+"\\excel\\"+strXls;
oWB.SaveAs(fileName,o,o,o,o,o,Excel.XlSaveAsAccessMode.xlExclusive,o,o,o,o);
fileName = "";
// PagePath path = new PagePath();
fileName = strXls;
string strUrl = "<script>window.open("+"'\\excel/"+strXls+"'";
strUrl = strUrl+","+"'"+"A"+"'"+","+"'"+"'";
strUrl =strUrl+","+"false)</script>";
// this.TB_cs.Text = strUrl;
Response.Write(strUrl);
oXL.Quit();
oWB = null;
oSheet = null;
Top
4 楼yuetong(需要交流)回复于 2005-04-02 01:21:59 得分 0
十分感谢!Top




