FpSpread.OpenExcel 方法 (Stream),无法从内存流打开文件?
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