[.net] Looking for a good xls file format tutorial.

Started by
3 comments, last by Cutman 18 years, 4 months ago
I've been having a problem - I need to save my data in .xls format. However, I am only finding ASP and ADO .NET tutorials. I just want to know what libs to import, how to open a file, how to put data in it, and how to save. I don't care about other properties like centering etc. I've spent the last two hours looking, and I am coming up short. VB.NET preferred, but I do C++ in the Framework too. Thanks
Advertisement
Looking over some stuff I found a managed set of libraries for office that come with Visual Studio. Of course, I can't tell if this is just with the Team system edition, or if other versions can install it as well. If I recall correctly, they require office installed to work. Check if you can import the assembly:
Microsoft.Office.Tools.Excel

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

Thank you very much. I'll give it a shot.
There's a reason you're getting ADO.NET tutorials for Excel. If you just want to read or write tabular data using the xls file format, create an OleDbConnection with a connection string like this (from connectionstrings.com):

@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyExcel.xls;Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\""

"HDR=Yes;" indicates that the first row contains columnnames, not data
"IMEX=1;" tells the driver to always read "intermixed" data columns as text
TIP! SQL syntax: "SELECT * FROM [sheet1$]" - i.e. worksheet name followed by a "$" and wrapped in "[" "]" brackets.

Follow the usual ADO.NET procedures to write data (create a DataTable, DataSet, DataAdapter, etc.) and read data.

Another option I've found is to write out a CSV (comma separated value) file instead. Excel is already associated with .csv files, and they are tabular just like .xls.
Ah, that does work! Excel can actually parse simple text files delimited with commas...I had no idea it could do that. Thanks!

This topic is closed to new replies.

Advertisement