Reading and writing XLS files - c#

Im searching for a .Net component to read and write xls files from an application in working on. I dont want use automation with Excel.
It should support reading and write Excel 97 and newer versions. And it would be great if its open source or free since its a very low budget project.
I have found this one: MyXLS that looks very promising.
Do you know of any alternatives?

SpreadsheetGear for .NET reads and writes CSV / XLS / XLSX and does more.
You can see live ASP.NET samples with C# and VB source code here and download a free trial here.
Disclaimer: I own SpreadsheetGear LLC

As an alternative I can suggest Excel
Jetcell .NET component. It pretty
Excel component. It does not use Jet
drivers and excel automation. All
information please find at:
http://www.devtriogroup.com/ExcelJetcell

You can use EasyXLS. The component reads xls files from Excel 97 and xlsx/xlsb files from Excel 2007-2010.
www.easyxls.com
You can find samples for how to use on their website.

This must be one of the most asked questions on SO.

First - which version of Excel must you support? For example, xslx (2007) is just a zip file with xml files inside - so you should be able to use #ZipLib and xml generation / copying.
Another option is to write CSV and let the user import it - obviously more appropriate for data than for calculations.
There is also the 2003 xml-spreadsheet format - with contents like:
<Table ss:ExpandedColumnCount="3" ss:ExpandedRowCount="1" x:FullColumns="1"
x:FullRows="1" ss:DefaultRowHeight="15">
<Row>
<Cell><Data ss:Type="Number">1</Data></Cell>
<Cell><Data ss:Type="Number">2</Data></Cell>
<Cell ss:Formula="=RC[-2]+RC[-1]"><Data ss:Type="Number">3</Data></Cell>
</Row>
</Table>
Pretty easy to create by hand...

Where I work they have this one: http://www.syncfusion.com/products/xlsio/backoffice/default.aspx
Have used it a couple of times and it is pretty easy to use.

I've worked with aspose for a long time and can really recommend it.
http://www.aspose.com/categories/file-format-components/aspose.cells-for-.net-and-java/default.aspx
Commercial product
Great support
Excel 97-2007
100% native .net

Related

How to generate xls & xlsx from office 2003 xml spreadsheet programatically in c#

Currently our application exporting large data to office 2003 xml spreadsheet format in server.
The user can download the xml file.The file can be easily opened in office 03 and 07 correctly.
I want to know whether it is possible to create xls and xlsx format from this xml file in server and serve them to user?
[The server doesn't have office and neither will be.So interop is useless in this case.]
====== EDIT=====
Can't use third party solutions... :(
With your XML file, you could easily use XSLT to transform your XML into CSV. However, if you really need to export in native Excel spreadsheet types, it's probably a good idea to use a component.
Something we've used in the past, that I'd recommend, is Aspose.Cells – we've used this to generate Excel spreadsheets where plain CSV output wouldn't suffice (are you sure it won't suffice in your case - XSLT will make short work of that).
Whilst it's not free, it saves having to install Office on the server (and avoid using Office Automation etc.) and has very good support.
Edited following comments:
If you can't use third party components, if you can't install Office on the server, and you can't use interop, then – unless you want to get comfortable and read the Excel Binary File Format (.xls) Structure Specification as provided by Microsoft – the answer is a very short one: no.
If I understand your question corretly, you are not just serving 'pure' XML, but SpreadsheetML that is interpreted by Excel just as an ordinary Excel-file in binary format. So your users already have a very nice solution. How do are you creating those files? I use an XSLT to transform my XML-data to SpreadsheetML that is just a specific XML-format. In that way I can do anything that is possible in Excel (formattings, formulas etc.). It yould be much more than just transforming XML to CSV.
Why do you want to change this? I can see that the resulting XML-Excel file usually is huge, is that the reason?
Now, since Excel 2007 format (xlsx) is basically a zip-archive of some XML-files describing the structure and the data of the file -- just rename the file extension name of any xlsx to zip and inspect after extracting -- you might be able to adapt your existing solution, i.e. instead of creating one SpreadsheetML-(XML)File create several and pack/zip them one the server. I assume your normal server installation should have the necessary tools.
BUT - this solution is difficult to maintain (as you might know wiht you current solution -- if I am at all right) and changes in the XSLT to add new functionality requires quite a bit of knowledge. So again I as well can recommend Aspose.Cells, even some knowledgeable users might be able to change simple formats.
HTH
Andreas
If you don't have office 2003 *or later) DLLs referenced to the project, I'm afraid you can't read that Office XML data in your program directly, unless of course you can manually parse the whole XML by studying its format.
You can use Open XML SDK to create or read xlsx files.
http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=5124

read .xlsx without Excel and OLEDB

Is there any chance to read .xlsx files in C# without having Excel installed on the client, and with no OLEDB connection available?
The application is a Winforms project written in VS2005 C# .NET Framework 2.0.
How about this one here:
EPPlus-Create advanced Excel 2007 spreadsheets on the server
EPPlus is a .net library that reads and writes Excel 2007 files using the Open Office Xml format (xlsx).
EPPlus supports ranges, cell styling, charts, pictures, shapes, named ranges, autofilters and a lot of other stuff.
I decided to use the the Excel Data Reader on CodePlex.
Koogra can read .xlsx files.
Have a look at excellibrary. For now it supports only xls, but xlsx support is planned for the future.
This question looks to be similar to this one no?
Have you checked NPOI ?
Best
We use NPOI successfully in our projects.
There might be some 3rd party components that can help you.
Here's one
Here's another
NPOI's latest version support both xsl and xslx. Download it from
NPOI 2.0
and use NPOI.XSSF.UserModel.XSSFWorkbook fro xlsx.

Reading and parsing Excel files in C#

What is the best way/library to read Excel 2003 and 2007 files using C#? I need to do some heavy parsing.
Do you need to parse the file, or deal with the contents?
For parsing the file, you'd better hope it's in Open Office XML format, because the previous binary version is not documented at all.
If you just need to deal with the contents, use the Office Interop libraries.
You can try SmartXLS for .Net,it support most features of excel(cell formatting,Charts,formulas,pivot tables etc),and can read/write both the excel97-2003 xls format and the excel2007 openxml format.
I would start by trying to use ADO.NET.
If that doesn't work, I used xlsio by Syncfusion.
If the data is in some kind of table format I'd suggest to try using OleDbConnection and treating the Excel sheet as another data connection. Otherwise Interop is ok if it's not on a server or anything like that.
You can use the MS Office interop assemblies (see here) to access Excel files from .NET applications.
There are a number of 3rd party tools you can use. I would avoid using the Interop libraries as they can be pretty slow. I have used Aspose.Cells before and it works pretty well. It does cost some money though.

how Read and write binary excel file without com library

I want to read and write excel file . it can do with oledb , there is a limitation
maximunm characters < 255
solution is mono data type , now create table become second sheet (when open excel it is shown as hidden.)
please give proper answer
There's twothree (Thanks Behrooz) ways of doing this, the first is using FileHelpers to create a ordinary CSV file which can be read by Excel. The other way is to use a common BIFF file format, see here on CodeProject on how to accomplish this. The third way is to use an ODBC connection to the Excel spreadsheet as shown here on Codeproject also. The fastest way of doing it IMHO is to work with the BIFF format. Also here on CodeProject is a fast Excel reader, similar to the DataReader class but for Excel only.
OpenOffice.org has extensive documentation on the binary format for the excel spreadsheets here, this is a PDF document which outlines the BIFF layout and structure.
Edit: Amended this as Behrooz pointed out a small grammer-typo....
Hope this helps,
Best regards,
TOm.
SpreadsheetGear for .NET will do it.
You can see live ASP.NET samples with C# and VB source here and download a free trial here if you want to try it yourself. The trial is fully functional for 30 days.
Disclaimer: I own SpreadsheetGear LLC

How can I programmatically create, read, write an excel without having office installed?

I'm confused as hell with all the bazillion ways to read/write/create excel files. VSTO, OLEDB, etc, but they all seem to have the requirement that office must be installed.
Here is my situation: I need to develop an app which will take an excel file as input, do some calculations and create a new excel file which will basically be a modification of the first excel file. All with the constraint that the machine that runs this may not have office installed. (Don't ask why...)
I need to support all excel formats. The only saving grace is that the formats spreadsheets themselves are really simple. Just a bunch of columns and values, nothing fancy. And unfortunately no CSV as the end user might not even know what a CSV file is.
write your excel in HTML table format:
<html>
<body>
<table>
<tr>
<td style="background-color:#acc3ff">Cell1</td>
<td style="font-weight:bold">Cell2</td>
</tr>
</table>
</body>
</html>
and give your file an xls extension. Excel will convert it automatically
Without Office installed you'll need something designed to understand the Excel binary file format (unless you only want to open Office 2007 .xlsx files).
The best I've found (and that I use) is SpreadsheetGear, which in addition to being .NET native, is much faster and more stable then the COM/OLE solutions (which I've used in the past)
read and write csv files instead. Excel reads them just fine and they're easier to use. If you need to work against .xls files then try having support for OpenOffice as well as Excel. OpenOffice can read and write excel files.
Did you consider way number bazillion and one: using the Open XML SDK? You can retain styles and tweak it to your liking. Anything you can do in an actual file is possible to achieve programatically. The SDK comes with a tool called Document Reflector that shows the underlying XML and even shows LINQ statements that can be used to generate them. That is key to playing around with it, seeing how the changes are made, then recreating that in code.
The only caveat is this will work for the new XML based formats (*.xlsx) not the older versions. There's a slight learning curve but more material is making its way on blogs and other sites.
If cost is not an issue, I'd suggest looking in Aspose's Excel product. I use their Word product and I've been satisfied.
Aspose.Cells
Excel XLSX files "just" XML files - more precisely ZIP files containing several XML files. Just rename a Excel file Test.xslx to Test.zip and open it with your favourit ZIP program. XML schemas are, afaik, standardized and availiable. But I think it might not be that easy to manipulate them only using primitive XML processiing tools and frameworks.
Excel files are in a proprietary format so (afaik) you're not going to be able to do this without having the office interop available. Some third party tools exist (which presumably licence the format from MS?) but I've not used them myself to comment on their usefulness.
I assume that you can't control the base file format, i.e. simple CSV or XML formats aren't going to be possible?
I used to use a very nice library called CarlosAg, which uses Excel XML format. It was great (and Excel recognizes the format), and also incredibly fast. Check it out here.
Oh, as a side note, we used to use this for the very same reason you need it. The servers that generated these files were not able to have Excel installed.
If you cannot work with CSV files as per #RHicke's suggestion, and assuming you are working on a web app, since a desktop app would be guaranteed to have XL installed as per requirements.
I'd say, create your processing app as a webservice, and build an XL addin which will interact with your webservice directly from XL.
For XLSX files, look at using http://www.codeplex.com/ExcelPackage. Otherwise, some paid 3rd party solutions are out there, like the one David suggested.
I can understand the requirement of not having office installed on a server machine.
There are many libraries like aspose being available, some of them requiring license though.
If you are targeting MS Excel formats, then a native, Interoperability library, ACE OLEDB data provider, from Microsoft is available which you can install on a machine and start reading, writing programmatically. You need to define a connection string and commands as per you needs. (Ref: This article #yoursandmyideas)talks about using this library along with setup and troubleshooting information.

Categories

Resources