wang1234587 发表于 2013-12-7 21:20:57

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;
                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 = (int)cell.NumericCellValue;
                  for(int j=0;j<=225;j++)
                  {
                        this.textBox1.Text+= bianhao.ToString();
                  }
                }
                fs.Close();
            }
            
            
      }
    }
}

每次到FileStream fs = File.Open(path,FileMode.Open);就会出错
我换过FileStream fs = new FileStream(path,FileMode.Open,FileAccess.Read);   还是同样出错

ibcadmin 发表于 2013-12-12 13:23:17

报的什么错
页: [1]
查看完整版本: NPOI读取数据,创建filestream实例时总是出错