1. Home
  2. Computing & Technology
  3. C / C++ / C#

Programming Challenge 21 - Data preparation
Runs Until February 28, 2009

By David Bolton, About.com

I use Excel extensively to prepare data for putting into databases or hard coded into applications. The tools I use do this but not everyone has them hence this programming challenge.

The Competition

Using any free or open source library that lets you read the contents xls files and write a command line or GUI application to read an xls file and output the contents as two text files xls.sql and xls.csv.
  1. SQL Insert statements
  2. CSV Data.

Download the xls spreadsheet
Note: The spreadsheet file will only have one sheet in it and the first row will have column names. I will be using a different spreadsheet with the same name (data.xls) to judge entries. It will have just one sheet and column names in the first row.

Example Answers

If the spreadsheet has 4 columns, say name, height, latitude and longitude, then the sql line for the row with name ='Bolton', height = 456, latitude = -4.0649, longitude = 53.8006 should be

insert into Table (name,height,latitude,longitude) values ('Bolton',456,-4.0649, 53.8006)
With csv data, the first row should be the column names followed by each row after e.g.
name, height, latitude,longitude
'Bolton',456,-4.0649, 53.8006

Results

There were two entries, both in C#, from Richard Mofet of South Africa who won and MJ Carmelotes who came 2nd. I judged them primarily on ease of use and the winner used a GUI with file dialogs etc.

Interestingly the winner used Microsoft Jet to read the file while the other entry used the Microsoft Office COM server for Excel. Thanks to both entrants.

  1. Richard Mofet (South Africa) - C#
  2. MJ Carmelotes(Philipines) - C#

More Programming Challenges

Explore C / C++ / C#
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. C / C++ / C#
  4. Projects
  5. Programming Challenges
  6. Programming Challenge 21 - Data Preparation>

©2009 About.com, a part of The New York Times Company.

All rights reserved.