Spire.XLS is a professional Excel .NET library that can be used to any type of .NET( C#, VB.NET, ASP.NET, .NET Core) application and Java (J2SE and J2EE) application.

Tue Feb 07, 2012 2:24 pm

I am evaluating the XLS component and i want to be able to open an excel file and convert it to a text file. I noticed in your sample that i downloaded that i can save a workbook to a stream. So I put together my own sample code that opens my excel file and writes it out to a file. When i run this, you seem to be overwriting my xls file with your copyright information because this is a trial version. My question is: Does the component support this?

Thanks for your help.

Dim workbook As Workbook = New Workbook()
Dim sheet As Worksheet = workbook.Worksheets(0)
Dim sFile As String

'Save an excel workbook to stream
Dim fileStream As FileStream = New FileStream("An_Inventory_Example.xls", FileMode.Open)

Dim bytes() As Byte = New Byte((fileStream.Length) - 1) {}
Dim numBytesToRead As Integer = CType(fileStream.Length, Integer)
Dim numBytesRead As Integer = 0
Dim objWriter As New System.IO.StreamWriter("An_Inventory_Example.prn")


While (numBytesToRead > 0)
' Read may return anything from 0 to numBytesToRead.
Dim n As Integer = fileStream.Read(bytes, numBytesRead, _
' Break when the end of the file is reached.
If (n = 0) Then
Exit While
End If
numBytesRead = (numBytesRead + n)
numBytesToRead = (numBytesToRead - n)


End While
numBytesToRead = bytes.Length


Posts: 1
Joined: Tue Feb 07, 2012 12:45 am

Wed Feb 08, 2012 2:32 am

Hello donbrookes,

Thanks for your inquiry.

The spire.Xls component support to save a worksheet to a text file directly. You can use the following code:
Code: Select all
 //load the workbook
            Workbook workbook = new Workbook();
            Worksheet sheet = workbook.Worksheets[0];

            //save the first worksheet as txt file
            sheet.SaveToFile("sample.txt", ",");

Please have a kind try. If you still have any other questions,please feel free to contact us.

Have a great day.

e-iceblue support
User avatar

Posts: 154
Joined: Thu Oct 20, 2011 2:53 am

Return to Spire.XLS