1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
string filePath = Server.MapPath("/test.xlsx"); FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite); XSSFWorkbook workbook1 = new XSSFWorkbook(); SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook(workbook1, 100); var first = sxssfWorkbook.CreateSheet("MySheet"); for (int i = 0; i < 1000000; i++) { var row = first.CreateRow(i); for (int j = 0; j < 11; j++) { if (i == 0) { // 首行 row.CreateCell(j).SetCellValue("column" + j); } else { // 数据 if (j == 0) { row.CreateCell(j).SetCellValue(i.ToString()); } else { row.CreateCell(j).SetCellValue(new Random().Next().ToString()); } } } } sxssfWorkbook.Write(fs); fs.Close(); fs.Dispose(); |