Rob Gonda's Blog

How do I return a query from an Excel file?

There are two three ways of doing this. The first one is using dynamic datasources, where you can define a dsn in the ColdFusion Administration, and then override the location of the file in runtime. This works for Access and Excel, and it's well explained in the Adobe site.

The second option JDBC drivers directly, and this is a good time to remind everyone about the ColdFusion Cookbook, which is yet another project that Ray's leading. It's explained here.

JIC you want to know what it looks like, here's a UDF.

<cffunction name="getExcelSheet" access="public" output="false" returntype="query">
      <cfargument name="filename" required="true" type="string" />
      <cfargument name="sheetName" required="true" type="string" />
      <cfscript>
         var c = "";
         var stmnt = "";
         var rs = "";
         var sql = "Select * from [#sheetName#$]";
         var myQuery = "";
         arguments.filename = expandPath(arguments.filename);
        
         if(len(trim(arguments.filename)) and fileExists(arguments.filename)){
            try{
               CreateObject("java","java.lang.Class").forName("sun.jdbc.odbc.JdbcOdbcDriver");  
               c = CreateObject("java","java.sql.DriverManager").getConnection("jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ=" & arguments.filename );
               stmnt = c.createStatement();
               rs = stmnt.executeQuery(sql);
               myQuery = CreateObject('java','coldfusion.sql.QueryTable').init(rs);
            }catch(any e){
               // error-handling code             }
         }
         return myQuery;
      </cfscript>
   </cffunction>

The third option is to use Sean Corfield's Java CFX tags, part of the OpenXCF project. I couldn't find extensive documentation, but it looks pretty straight forward:

<cfx_ExcelQuery action="read" file="#xlsfile#" variable="myQuery" />
<cfx_ExcelQuery action="write" file="#xlsfile#" query="myQuery" />

Reminder: South Flordia CFUG tomorrow

Drew Nathanson will be speaking tomorrow at the South Florida CFUG and database design. For those of you who didn't make it to Max -- most of us --, I'm sure this would be a great topic, so I hope to see you there.

As a side note, I would probably brief you on some info Adobe is releasing at Max, such as info on Scorpio and Apollo.

Firefox 2 new features

For those of you wondering what improved on Firefox 2, you can check out this link for complete details. They mentioned Improved Tabbed Browsing, Spell Checking, Search Suggestions, Session Restore, Web Feeds (RSS), Live Titles, Integrated Search, Live Bookmarks, Pop-up Blocker, Streamlined Interface, Accessibility, Phishing Protection, Open Source, More Secure, Automated Update, Protection from Spyware, Clear Private Data, An Add-on for Everyone, Add-ons Manager for Extensions and Themes, and Search Engine Manager.

So btw, I was wrong on my last post where I mentioned Tab Mix Plus does not work with FF2; it doesn't indeed, but all the functionality is now part of the core distribution, including session management.

This blog is running version 5.9.003. Contact Blog Owner