I need help tracking down an error in using CFOBJECT to create a csv file
from an excel spreadsheet. 

I am using CF to open up an excel spreadsheet and then trying to turn the
data into a csv file. The code i'm using works fine the first time the
application is launched but on subsequent tries nothing happens. According
to the company hosting my site COM is causing the CF service to fail then it
has to be restarted. I'm listing the code i'm using below. 

Is this an issue with a patch needing to be installed or a problem with the
code below? Any help would much appreciated. Thanks.


-Brian


Stats
------
CF version CF5.0
IIS
Windows 2K server

Code
----

<cftry>
    <cfobject 
        action="CONNECT" 
        class="Excel.Application" 
        name="objExcel" 
        type="COM">
  <cfcatch>
        <cftry>
            <cfobject 
                action="CREATE" 
                class="Excel.Application" 
                name="objExcel" 
                type="COM"> 
          <cfcatch type="Object">
              Cannot create Excel Object
              <cfabort>
          </cfcatch>
        </cftry>
  </cfcatch>
</cftry>

<cftry>

<cfscript>

// this code will open up the excel spread sheet and then save it as a CSV
file.

    // HTML file path
    ExcelFilePath = "#attributes.excelFileIn#";
    
    // Destination path for new Word document
    // We leave off the extension since we'll declare the file type later on
    CSVFilePath = "#attributes.CSVFileOut#";
    
    // Open Word in the background
    objExcel.Visible = false;  
    
    // Disable alerts such as: 'Save this document?'
    objExcel.DisplayAlerts = false;               
    
    // Get the 'Documents' collection
    objBooks = objExcel.workbooks;  
    
    // Open the HTML document
    objBook = objBooks.Open(ExcelFilePath);  
        
        // Get the sheets collection 
        objSheets = objBook.WorkSheets;

        // Get the first sheet 
        objSheet = objSheets.Item(Val(1));   
        
        // Get a named sheet 
        objSheet = objSheets.Item("#attribtues.sheetName#");       
    
        
        /* Save it as a new document -- the extension will automatically
       be appended based on the file type we choose.
       Some of the file types to convert to:
       1 = .xls
       3 = .txt (tab delimetered
       6 = .csv
    */
        objSheet.SaveAs(CSVFilePath, Val(6));  
      
    // The next line would convert it to RTF instead
    // objSpreadSheet.SaveAs(CSVFilePath,Val(6));  
      
    // Close the document
    objBook.Close();    
    
    // Quit Word
    objExcel.Quit();
        
        if (attribtues.showConfirmation EQ 1) {
                writeOutput("<font size=""-1""
face=""Verdana,Geneva,Arial,Helvetica,sans-serif""><b>File Created:</b>
""#attributes.CSVFileOut#"" <b>from file:</b>
""#attributes.excelFileIn#""<p></font>");
        }
</cfscript>

  <cfcatch>
  <!--- error creating file --->
  <font face="Verdana,Geneva,Arial,Helvetica,sans-serif" size="-1">there was
an error creating your new CSV filesfrom your Excel Spreadsheet</font>
  </cfcatch>
</cftry>
______________________________________________________________________
Get the mailserver that powers this list at http://www.coolfusion.com
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to