FpSpread.OpenExcel 方法 (Stream),无法从内存流打开文件?

firejay 2012-01-27 06:37:50
1、有一个xls文件存储在ACCESS数据库的ole字段“结算单存储路径”中
2、首先我尝试从文件流打开文件:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'打开数据库连接
Dim tempConnection As New OleDb.OleDbConnection
tempConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\Backup\我的文档\Visual Studio 2008\Projects\文件读写测试\结算计价信息系统.mdb"
tempConnection.Open()
Dim readimg As New OleDb.OleDbCommand("SELECT 结算单台账.结算单存储路径, 结算单台账.ID FROM 结算单台账 where 结算单台账.ID=109", tempConnection)
Dim rs As OleDbDataReader = readimg.ExecuteReader()
Dim xlsbyte() As Byte
While rs.Read
xlsbyte = rs("结算单存储路径")
MsgBox(rs("ID").ToString)
End While
Dim f As String
f = "C:\Documents and Settings\Administrator\桌面\19.xls"
Dim s As New System.IO.FileStream(f, IO.FileMode.Create, IO.FileAccess.ReadWrite)
s.Write(xlsbyte, 0, xlsbyte.Length)
s.Close()
Dim opf As New System.IO.FileStream(f, IO.FileMode.Open, IO.FileAccess.ReadWrite)
Try
FpSpread1.OpenExcel(opf)'结果:可以成功打开文件。
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
2、我改用从内存流来打开xls,我失败了,请教有什么办法可以解决?
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
'打开数据库连接
Dim tempConnection As New OleDb.OleDbConnection
tempConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\Backup\我的文档\Visual Studio 2008\Projects\文件读写测试\结算计价信息系统.mdb"
tempConnection.Open()
Dim readimg As New OleDb.OleDbCommand("SELECT 结算单台账.结算单存储路径, 结算单台账.ID FROM 结算单台账 where 结算单台账.ID=109", tempConnection)
Dim rs As OleDbDataReader = readimg.ExecuteReader()
Dim xlsbyte() As Byte
While rs.Read
xlsbyte = rs("结算单存储路径")
MsgBox(rs("ID").ToString)
End While
Dim xlsmemory As New MemoryStream()
Try
xlsmemory.Write(xlsbyte, 0, xlsbyte.Length)
FpSpread1.Open(xlsmemory)’无法打开文件,请问怎么解决?
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
...全文
204 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
firejay 2012-01-29
  • 打赏
  • 举报
回复
3、FpSpread.OpenExcel 方法 (Stream)

参数 说明 stream 表示指定的 Excel 文件流。

4、我现在要从内存流在控件中显示表格,那么可能需要将内存流转换成文件流。是不是必须将内存流内容创建为文件然后打开文件创建文件流才能成功呢?

8,834

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 组件/控件开发
社区管理员
  • 组件/控件开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧