C# .NET 使用 NPOI 生成 .xlsx 格式 Excel
1 IWorkbook workbook = new XSSFWorkbook();2 ISheet sheet = workbook.CreateSheet("-");
3 IRow row = sheet.CreateRow(0);//标题
4
5 IRow titleRow = row.CreateCell(0);
6 Row.SetCellValue("标题列1");
7
8 IRow dataRow = sheet.CreateRow(1);
9 dataRow.CreateCell(0).SetCellValue(“第一行第一列数值”);
10
11 string fileName = "demo.xlsx";
12
13 FileStream file = new FileStream("C:\\Desktop\\" + fileName, FileMode.Create);//把这个HSSFWorkbook实例写入文件
14 workbook.Write(file);
15 file.Close();
16
17 /*假如此处要下载*/
18 //MemoryStream ms = new MemoryStream();
19 //workbook.Write(ms);
<p> </p>
页:
[1]