最近有一个需求,将数据库里用户表的部分列提取出来,写入到Excel中去提供下载。
我的方法是一列一列提取出来放入一个二维的list里,然后通过NPOI写入到Excel中。
使用NPOI需要先导入相应的库
//部分引用
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using NPOI.HSSF.UserModel;
using System.IO;
public static void CreateYourExcel()
{
List<List<string>> List = new List<List<string>>();
List<string> List1 = new List<string>();
List<string> List2 = new List<string>();
List<string> List3 = new List<string>();
OracleConnection connOrac = new OracleConnection(connString.strLogin);
OracleCommand cmd = new OracleCommand
{
Connection = connOrac,
CommandType = CommandType.Text
}