public void ExportToExcel(string Filename, GridView gridview, Page page)
        {
            page.Response.Clear();            // 防止中文内容为乱码            page.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");            //可令中文文件名不为乱码            page.Response.AppendHeader("content-disposition", "attachment;filename=\"" + System.Web.HttpUtility.UrlEncode(Filename + "课程题库" + DateTime.Now.ToShortDateString(),            System.Text.Encoding.UTF8) + ".xls\"");            StringWriter sw = new StringWriter();            HtmlTextWriter htw = new HtmlTextWriter(sw);            gridview.RenderControl(htw);            page.Response.Write(sw.ToString());            page.Response.End();        }

解决方案 »

  1.   

    onclick="AllAreaExcel()"function AllAreaExcel()    
    {   
      var oXL = new ActiveXObject("Excel.Application");    
      var oWB = oXL.Workbooks.Add();    
      var oSheet = oWB.ActiveSheet;     
      var elTable = document.getElementById("print"); //你表格的ID
      var sel=document.body.createTextRange();   
      sel.moveToElementText(elTable);//tableId是要导出表格的ID   
      sel.select();   
      sel.execCommand("Copy");    
      oSheet.Paste();   
      oXL.Visible = true;   
         
    }
      

  2.   


    http://bbs.csdn.net/topics/390830774
      

  3.   

    导出Excel数据到文本文件
     private void btn_Txt_Click(object sender, EventArgs e)
            {
                //连接Excel数据库
                OleDbConnection olecon = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + txt_Path.Text + ";Extended Properties=Excel 8.0");
                olecon.Open();//打开数据库连接
                OleDbDataAdapter oledbda = new OleDbDataAdapter("select * from [" + cbox_SheetName.Text + "$]", olecon);//从工作表中查询数据
                DataSet myds = new DataSet();//实例化数据集对象
                oledbda.Fill(myds);//填充数据集
                StreamWriter SWriter = new StreamWriter(cbox_SheetName.Text + ".txt", false, Encoding.Default);//实例化写入流对象
                string P_str_Content = "";//存储读取的内容
                for (int i = 0; i < myds.Tables[0].Rows.Count; i++)//遍历数据集中表的行数
                {
                    for (int j = 0; j < myds.Tables[0].Columns.Count; j++)//遍历数据集中表的列数
                    {
                        P_str_Content += myds.Tables[0].Rows[i][j].ToString() + "  ";//记录当前遍历到的内容
                    }//CodeGo.net/
                    P_str_Content += Environment.NewLine;//字符串换行
                }
                SWriter.Write(P_str_Content);//先文本文件中写入内容
                SWriter.Close();//关闭写入流对象
                SWriter.Dispose();//释放写入流所占用的资源
                MessageBox.Show("已经将" + cbox_SheetName.Text + "工作表中的数据成功写入到了文本文件中", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
    4--C#界面上制作一个地图,每个省这些形状都可以点击,如何实现 [
    http://bbs.csdn.net/topics/390898888
    答:取得鼠标焦点后自动放大Button按钮
     private void button1_MouseEnter(object sender, EventArgs e)
            {
                button1.Location = new Point(80, 10);//设置按钮位置
                button1.Font = new Font("隶书", 18);//设置按钮字体样式
                button1.Width = 200;//设置按钮宽度
                button1.Height = 80;//设置按钮高度
            }        private void button1_MouseLeave(object sender, EventArgs e)
            {
                button1.Location = new Point(130, 30);//设置按钮位置
                button1.Font = new Font("宋体",9);//设置按钮字体样式
                button1.Width = 100;//设置按钮宽度
                button1.Height = 40;//设置按钮高度
            }
      

  4.   

    参考:http://blog.csdn.net/chinacsharper/article/details/8980456
    public void ExportResult(DataTable dt, string excelName)  
    {  
        Response.Clear();  
        Response.Charset = "";  
        Response.ContentType = "applicationnd.ms-xls";  
        StringWriter sw = new StringWriter();  
        HtmlTextWriter htmlWrite = new HtmlTextWriter(sw);  
      
        DataGrid dg = new DataGrid();  
        dg.DataSource = dt;  
        dg.DataBind();  
        dg.RenderControl(htmlWrite);  
        Response.AddHeader("content-disposition", "attachment;filename=" + HttpUtility.UrlEncode(excelName));  
        Response.Write(sw.ToString());  
        Response.End();  
    }