Link to home
Start Free TrialLog in
Avatar of deanlee17
deanlee17

asked on

StreamWriter to output grid into .xls

Hi experts,

As above I need to output a wpf grid control into xls. I tried the below code to start, however when I try to open the xls I get 'the file you are trying to open is in a different format than specified by the file extension '

Code so far...

 var writer = new System.IO.StreamWriter("C:\\Users\\dean.lee\\Desktop\\moi.xls");

                writer.Write("Header1");
                writer.Write("Header2");
                writer.WriteLine();
                writer.Close();

Open in new window



Ideally I want the above and then I will FOR loop through the grid to populate with data.

Thanks,
Dean
Avatar of kaufmed
kaufmed
Flag of United States of America image

You say ".xls", but do you really mean an Excel file, or are you simply trying to write a file that Excel can open (e.g. .csv)?
Avatar of deanlee17
deanlee17

ASKER

I mean an xls ideally, I really dont want a .csv file.
Then you'll need to add a reference to the Excel Interop libraries and become cozy with the Excel object model. You'll need Office installed in order to be able to reference the Excel Interop libraries.
I'm sensing you don't recommend the above?

So its easier to just output to CSV? I just didn't want the user having to run through the process of choosing comma delimited etc etc as opposed to the file just opening.

Cheers.
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
haha ok cool.

Well I am happy to use a CSV but ideally I need it to open without asking the user any questions, I realise this may not be possible?