0

您好我有以下用于将文件从 .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()); 
}
4

1 回答 1

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
于 2012-11-05T06:56:08.273 回答