vb.net转换

时间:2012-11-05 06:42:49

标签: vb.net

您好我有以下代码片段,用于将文件从.xlsm转换为.xlsx。 代码在C#中,但我在vb中需要它。请咨询。

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()); 
}

1 个答案:

答案 0 :(得分:1)

你有没有试过自己做?在线提供这种转换的好工具很少,例如: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