本帖最后由 zhangcheng5468 于 2013-8-1 10:43 编辑
通过内存流NPOI操作Excel时报错,提示DisposeException,但建立HSSFWorkbook仍在using内部内存流的作用域当中!求解?- WebClient wc = new WebClient();
- wc.Credentials = new NetworkCredential(txt_username.Text.Trim(), txt_pwd.Text.Trim());//指定用户名密码
- //约定下载的文件名为“门店号+当天日期”如:0220130801.xls
- using(Stream stream = wc.OpenRead("ftp://127.0.0.1/0220130730.xls"))
- {
- using(Stream ms = new MemoryStream())
- {
- byte[] bytes = new byte[1024];//创建1K的缓存区
- int readbytes;
- while ((readbytes = stream.Read(bytes, 0, bytes.Length)) > 0)
- {
- ms.Write(bytes, 0, bytes.Length);
- }
- //TODO:根据内存流创建HSSFWorkbook失败
- HSSFWorkbook wb = new HSSFWorkbook(ms);
- MessageBox.Show(wb.GetSheetAt(0).GetRow(0).GetCell(0).StringCellValue);
- }
- }
- MessageBox.Show("数据导入成功!");
复制代码 |