Batch-Konvertierung von XLS in XLSX

Ich muss mit einer alten Anwendung arbeiten, die nur XLS-Dateien exportieren kann, und ich schreibe Programme in.NET mit der EPPlus-Bibliothek, die nur XLSX-Dateien lesen kann.

Was ist der einfachste Weg, um sie von XLS in XLSX Batch zu konvertieren?

Author: phuclv, 2012-12-25

6 answers

Schauen Sie sich Office Migration Planning Manager an.

Das Toolkit enthält auch den Office File Converter (OFC), der die Konvertierung von Großdokumenten von Binär-in OpenXML-Formate ermöglicht. (Technet - )

Übersicht über Technet

Download-Link

Beachten Sie, dass Sie auch die Microsoft Office Compatibility Pack for Word, Excel, and PowerPoint File Formats benötigen, damit der OFC funktioniert.
Beide Tools scheinen nicht mehr wirklich unterstützt zu werden.

 6
Author: ChrisN,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2019-11-20 16:32:27

Ich würde empfehlen, ein Makro zu verwenden, um die Dateien in einem Ordner zu verarbeiten und sie von xls in xlsx zu konvertieren. Dieser Code setzt voraus, dass sich die Dateien alle in einem Ordner befinden und dass alle xls-Dateien konvertiert werden müssen, aber wenn Sie einzelne Dateien auswählen möchten, kann dieser Code aktualisiert werden.

Dieser Code müsste von einer Excel 2007 oder höher Arbeitsmappe ausgeführt werden.

Option Explicit

' Convert all xls files in selected folder to xlsx

Public Sub convertXLStoXLSX()

    Dim FSO As Scripting.FileSystemObject
    Dim strConversionPath As String
    Dim fFile As File
    Dim fFolder As Folder
    Dim wkbConvert As Workbook

    ' Open dialog and select folder
    With Application.FileDialog(msoFileDialogFolderPicker)
        .AllowMultiSelect = False
        .Show
        On Error Resume Next ' Prevent debug mode if user cancels selection
        strConversionPath = .SelectedItems(1)
        On Error GoTo 0      ' Re-enable default error handling
    End With

    Set FSO = New Scripting.FileSystemObject

    ' Check if the folder exists
    If FSO.FolderExists(strConversionPath) Then
        Set fFolder = FSO.GetFolder(strConversionPath)

        ' Disable confirmation dialogs (to prevent "unsaved changes" dialog popping up)
        ' and screen updates (to speed up conversion)
        Application.DisplayAlerts = False
        Application.ScreenUpdating = False

        ' Loop through files, find the .xls files
        For Each fFile In fFolder.Files
            If LCase$(Right(fFile.Name, 4)) = ".xls" Then
                ' Open temporary workbook
                Set wkbConvert = Workbooks.Open(fFile.Path)
                ' Save as OpenXML workbook - if your .xls files contain macros
                ' then change to FileFormat:=xlOpenXMLWorkbookMacroEnabled
                wkbConvert.SaveAs FSO.BuildPath(fFile.ParentFolder, _
                                    Left(fFile.Name, Len(fFile.Name) - 4)) & ".xlsx", _
                                  FileFormat:=xlOpenXMLWorkbook
                wkbConvert.Close SaveChanges:=False
                ' Delete original file
                fFile.Delete Force:=True
            End If
        Next fFile

        ' Re-enable confirmation dialogs and screen updates
        Application.DisplayAlerts = True
        Application.ScreenUpdating = True

    End If

End Sub

Hinweis: Wenn die Dateien, die Sie konvertieren, Makros enthalten, müssen Sie die FileFormat:=xlOpenXMLWorkbook zu lesen FileFormat:=xlOpenXMLWorkbookMacroEnabled. Wenn Sie den Makrocode in den konvertierten Dateien nicht benötigen, können Sie ihn in Ruhe lassen und die Makros entfernen, wenn er in das xlsx-Format konvertiert wird.

 4
Author: Nick Perkins,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2019-11-25 14:25:37

Also habe ich ein einfaches VBScript zum Konvertieren geschrieben .xls-Dateien zu .xlsx auf stille Weise.

./convert-xls-xlsx.vbs {path to folder containing .xls files}

Convert-xls-xlsx-Format.vbs:

Set args = WScript.Arguments
strPath = args(0)
strPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(strPath)
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = False
objExcel.DisplayAlerts = False
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFso.GetFolder(strPath)
For Each objFile In objFolder.Files
    fileName = objFile.Path
    If (objFso.GetExtensionName(objFile.Path) = "xls") Then
        Set objWorkbook = objExcel.Workbooks.Open(fileName)
        saveFileName = Replace(fileName,".xls",".xlsx")
        objWorkbook.SaveAs saveFileName,51
        objWorkbook.Close()
        objExcel.Application.DisplayAlerts =  True
    End If
Next
MsgBox "Finished conversion"

HINWEIS: Achten Sie auf Leerzeichen im Ordnerpfad, wenn Ihr Pfad ein Leerzeichen dazwischen hat, setzen Sie den Pfad in Anführungszeichen.

 2
Author: brosahay,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2020-11-11 16:06:08

Wenn Sie LibreOffice oder OpenOffice haben, können Sie deren CLI convert feature

for %f in (*.xls) do "path\to\libreoffice\soffice.com" --convert-to xlsx "%f"

%f muss in einer Batchdatei in %%f geändert werden

In einigen Versionen müssen Sie libreoffice anstelle von soffice. Und manchmal müssen Sie --headless vor oder nach --convert-to hinzufügen, damit es funktioniert

Sie können auchunoconv da es "zwischen jedem von LibreOffice/OpenOffice unterstützten Dokumentformat konvertieren kann"

for %f in (*.xls) do unoconv -f xlsx "%f"
 1
Author: phuclv,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2021-02-04 02:01:16

Wenn Sie MSOffice installiert haben, dann könnte dieses Tool einen Download für eine schnelle Lösung wert sein.

Http://www.softinterface.com/Convert-XLS/Features/Convert-XLS-To-XLSX.htm

Wenn Sie einen Ordner auswählen, in dem die xls-Dateien konvertiert werden sollen, stellen Sie sicher, dass Sie die Option Konvertierungstool ankreuzen, die MS Office für die Konvertierung verwendet, nicht ihren eigenen Konverter.

Wenn Sie einen eigenen Konverter verwenden, verlieren Sie Farben in den Zellen und ein einzelnes Blatt scheint herauszukommen. Wenn Sie die MSOffice als Konverter scheint gut zu funktionieren. Gutes Werkzeug für eine schnelle Lösung.

 0
Author: 99Sono,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2016-06-16 12:02:23
Sub SaveAllAsXLSX()
Dim strFilename As String
Dim strDocName As String
Dim strPath As String
Dim wbk  As Workbook
Dim fDialog As FileDialog
Dim intPos As Integer
Dim strPassword As String
Dim strWritePassword As String
Dim varA As String
Dim varB As String
Dim colFiles As New Collection
Dim vFile As Variant
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
With fDialog
    .Title = "Select folder and click OK"
    .AllowMultiSelect = True
    .InitialView = msoFileDialogViewList
    If .Show <> -1 Then
        MsgBox "Cancelled By User", , "List Folder Contents"
        Exit Sub
    End If
    strPath = fDialog.SelectedItems.Item(1)
    If Right(strPath, 1) <> "\" Then strPath = strPath + "\"
End With
If Left(strPath, 1) = Chr(34) Then
    strPath = Mid(strPath, 2, Len(strPath) - 2)
End If
Set obj = CreateObject("Scripting.FileSystemObject")
RecursiveDir colFiles, strPath, "*.xls", True
For Each vFile In colFiles
        Debug.Print vFile
    strFilename = vFile
    varA = Right(strFilename, 3)
    If (varA = "xls" Or varA = "XLSX") Then
     Set wbk = Workbooks.Open(Filename:=strFilename)
       If wbk.HasVBProject Then
              wbk.SaveAs Filename:=strFilename & "m", FileFormat:=xlOpenXMLWorkbookMacroEnabled
            Else
               wbk.SaveAs Filename:=strFilename & "x", FileFormat:=xlOpenXMLWorkbook
            End If
            wbk.Close SaveChanges:=False
           obj.DeleteFile (strFilename)
    End If
Next vFile

End Sub
Public Function RecursiveDir(colFiles As Collection, _
                             strFolder As String, _
                             strFileSpec As String, _
                             bIncludeSubfolders As Boolean)

    Dim strTemp As String
    Dim colFolders As New Collection
    Dim vFolderName As Variant

    'Add files in strFolder matching strFileSpec to colFiles
    strFolder = TrailingSlash(strFolder)
    strTemp = Dir(strFolder & strFileSpec)
    Do While strTemp <> vbNullString
        colFiles.Add strFolder & strTemp
        strTemp = Dir
    Loop

    If bIncludeSubfolders Then
        'Fill colFolders with list of subdirectories of strFolder
        strTemp = Dir(strFolder, vbDirectory)
        Do While strTemp <> vbNullString
            If (strTemp <> ".") And (strTemp <> "..") Then
                If (GetAttr(strFolder & strTemp) And vbDirectory) <> 0 Then
                    colFolders.Add strTemp
                End If
            End If
            strTemp = Dir
        Loop

        'Call RecursiveDir for each subfolder in colFolders
        For Each vFolderName In colFolders
            Call RecursiveDir(colFiles, strFolder & vFolderName, strFileSpec, True)
        Next vFolderName
    End If

End Function
Public Function TrailingSlash(strFolder As String) As String
    If Len(strFolder) > 0 Then
        If Right(strFolder, 1) = "\" Then
            TrailingSlash = strFolder
        Else
            TrailingSlash = strFolder & "\"
        End If
    End If
End Function
 0
Author: pratap,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2020-11-10 07:18:17