将Excel 95转换为Excel 97或更高版本

所以我们使用第三方组件打开excel表格并做一些工作。 但是,该工具无法处理Excel 95文件。 有谁知道一个工具,可以将Excel 95文件转换为以后的格式? 它可以指向一个外部应用程序…基于命令行的将是最好的。

另外:我们不能使用Excel COM Interop。

您可以使用Microsoft Access数据库引擎2010打开它,并将其用DocumentFormat.OpenXml.Packaging.SpreadsheetDocument类写出到xlsx文件中。

谷歌ado.Net excel c# ,你会发现很多关于如何设置连接string和打开Excel文件的示例。 (例如http://sharpertutorials.com/accessing-excel-spreadsheets-within-c-adonet/

理论上你应该可以遍历表单和行/列,并以类似的方式将它们写出到xlsx文件中。

你可以使用一个小的Excel助手macros。打开你的95源和.Save作为另一种格式使用命令行。 您可以使用kernel32 / GetCommandLine例程来获取cmdline参数。

为此,请创build一个工作簿“Converter.xls”并插入以下代码

模块“ThisWorkbook”

 Private Sub Workbook_Open() Dim CmdRaw As Long, CmdLine As String, Idx As Integer Dim MyFile As Workbook CmdRaw = GetCommandLine CmdLine = CmdToSTr(CmdRaw) ' Msgbox CmdLine Idx = InStr(1, CmdLine, "/e/") Set MyFile = Workbooks.Open(Mid(CmdLine, Idx + 3, 99)) MyFile.SaveAs "Test2003.xls", xlExcel7 Application.Quit End Sub 

模块“Module1”

 Declare Function GetCommandLine Lib "kernel32" Alias "GetCommandLineW" () As Long Declare Function lstrlenW Lib "kernel32" (ByVal lpString As Long) As Long Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (MyDest As Any, MySource As Any, ByVal MySize As Long) Function CmdToSTr(Cmd As Long) As String Dim Buffer() As Byte Dim StrLen As Long If Cmd Then StrLen = lstrlenW(Cmd) * 2 If StrLen Then ReDim Buffer(0 To (StrLen - 1)) As Byte CopyMemory Buffer(0), ByVal Cmd, StrLen CmdToSTr = Buffer End If End If End Function 

最后,通过命令行从包含95-XLS的path调用它

 C:\Progra~1\Micros~2\OFFICE11\excel Converter.xls /e/test95.xls 

test95.xls将被打开并以xlExcel7格式保存为test2003.xls。

到目前为止,基本的技术…现在你可以创造性地添加第二厘米线参数(由“/”分隔 – 更聪明地parsing等)等

重要:Excel必须运行在“宽松的安全”上,以避免在启动时发出macros警告消息 – 但是只要您debugging(禁用允许您返回到您的代码;-),警告消息是伟大的)

我快速和肮脏的testing这在Excel2003上

希望有所帮助