日期:2014-05-17  浏览次数:20929 次

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();
                    }