I have to make a simple WPF application that manages and displays some data in form of objects(strings and ints). It needs to be saved in excel format, so that it can me manually opened and viewed by any user with Excel. But because not every user necessarily has Excel it needs to be independent from it. I found very few solutions but none worked for me. This works but as far as I know it needs Excel installed to run.
I use EPPlus for this purpose. http://epplus.codeplex.com/
It does not require that you have excel installed and is easy to use.
You can't use Microsoft.Office.Interop.Excel without having Microsoft Office installed.
You can use external libraries that allow xls or xlsx modification without Excel installed:
http://code.google.com/p/excellibrary/
http://simpleooxml.codeplex.com/ (only xlsx)
Related
I want to read and write excel file with extensions: .xls and .xlsx (Generated from any office version i.e. Office 2003, Office 2016).
I have read and written Excel with office interop, it is working fine at local environment but once I hosted on Azure Cloud Service Worker Role, it is not working(Need office interop dependency).
Please suggest me best way to read and write excel with no dependencies in Azure environment?
You should use OpenXML or ClosedXML.
It's probably easiest to start with ClosedXML, which builds upon OpenXML, and makes a lot of tasks much simpler.
If ClosedXML does not work for older versions, you can try Excel Data Reader.
I haven't tried it myself, but a lot of people recommend it.
Not sure about the support for Office 2003 though. You'll have to check for that.
We have used FreeSpire. It works perfectly for .xlsx but has some limitations for .xls
Edit:
Our use case was to Password-Protect the excel file. So, we achieved this using the following code:
Workbook book = new Workbook();
book.LoadFromFile(#"E:\Work\Documents\Sample.xlsx");
//Protect Workbook
book.Protect("abc-123");
//Save
book.SaveToFile("Output.xlsx", ExcelVersion.Version2010);
You can download the dll here
I am writing an application where we need to update an existing Excel sheet through our system. I was able to do so on my local machine with OleDbConnection but when i deploy the application on server it gives me "operation must use an updateable query"
error on Windows server 2012.
I know its not recommended to install MS Office on Server and thats why its causing the issue. Any one has an idea whast the work around for this problem.
Do i have to give permission to my .net application so it can update the excel file or its something else?
Thanks in Advance.
I know its not recommended to install MS Office on Server
Last I checked, it is also a violation of the license terms (though that may have changed)
As you note, there are many reasons it is unwise to deploy Office to a server environment.
If you are using the newer (2007+) .xlsx file format exclusively, you can use the open source EPPlus library for most common Excel tasks. It is free, straightforward to use, and is designed to work on a server.
EPPlus is a .net library that reads and writes Excel 2007/2010 files using the Open Office Xml format (xlsx).
Do you know any external MS Excel library for C# (it should work without MS Office installed on machine) which has possibility to run macros?
It's possible to run it with "Microsoft.Office.Interop.Excel", but for that you need MS Office.
The scenario: I have MS Excel file template with macro. Adding part of the data programmatically to that template, running macro which was wrote to excel template, adding another part of data.
Thanks in advance!
NPOI is a great tool and is Open Source:
NPOI
I have a desktop application which has to read an excel file (either .xls or .xlsx).
When the application is installed in a Windows 7 pc with Office 2003 i cant read the excel file using Microsoft.ACE.OLEDB.12.0. I have the message that Microsoft.ACE.OLEDB.12.0 is not registered.
Using Microsoft.JET.OLEDB.4.0. doesnt help either.
So how can we read the excel file? I know one option is to build my application forcing it to compile to (x86) so it runs as a 32-bit application.
Ok, supposing i dont want to do so, is there any other option?
Thanks for any answers. Any comments are welcome!
You need the 64-bit JET/ACE driver installed:
http://www.microsoft.com/en-us/download/details.aspx?id=13255
Sounds like a job for Npoi. Stand alone library that can work with xls and xlsx files. No need to use those Jet libraries.
Ok, that will involve a bit of work, but you remove a dependency from something you can't control on user's machine.
Can I create an Excel sheet using the C# without having MS Office installed on the host machine?
If you are targetting Office 2007+ - you can take a look at the the Office Open XML. Your .xlsm is basically a compressed XML file and as long as you are not doing anything fancy - it should be easy to generate.
If however - you are targeting Office 2003 or earlier - the .xls is a binary format. You might need to look at abiword or star office to see if you can use any of their code to serialize you data to it.
I have achieved this using the EPPlus library.
In the past I've created a simple HTML table and saved as .xls and this has opened fine in Excel.