当前位置:编程学习 > C#/ASP.NET >>

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 --------------------编程问答-------------------- 3、FpSpread.OpenExcel 方法 (Stream)

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

4、我现在要从内存流在控件中显示表格,那么可能需要将内存流转换成文件流。是不是必须将内存流内容创建为文件然后打开文件创建文件流才能成功呢?
补充:.NET技术 ,  组件/控件开发
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,