输出到Excel
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
轉(zhuǎn)載于:https://www.cnblogs.com/TTonly/p/10349925.html
與50位技術(shù)專家面對(duì)面20年技術(shù)見證,附贈(zèng)技術(shù)全景圖總結(jié)
- 上一篇: Zinterstore 命令
- 下一篇: 缓存的那些事