c# 和 Excel

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;


using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;


namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
HSSFWorkbook wk = new HSSFWorkbook();
//创建一个Sheet
ISheet sheet = wk.CreateSheet("例子");
//在第一行创建行
IRow row = sheet.CreateRow(0);
//在第一行的第一列创建单元格
ICell cell = row.CreateCell(0);
cell.SetCellValue("测试");
//打开一个xls文件,如果没有则自行创建,如果存在myxls.xls文件则在创建时不要打开该文件
using (FileStream fs = File.OpenWrite("d:\excel.xls"))
{
wk.Write(fs);//向打开的这个xls文件中写入并保存。
}
}
}
}
原文地址:https://www.cnblogs.com/eaglezzb/p/4176473.html