Jump to content
  • Advertisement
Sign in to follow this  
Cutman

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

This topic is 4551 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Ah, that does work! Excel can actually parse simple text files delimited with commas...I had no idea it could do that. Thanks!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!