Open an excel file using COM and save it as .xml file
        Posted  
        
            by chupinette
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by chupinette
        
        
        
        Published on 2010-03-25T08:02:41Z
        Indexed on 
            2010/03/25
            8:13 UTC
        
        
        Read the original article
        Hit count: 571
        
Hi. Im trying the following code:
<?php
    $workbook = "D:\b2\\test.XLS";
    $sheet = "Sheet1";
    #Instantiate the spreadsheet component.
        $ex = new COM("Excel.sheet") or Die ("Did not connect");
    #Get the application name and version    
        print "Application name:{$ex->Application->value}<BR>" ; 
        print "Loaded version: {$ex->Application->version}<BR>"; 
    #Open the workbook that we want to use.
        $wkb = $ex->application->Workbooks->Open($workbook) or Die ("Did not open");
    #Create a copy of the workbook, so the original workbook will be preserved.
        $ex->Application->ActiveWorkbook->SaveAs("D:\b2\Ourtest.xml");  
        #$ex->Application->Visible = 1; #Uncomment to make Excel visible.
    #Optionally, save the modified workbook
        $ex->Application->ActiveWorkbook->SaveAs("D:\Ourtest.xml");                      
    #Close all workbooks without questioning
        $ex->application->ActiveWorkbook->Close("False");    
        unset ($ex);
    ?> 
This actually works and creates the Ourtest.xml file. But im getting characters like:
ÐÏà¡±á                >  þÿ                                þÿÿÿ
I have tried with SaveAs("D:\Ourtest.pdf") and it says the file has been corrupted or incorrectly decoded. 
Can anyone help me please?Thanks
© Stack Overflow or respective owner