I have an excel file that has ~10 columns and 1-20 rows. I need to insert 1-20 rows with various data elements.
I was wondering if there was a way I could put some tags in the excel file so they could be found and replaced. Something that marks a column as “Name”. That way in code I could just say:
Name[0] = object.name;
I’m not sure if this exact method is possible, but I really don’t need any heavy lifting and I rather not hard code the cell locations as the excel file might change over time.
I will also have to add a hidden ‘ID’ cell in row. I imagine I can cross that bridge later though.
Using ADO.NET is easy to add a row to an Excel Sheet
The code above assumes that you have a first row with an header with Column1… as column names.
Also, the code use the ACE OleDB provider for Excel 2007 or 2010 instead of Microsoft.Jet.OleDb.4.0.
EDIT: To refer to a Named Range you could change the sql command to this one
Alas, I can’t find a way to refer to the individual columns.