Jump to content

Convert XML to XLS


Recommended Posts

Can someone please guide me if there is a way to Open XML file as XLS? Or if we can convert XML to XLS file format.

I have an xml file which contains list of lines and when I open it in xls format the contents appear in columns and rows automatically. Which is the way I am looking for...

Link to comment
Share on other sites

Link to comment
Share on other sites

I am still facing some issues here getting the error for "Error Opening WorkBook..."

I am trying to Open $XML > Read the lines > and Save the file in $XLS format.

$XML = "C:\Temp\Scan.xml"
$XLS = "C:\Temp\Final.xls"

Func Convert()
    ; Create application object and open an example workbook
    Local $XLS = _Excel_Open()
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookSaveAs Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    Local $oWorkbook = _Excel_BookOpen($XLS, $XML)
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookSaveAs Example", "Error opening workbook '" & @ScriptDir & $XLS & @CRLF & "@error = " & @error & ", @extended = " & @extended)
        _Excel_Close($XLS)
        Exit
    EndIf

    ; *****************************************************************************
    ; Save the workbook (xls) in another format (html) to another directory and
    ; overwrite an existing version
    ; *****************************************************************************
    Local $sWorkbook = "C:\Temp\Scan.xml"
    _Excel_BookSaveAs($sWorkbook, $oWorkbook, True)
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookSaveAs Example 1", "Error saving workbook to '" & $sWorkbook & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookSaveAs Example 1", "Workbook successfully saved as '" & $sWorkbook & "'.")
;~ ShellExecute($sWorkbook)
EndFunc   ;==>ConvertToXLS

Convert()

 

Link to comment
Share on other sites

Try this.

 

#include <Excel.au3>



Local $sSourceFileXML = "C:\Users\xxx\Desktop\1.xml"
Local $sFinalFileXLS = "C:\Users\xxx\Desktop\1.xls"

_Convert($sSourceFileXML, $sFinalFileXLS)

Func _Convert($sXML, $sXLS)

    Local $oExcel = _Excel_Open(False)
    If @error Then Return False


    Local $oWorkbook = _Excel_BookOpen($oExcel, $sXML)
    If @error Then
        _Excel_Close($oExcel)
        Return False
    EndIf

    Local $iResult = _Excel_BookSaveAs($oWorkbook, $sXLS)

    _Excel_Close($oExcel)

    Return $iResult


EndFunc   ;==>_Convert

Saludos

Edited by Danyfirex
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...