tags:

views:

523

answers:

2

Hello.

I am creating a small winforms application for distribution to a few people. I would like the users to be able to export the contents of a DataGridView to a file that Excel can read. I would like the file to be a excel file and not csv or xml. In the past when I have created an "export to excel" function I have always had to include the "Microsoft.Office.Interop.Excel.dll" as part of the distribution. I would like to just send the users the exe file nothing else. is there a way that I could get away from this second file?

update:

to combine the assemblys I used ILmerge with the following Cmd Line ilmerge /target:winexe /out:PpShiftReport.exe OperatorShiftReport.exe Microsoft.Office.Interop.Excel.dll

+1  A: 

If you want to create .xls files you'll need to either use the interop assembly or find another library that can create xls files (I don't know of any offhand). There's no way around the licensing issue but if you want .xls files then you can safely assume the client has excel installed on their machine? (otherwise how would they open them?)

To avoid this I usually just export to CSV. Remember to handle quoting (double quotes twice to include a literal double quote).

Arnshea
+1  A: 

Use ILMerge to embed the interop DLL into your EXE.

Duncan Smart
Oh yes I forgot about that...I'll give it a shot. On first inspection it looked painful to use.
Brad