HSSFWorkbook oBook = new HSSFWorkbook();
NPOI.SS.UserModel.ISheet oSheet = oBook.CreateSheet();
#region 输出到Excel
MemoryStream ms = new MemoryStream();
oBook.Write(ms);
string sExportPath = "";
using (SaveFileDialog saveFileDialog1 = new SaveFileDialog())
{
saveFileDialog1.Title = "另存为";
saveFileDialog1.InitialDirectory = @"C:";
saveFileDialog1.Filter = "Excel(*.xls)|*.xls";
saveFileDialog1.AddExtension = true;
saveFileDialog1.FileName = "未刷_方" + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls";
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
sExportPath = saveFileDialog1.FileName;
}
}
using (FileStream fs = new FileStream(sExportPath, FileMode.Create, FileAccess.Write))
{
byte[] bArr = ms.ToArray();
fs.Write(bArr, 0, bArr.Length);
fs.Flush();
}
#endregion