Querying Excel files in ColdFusion

I have a project where I regularly import some data from an Excel file. Up until recently, I was exporting the data to a text file, using cffile to read it in, then parsing the data. Since I can run this particular process on my development machine, I decided to instead query the Excel file directly to cut down on the number of steps involved in the update.

Initially I ran into a problem with a column titled "Room". This column is a room number which is strictly a number half the time, but may also contain letters, such as in "26A". The problem was that Excel decides what each column data type is and it thought this column was a number. Guess what Excel does with the data that is not numeric--it throws it out and makes it a null value. So my initial queries had a bunch of null data for the room column.

To fix the problem, my google search turned up this resource on the ColdFusion FAQ. It talks about how to force a data type of text on a column containing mixed data. Here is the basic idea:

How to force a cell to be text;
You need a "copy" column beside it and put the following formula into it;
=Mid("'"&a2,2,Len(a2))
Assuming that A2 is the cell that contains the original data

So I created a new column in my spreadsheet that duplicated the Room column and named it RoomText. Then in my ColdFusion query, I referenced RoomText instead of Room. This fixed my problem! Whoohoo! It seems like there should be a better way...

Related Blog Entries

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
BlogCFC was created by Raymond Camden. This blog is running version 5.8.