zoukankan      html  css  js  c++  java
  • 使用NOPI写入Excel基础代码

     1 using NPOI.XSSF.UserModel;
     2 using System;
     3 using System.Collections.Generic;
     4 using System.IO;
     5 using System.Linq;
     6 using System.Text;
     7 using System.Threading.Tasks;
     8 
     9 namespace 学习NOPI
    10 {
    11     class Program
    12     {
    13         static void Main(string[] args)
    14         {
    15             //创建workbook工作簿
    16             XSSFWorkbook workbook = new XSSFWorkbook();
    17             //在workbook工作簿下创建两个工作表
    18             workbook.CreateSheet("SheetFirst");
    19             workbook.CreateSheet("SheetSecond");
    20             //获取工作表SheetFirst
    21             XSSFSheet worksheet = (XSSFSheet)workbook.GetSheet("SheetFirst");
    22             //在工作表下面创建10行
    23             for (int i = 0; i < 10; i++)
    24             {
    25                 worksheet.CreateRow(i);
    26             }
    27             //获取10行中的首行
    28             XSSFRow sheetrow = (XSSFRow)worksheet.GetRow(0);
    29             //申明一个长度10的单元格数组
    30             XSSFCell[] sheetcell = new XSSFCell[10];
    31 
    32             for (int i = 0; i < sheetcell.Length; i++)
    33             {   //创建10个单元格
    34                 sheetcell[i] = (XSSFCell)sheetrow.CreateCell(i);
    35                 //分别赋值
    36                 sheetcell[i].SetCellValue(i);
    37             }
    38             //写入流
    39             using (FileStream fs = new FileStream("TestNOPI.xlsx", FileMode.Create))
    40             {
    41                 workbook.Write(fs);
    42             }
    43             Console.WriteLine("OK");
    44             Console.ReadKey();
    45 
    46         }
    47     }
    48 }
  • 相关阅读:
    时间日期总览
    Mysql一次更新多条数据
    windows远程桌面连接无法粘贴
    vmware workstation pro密钥
    C#自动生成XML文件
    Mysql 缺少MSVCR120DLL问题
    hdu 5672 Strings 模拟
    poj 1328 雷达覆盖 贪心
    hdu 5667 Sequence (矩阵快速幂)
    CodeForces 652D Nested Segments 树状数组
  • 原文地址:https://www.cnblogs.com/sighful/p/9066027.html
Copyright © 2011-2022 走看看