Best free Excel writer for C# to output datatable to excel
Asked Answered
L

4

6

I've got a console app that loads up a datatable; I'd like to export that to an Excel format and attach it to an email that's sent out on a regular basis.

What is the best library to do so that I can pull down for free? I'm working for an academic institution and we don't have a budget for third-party controls.


possible related question: How to store data to Excel from DataSet without going cell-by-cell?

Legend answered 27/5, 2009 at 8:46 Comment(1)
What Excel features do you need? Do you just want to dump the data into an excel format or do you need charts or formulates, etc?Gober
A
13

Another free lib is CarlosAg Excel Xml Writer Library. Supports the new xml-based format.

Clarification: as we are talking about MS Excel here the new xml-based format is MS Office XML.

Amaurosis answered 27/5, 2009 at 8:57 Comment(4)
Just to be clear "the new XML-based format" isn't Office Open XML (which I would call "new"). It's MS Office XML. en.wikipedia.org/wiki/Microsoft_Office_XML_formatsDiverticulum
does it allow for cell merging?Concatenation
Thanks for the headsup - it's a critical thing for us as well as the ability to format the output.Concatenation
I also use it, even when the last update is from august 2005!Stereopticon
F
7

I would just write a CSV file to the hard drive.

Festive answered 27/5, 2009 at 8:51 Comment(5)
+1. When just dumping data, csv is a nice way to go. Especially since you then can load it easily into applications that doesn't read excel as well.Buchmanism
customers unfortunately dont always want thatBroomrape
indeed not what the OP was asking for. CSV is an alternative since Excel can import it, but imho not the best free option.Amaurosis
Yes, not the best free option, BUT maybe the most flexible option given that the OP works in an academic environment and the output can be read on any machine with or without Excel installed. Why lock yourself in to a data viewer when you don't have to..?Festive
ok fellas. side question - what's the best free option for delivering data from a web page if not csv? XML?Wallas
D
5

I usually use MyXls when I can't use commercial tools for some reason.

Shameless self-promotion: You could have a look at my SpreadsheetFactory tool, which is a tool designed to make exporting IEnumerable collections to spreadsheets easier. It is using MyXls as underlying xls engine.

Diorite answered 27/5, 2009 at 8:53 Comment(0)
C
3

You can just use a ODBCConnection with the connection string specifying the spreadsheet file.

EDIT: This does not require Excel on the server machine. It will produce an .xls file that can be readable on the client machine with MS Excel.

see How to store data to Excel from DataSet without going cell-by-cell? for more detail.

Corney answered 27/5, 2009 at 10:0 Comment(3)
Wouldn't that still require Excel to be installed on the machine?Ganesa
Not as far as I'm aware. I've used this technique on a server import application before and I don't believe we have Excel installed on our servers. Give it a try.Corney
using the OleDbConnection to create or fill an Excel file with data does not Excel to be installed on the machine.Wallas

© 2022 - 2024 — McMap. All rights reserved.