Search code examples
excelsql-updateoledb

How to update excel cell via SQL by a coordinate?


Is it possible to update an excel file using this SQL query?

UPDATE [My Sheet] SET B40='17'

The B40 is the coordinate of that excel file. Due to the structure of the existing excel file, I cannot use a table column to update. I only have to use coordinates.

When I run this I get this exception below:

No value given for one or more required parameters.

And my connection string is:

@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileName +";Extended Properties='Excel 12.0;HDR=NO;ReadOnly=False;'"

There is also a question here but I'm still getting the same error


Solution

  • Thank you very much for Aditya on the comments that helped me realize I was thinking this a bit wrong.

    First, my conn string is now:

    @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileName + ";Extended Properties='Excel 12.0;HDR=NO;ReadOnly=False;'"
    

    And second, the query is now like:

    UPDATE [My Sheet$B40:B40] SET F1=17
    

    I always thought F1 should be THE coordinate I want to update and that's why I failed.