1 添加NPOI相关引用
2 在debug下建立一个excle模版文件
3
导入
private void Createcell(IRow row, int index, string msg)
{
ICell ic = row.GetCell(index);
if (msg != null)
{
ic.SetCellValue(msg);
}
}
private void button2_Click(object sender, EventArgs e)
{
string excelpath ="c:/11" + ".xls";
File.Copy(Application.StartupPath + "\\temp.xls", excelpath, true);
HSSFWorkbook writexcel;
using (FileStream file = new FileStream(excelpath, FileMode.Open, FileAccess.Read, System.IO.FileShare.Read))
{
writexcel = new HSSFWorkbook(file);
}
//打开sheet