首页 新闻 搜索 专区 学院

这个吧datatable导进excel的方法,如果表的行数超过65000条,要怎么改,求高手、大神们帮忙改改

0
[已关闭问题] 关闭于 2012-09-12 08:24
 public void saveAsExcel(string path, DataTable tbdt)
        {
            object objMissing = System.Reflection.Missing.Value;
            Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
            app.Visible = false;
            Microsoft.Office.Interop.Excel.Workbook workBook = app.Workbooks.Add(objMissing);
            Microsoft.Office.Interop.Excel.Worksheet workSheet = (Microsoft.Office.Interop.Excel.Worksheet)workBook.Worksheets[1];
            for (int i = 0; i < tbdt.Columns.Count; i++)
            {
                Microsoft.Office.Interop.Excel.Range head = (Microsoft.Office.Interop.Excel.Range)workSheet.Cells[3, i + 1];
                head.Value = tbdt.Columns[i].ColumnName;
                head = null;
            }
            Microsoft.Office.Interop.Excel.Range range = workSheet.get_Range("A4", objMissing);
            int rows = tbdt.Rows.Count, cols = tbdt.Columns.Count;
            Microsoft.Office.Interop.Excel.Range ranges = range.get_Resize(rows, cols);
            object[,] datas = new object[rows, cols];
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < cols; j++)
                {
                    datas[i, j] = tbdt.Rows[i][j].ToString();
                }
            }
            ranges.Value = datas;
           
            workBook.SaveAs(path, objMissing, objMissing, objMissing, objMissing, objMissing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, objMissing,
                objMissing, objMissing, objMissing);
            workBook.Close(false, objMissing, objMissing);
            app.Quit();
            range = null;
            ranges = null;
            workBook = null;
            workSheet = null;
            app = null;
        }
C#
Sureboy的主页 Sureboy | 菜鸟二级 | 园豆:212
提问于:2012-09-04 10:05
< >
分享
所有回答(2)
0

分多个sheet

向往-SONG | 园豆:4853 (老鸟四级) | 2012-09-04 10:30
0

更换成 excel 2007 或 excel 2010

Launcher | 园豆:45045 (高人七级) | 2012-09-04 11:34
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册