Option Strict On
Option Explicit On
Imports System.IO
Imports System.Text
Module Module1
Dim Stream1 As Stream
Dim BinaryWriter1 As BinaryWriter
Dim clBegin() As UShort = {CUShort(Convert.ToInt32("809", 16)), 8, 0, CUShort(Convert.ToInt32("10", 16)), 0, 0}
Dim clEnd() As UShort = {CUShort(Convert.ToInt32("0A", 16)), 0}
Private Sub WriteUShortArray(ByVal pValue As UShort())
For DL As Integer = 0 To pValue.Length - 1
BinaryWriter1.Write(pValue(DL))
Next
End Sub
Public Sub ExcelWriter(ByVal pStream As Stream)
Stream1 = pStream
BinaryWriter1 = New BinaryWriter(Stream1)
End Sub
Public Sub WriteCell(ByVal pRow As Integer, ByVal pCol As Integer, ByVal pValue As String)
Dim clData() As UShort = {CUShort(Convert.ToInt32("204", 16)), 0, 0, 0, 0, 0}
Dim plainText() As Byte = Encoding.ASCII.GetBytes(pValue)
clData(1) = CUShort(8 + pValue.Length)
clData(2) = CUShort(pRow)
clData(3) = CUShort(pCol)
clData(5) = CUShort(pValue.Length)
WriteUShortArray(clData)
BinaryWriter1.Write(plainText)
End Sub
Public Sub WriteCell(ByVal pRow As Integer, ByVal pCol As Integer, ByVal pValue As Integer)
Dim clData() As UShort = {CUShort(Convert.ToInt32("27E", 16)), 10, 0, 0, 0}
clData(2) = CUShort(pRow)
clData(3) = CUShort(pCol)
WriteUShortArray(clData)
Dim Value1 As Integer = (pValue << 2) Or 2
BinaryWriter1.Write(Value1)
End Sub
Public Sub WriteCell(ByVal pRow As Integer, ByVal pCol As Integer, ByVal pValue As Double)
Dim clData() As UShort = {CUShort(Convert.ToInt32("203", 16)), 14, 0, 0, 0}
clData(2) = CUShort(pRow)
clData(3) = CUShort(pCol)
WriteUShortArray(clData)
BinaryWriter1.Write(pValue)
End Sub
Public Sub WriteCell(ByVal pRow As Integer, ByVal pCol As Integer)
Dim clData() As UShort = {CUShort(Convert.ToInt32("201", 16)), 6, 0, 0, CUShort(Convert.ToInt16("17"))}
clData(2) = CUShort(pRow)
clData(3) = CUShort(pCol)
WriteUShortArray(clData)
End Sub
Public Sub BeginWrite()
WriteUShortArray(clBegin)
End Sub
Public Sub EndWrite()
WriteUShortArray(clEnd)
BinaryWriter1.Flush()
End Sub
Sub Main()
Try
Dim FileStream1 As FileStream = New FileStream("demo.xls", FileMode.OpenOrCreate)
ExcelWriter(FileStream1)
BeginWrite()
WriteCell(0, 0, "ExcelWriter Demo")
WriteCell(1, 0, "int")
WriteCell(1, 1, 10)
WriteCell(2, 0, "double")
WriteCell(2, 1, 1.5)
WriteCell(3, 0, "empty")
WriteCell(3, 1)
EndWrite()
FileStream1.Close()
Catch ex As Exception
MsgBox(Err.Description)
End Try
End Sub
End Module