chubhub
chubhub

Reputation: 19

vb.net conversion

Hi I have the following code snippet for converting files from .xlsm to .xlsx. The code is in C# but I need it in vb. Pls advice.

byte[] byteArray = File.ReadAllBytes("C:\\temp\\test.xlsm");
using (MemoryStream stream = new MemoryStream())
{
stream.Write(byteArray, 0, (int)byteArray.Length);
using (SpreadsheetDocument spreadsheetDoc = SpreadsheetDocument.Open(stream, true))
 // Change from template type to workbook type
{
spreadsheetDoc.ChangeDocumentType (SpreadsheetDocumentType.Workbook);
}
File.WriteAllBytes ("C:\\temp\\test.xlsx", stream.ToArray()); 
}

Upvotes: 0

Views: 367

Answers (1)

MarcinJuraszek
MarcinJuraszek

Reputation: 125620

Have you even tried doing it by yourself? There are few good tools for that kind of conversion available online, like that one: http://www.developerfusion.com/tools/convert/csharp-to-vb/

Dim byteArray As Byte() = File.ReadAllBytes("C:\temp\test.xlsm")
Using stream As New MemoryStream()
    stream.Write(byteArray, 0, CInt(byteArray.Length))
    Using spreadsheetDoc As SpreadsheetDocument = SpreadsheetDocument.Open(stream, True)
        ' Change from template type to workbook type
        spreadsheetDoc.ChangeDocumentType(SpreadsheetDocumentType.Workbook)
    End Using
    File.WriteAllBytes("C:\temp\test.xlsx", stream.ToArray())
End Using

Upvotes: 1

Related Questions