NPOI:如何使用NPOI读取文件 [英] NPOI : How To Read File using NPOI
本文介绍了NPOI:如何使用NPOI读取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发现使用C#编写的Excel文件非常好。
但是我想打开,读取和修改C#中的Excel文件。
I found NPOI is very good to write Excel files with C#. But I want to open, read and modify Excel files in C#.
我该怎么做?
推荐答案
以下简单阅读示例:
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
//.....
private void button1_Click(object sender, EventArgs e)
{
HSSFWorkbook hssfwb;
using (FileStream file = new FileStream(@"c:\test.xls", FileMode.Open, FileAccess.Read))
{
hssfwb= new HSSFWorkbook(file);
}
ISheet sheet = hssfwb.GetSheet("Arkusz1");
for (int row = 0; row <= sheet.LastRowNum; row++)
{
if (sheet.GetRow(row) != null) //null is when the row only contains empty cells
{
MessageBox.Show(string.Format("Row {0} = {1}", row, sheet.GetRow(row).GetCell(0).StringCellValue));
}
}
}
顺便说一句:在NPOI网站 here 在下载部分中有示例包 - 一组C#示例。尝试一下,如果还没有。 :)
By the way: on NPOI website here in Download section there is example package - a pack of C# examples. Try it, if you haven't yet. :)
这篇关于NPOI:如何使用NPOI读取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文