Public
Class
ExcelWriter
Private _wirter As System.IO.FileStream
Public Sub New ( ByVal strPath As String )
_wirter = New System.IO.FileStream(strPath, System.IO.FileMode.OpenOrCreate)
End Sub
''' <summary>
''' 写入short数组
''' </summary>
''' <param name="values"></param>
Private Sub _writeFile( ByVal values As Short ())
For Each v As Short In values
Dim b As Byte () = System.BitConverter.GetBytes(v)
_wirter.Write(b, 0 , b.Length)
Next
End Sub
''' <summary>
''' 写文件头
''' </summary>
Public Sub BeginWrite()
_writeFile( New Short () { & H809, 8 , 0 , & H10, 0 , 0 })
End Sub
''' <summary>
''' 写文件尾
''' </summary>
Public Sub EndWrite()
_writeFile( New Short () { & HA, 0 })
_wirter.Close()
End Sub
''' <summary>
''' 写一个数字到单元格x,y
''' </summary>
''' <param name="x"></param>
''' <param name="y"></param>
''' <param name="value"></param>
Public Sub WriteNumber( ByVal x As Short , ByVal y As Short , ByVal value As Double )
_writeFile( New Short () { & H203, 14 , x, y, 0 })
Dim b As Byte () = System.BitConverter.GetBytes(value)
_wirter.Write(b, 0 , b.Length)
End Sub
''' <summary>
''' 写一个字符到单元格x,y
''' </summary>
''' <param name="x"></param>
''' <param name="y"></param>
''' <param name="value"></param>
Public Sub WriteString( ByVal x As Short , ByVal y As Short , ByVal value As String )
Dim b As Byte () = System.Text.Encoding.Default.GetBytes(value)
_writeFile( New Short () { & H204, CShort ((b.Length + 8 )), x, y, 0 , CShort (b.Length)})
_wirter.Write(b, 0 , b.Length)
End Sub
End Class
Private _wirter As System.IO.FileStream
Public Sub New ( ByVal strPath As String )
_wirter = New System.IO.FileStream(strPath, System.IO.FileMode.OpenOrCreate)
End Sub
''' <summary>
''' 写入short数组
''' </summary>
''' <param name="values"></param>
Private Sub _writeFile( ByVal values As Short ())
For Each v As Short In values
Dim b As Byte () = System.BitConverter.GetBytes(v)
_wirter.Write(b, 0 , b.Length)
Next
End Sub
''' <summary>
''' 写文件头
''' </summary>
Public Sub BeginWrite()
_writeFile( New Short () { & H809, 8 , 0 , & H10, 0 , 0 })
End Sub
''' <summary>
''' 写文件尾
''' </summary>
Public Sub EndWrite()
_writeFile( New Short () { & HA, 0 })
_wirter.Close()
End Sub
''' <summary>
''' 写一个数字到单元格x,y
''' </summary>
''' <param name="x"></param>
''' <param name="y"></param>
''' <param name="value"></param>
Public Sub WriteNumber( ByVal x As Short , ByVal y As Short , ByVal value As Double )
_writeFile( New Short () { & H203, 14 , x, y, 0 })
Dim b As Byte () = System.BitConverter.GetBytes(value)
_wirter.Write(b, 0 , b.Length)
End Sub
''' <summary>
''' 写一个字符到单元格x,y
''' </summary>
''' <param name="x"></param>
''' <param name="y"></param>
''' <param name="value"></param>
Public Sub WriteString( ByVal x As Short , ByVal y As Short , ByVal value As String )
Dim b As Byte () = System.Text.Encoding.Default.GetBytes(value)
_writeFile( New Short () { & H204, CShort ((b.Length + 8 )), x, y, 0 , CShort (b.Length)})
_wirter.Write(b, 0 , b.Length)
End Sub
End Class