Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I programatically interface an Excel spreadsheet?

I have a request for some contract work from an organization that uses Excel as a database and wants to do some work on the Excel data via a real database. (Yeah, I know, never mind...)

The client has an Excel sheet that they use internally to keep track of some government programmes. The data from this Excel sheet used to be manually imported into a SQL database via CSV as intermediate format and made available via a tiny web app. Changes in either the spreadsheet or the db were done manually (by different people) and had to be kept in sync manually.

The spec for new functionality includes:

  • upload the Excel file into the web app
  • make minor changes via the web app (this bit is, of course, a no-brainer)
  • occasionally export the data back into Excel

The spreadsheet (actually, it's a couple of them in a workbook) implements some guidelines necessary to interact with other institutions and therefore has to remain the same structurally before and after import. It contains a lot of formatting, hidden columns and sort buttons as well as a lot of data links between the cells in the different sheets.

I don't want to have to reproduce the spreadsheet from scratch to deliver the export, nor do I want to manually extract the proper columns into CSV before making the import. I'm rather looking for a way to load the Excel, "query" certain fields, write them to the DB and later load the data back from the DB and manipulate only the contents of the proper cells.

Is there a way to programatically interface with an existing spreadsheet and only read or change the bits that you need?

like image 284
Hanno Fietz Avatar asked Nov 30 '22 20:11

Hanno Fietz


1 Answers

Excel is a 'COM Capable Application' and as such you can use COM to access and manipulate the data in an Excel document. You don't say what platform you are using - but if it's .NET then it's really very easy. See http://support.microsoft.com/kb/302084 for how to get started with C#.

If you're not using .net then any language that can interact with a COM component will work.

like image 174
Jackson Avatar answered Dec 04 '22 16:12

Jackson