Reading Excel sheet missing columns

T

tshad

I am reading an excel sheet that shows 6 columns when opening it in excel
but when I open it in my c# program I only get 4 and the count is 4. It is
dropping Column A and Column B, which have nothing in the files.

I tried saving the file in csv format from excel and it only wrote out the 4
columns that had data in it (.C-F)

,Data,,
desc,Count of desc,,Sum of paymntamt
100,19,,363
111,45,,129

What happened to the 1st 2 columns?

Other files show columns when they aren't empty, since we are told which
columns to read from our client - we have to assume that all the columns are
they. In this file, they said to read columns C,D,E,F - but only C and D
are there and they are obviously the wrong columns for C and D. E and F are
out of bounds.

Thanks,

Tom
 
T

tshad

It turns out that if there absolutely nothing in the 1st set of columns,
they will not show, except in excel in xls format.

If you put anything in any cell in the A Column (including blank), it will
show the A and B columns. But if you take the blank out it will revert to
the old behavior.

I understand why this would work at the end of the column list but why at
the begining?

Thanks,

Tom
 
P

Peter Duniho

tshad said:
It turns out that if there absolutely nothing in the 1st set of columns,
they will not show, except in excel in xls format.

If you put anything in any cell in the A Column (including blank), it will
show the A and B columns. But if you take the blank out it will revert to
the old behavior.

I understand why this would work at the end of the column list but why at
the begining?

Your question appears to have absolutely nothing at all to do with C# or
..NET. Or even Windows programming, really.

Frankly, the answer to your question is moot. You can't change how
Excel writes out .csv files, or how other data providers (e.g.
database-like adapters) interpret a .xls file. But, assuming you really
want information about why it does things a certain way, I'm sure a C#
newsgroup is not the best place to look for an answer.

Even if you're writing your own program to read .xls files from scratch,
certainly the answer would be found in some misinterpretation on your
part of the .xls file format. But even if you had posted that code
(which of course you have not), without the additional information
regarding the file format itself, there's little anyone here would be
able to provide in the way of specific suggestions.

You're barking up the wrong tree. :) You will have much better success
posting your question in a forum where it's on-topic.

Pete
 
A

Andy O'Neill

tshad said:
It turns out that if there absolutely nothing in the 1st set of columns,
they will not show, except in excel in xls format.

If you put anything in any cell in the A Column (including blank), it will
show the A and B columns. But if you take the blank out it will revert to
the old behavior.

It's one of the many reasons why you shouldn't use excel files to hand data
between organisations.

People can put any old nonsense in any old column.
Management just don't understand.
You're the programmer.
Work your magic and just make it work for us.

Been there.
Iit was bad.
 
J

Jeff Johnson

I am reading an excel sheet

How? Using ADO.NET? If so, then the answer is "because that's how the
provider works" and, like Pete said, has nothing to do with C# but rather
ADO.NET.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top