c# reading excel with spaces in column hdr

Microsoft Excel 2003 (full product)
March 15, 2011 at 14:40:33
Specs: windows server standard without hyperv
How do I...
I'm using c# to read an excel workbook that has spaces in the column header.

For example

string SelectCommand = "Select Account, City, 'Store Number' as Strnbr from [Sheet1$]";

I've tried
backtick - `Store Number` - gets error at runtime
brackets - [Store Number] - gets error at runtime
single quote 'Store Number' - returns the string "Store Number" rather than actual data
double quote /"Store Number/" - returns the string "Store Number" rather than actual data

In sql, using double quotes around the header works, but it's not working with c#.

Does anyone know the syntax to get this to work? Thanks.


See More: c# reading excel with spaces in column hdr

Report •


#1
April 5, 2011 at 20:01:36
Did you get an answer to this? I have similar issue. I need to read an excel sheet in C# but the column names have too many extra spaces.

Report •

#2
April 6, 2011 at 05:26:49
No, I never got this to work, sorry. I ended up having the user redo the sheet with no spaces in the headers. But, if you're desperate, you can programmatically either ignore the header line (select *, process the columns by number ([0], [1] in place of the name to look at specific columns) and don't process the first row), or delete the header row and put your own on. I think all that is possible with c#.

Report •

Related Solutions


Ask Question