我现在做了个gridview显示数据,有N条,分了很多页面,但是现在要用一个导出按钮把数据全部导出到Excel表格中,不要只导出一个页面的数据,我在网上找的解决方法全是只导出一个页面的数据,
如何解决! 

解决方案 »

  1.   

    将所有数据放在dataset中,然后将dataset里面的数据直接导出。
      

  2.   

    你总的有个dataset什么的吧?你导数据的时候先SQL出一个全的Dataset,然后再Download
      

  3.   


    public static void ExportToExcel(DataSet ds, string fileStrName)        {            Excel.Application excel = new Excel.ApplicationClass();            if (excel == null)            {                MessageBox.Show("Excel无法启动", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);            }            int rowindex = 2;            int colindex = 0;            excel.Application.Workbooks.Add(true);            DataTable dt = ds.Tables[0];            Excel.Range range = excel.get_Range(excel.Cells[1, 1], excel.Cells[1, dt.Columns .Count]);            range.MergeCells = true;            excel.ActiveCell.FormulaR1C1 =fileStrName;            excel.ActiveCell.Font.Size = 18;            excel.ActiveCell.Font.Bold = true;                       foreach (DataColumn col in dt.Columns)            {                colindex=colindex +1;                excel.Cells[2, colindex] = col.ColumnName;            }            foreach (DataRow row in dt.Rows)            {                colindex = 0;                rowindex++;                foreach (DataColumn col in dt.Columns)                {                    colindex++;                    excel.Cells[rowindex, colindex] = row[col.ColumnName].ToString();                }            }            excel.get_Range(excel.Cells[1, 1], excel.Cells[1, dt.Columns.Count]).Font.Bold = true;            excel.get_Range(excel.Cells[1, 1], excel.Cells[rowindex, colindex]).Borders.LineStyle = 0;            excel.Cells.EntireColumn.AutoFit();            excel.Cells.VerticalAlignment = Excel.Constants.xlCenter;            excel.Cells.HorizontalAlignment = Excel.Constants.xlCenter;            try            {                excel.Visible = false;                excel.Save("Sheet1");                            }            catch { }            finally            {                excel.Quit();                excel = null;            }        }
      

  4.   

    这段代码好像是应该winform里面使用的啊!
      

  5.   

    先把数据select到dataset .在把dataset数据导出excel百度: dataset导出excel
      

  6.   

    导出的时候把gridview的allowpage设置为FALSE就,然后导出成功后再设置为TRUE即可!具体操作完全可以再cs文件里写!