首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

NPOI读取数据,创办filestream实例时总是出错

2013-12-10 
NPOI读取数据,创建filestream实例时总是出错这是代码 using Systemusing System.Collections.Genericusi

NPOI读取数据,创建filestream实例时总是出错
这是代码 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NPOI.HSSF.UserModel;
using NPOI.HPSF;
using NPOI.POIFS.FileSystem;
using System.IO;
using NPOI.SS.UserModel;
namespace XLS实验
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        
        private void button1_Click(object sender, EventArgs e)
        {
            if (openFile.ShowDialog() == DialogResult.OK)
            {
                int[] bianhao = new int[225];
                string path = "";
                path = openFile.FileName;
                FileStream fs = File.Open(path,FileMode.Open);
                HSSFWorkbook myxls = new HSSFWorkbook(fs);
                ISheet mysheet = myxls.GetSheet("sheet1");
                StringBuilder sb = new StringBuilder("");
                for (int i = 0; i <= 225; i++)
                {
                    IRow row = mysheet.GetRow(i + 2);
                    ICell cell=row.GetCell(1);
                    bianhao[i] = (int)cell.NumericCellValue;
                    for(int j=0;j<=225;j++)
                    {
                        this.textBox1.Text+= bianhao[j].ToString();
                    }
                }
                fs.Close();
            }
            
            
        }
    }
}

每次到FileStream fs = File.Open(path,FileMode.Open);就会出错
我换过FileStream fs = new FileStream(path,FileMode.Open,FileAccess.Read);   还是同样出错
[解决办法]
接着按下F10,看得到什么错误信息。

热点排行