Creating Excel File - c#

Well, I didn't find any libs to create Excel file in Windows Phone 7 and the default libs for Excel are not working because they weren't compile for it.
Does any of you guys know how to do this?

Excel is able to open many different kinds of files beyond the .xls or .xlsx. Most common is CSV; it's dead simple but not very capable, and I would avoid it for all but the simplest applications.
A format I've used successfully is the Symbolic Link (SYLK) format. The .slk files open directly in Excel, and you can include cell formatting and formulas. It's easy to save out a file from Excel itself and use it as a template for creating your own files.

You're going to struggle to find a library to do this simply because WP (as of 7.1) doesn't include the System.IO.Packaging namespace, which most libraries will depend on to read/write docx/xlsx/etc files.

Related

Creating excel - improve performance

Good afternoon,
we have a small problem with performance of generating excel.
First, we was creating excel cell by cell - it is ... let's say unacceptable.
Second, we started insert into excel with one command - range creating and it is much faster, but still not perfect so we are searching next solutions.
Because we can load XML file from database, we tried used XSLT and from these two files create xls file. It is nice, but after open this file there is error message shown (it is because of problem or bug in registry). User has to accept this message and after excel is opened. We want to eliminate this error message. However we don't know how.
We was thinking about convert this xls file into xlsx but we are unable to do it becouse we can't install office on server (we cannot use Interop) and OpenXML libraries don't know work with normal xls file. So my question is:
Is possible to generate from XML file with using of some XLST (or something) the xlsx file?
Eventually can what files do we need to create and zip together if we want create xlsx file?
Thank you for information
You mention not being able to use the OpenXML libraries because they don't work with .xls files, but you also say "creating cell by cell", which implies that you are generating the file from scratch. Where is the xls file coming from? You mention excel opening, but then say you can't install it on the server. So, it appears to me that a user is uploading an xls file to your server, and then you are doing something with it and giving it back to them? If that is the case and you must be able to read/write an xls file without installing office, then I would suggest using ExcelLibrary, as mentioned in this post
Indeed, creating an xlsx file is much magnitudes faster with the open xml sdk.

How to export a table into the open office spreadsheet (.ods file) through C#.net?

I want to create a .ods file throught C#.net and also want to export tables,images into it.
Is there any solution for that?
All OpenDocument's is just a couple of XML-files, that are packed into zip-archive and named with different file extensions. It's hard, but possible to write this documents with just only standard XMLWriter/ZipFile classes. Format specifications are open to anyone.
But there are many packages that simplifies and abstracts this process. Take look on Aspose.Words for .NET and AODL NuGet package's at least.

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

Create Excel files from C# without office [duplicate]

This question already has answers here:
How do I create an Excel (.XLS and .XLSX) file in C# without installing Microsoft Office?
(47 answers)
Closed 4 years ago.
I am writing a program that generates excel reports, currently using the Microsoft.Interop.Excel reference. My dev computer has Excel on it, but the end user may or may not have Office installed. Will this tool fail if Office isn't installed on the end users computer, or is this interop service separate from the actual application?
If you're interested in making .xlsx (Office 2007 and beyond) files, you're in luck. Office 2007+ uses OpenXML which for lack of a more apt description is XML files inside of a zip named .xlsx
Take an excel file (2007+) and rename it to .zip, you can open it up and take a look. If you're using .NET 3.5 you can use the System.IO.Packaging library to manipulate the relationships & zipfile itself, and linq to xml to play with the xml (or just DOM if you're more comfortable).
Otherwise id reccomend DotNetZip, a powerfull library for manipulation of zipfiles.
OpenXMLDeveloper has lots of resources about OpenXML and you can find more there.
If you want .xls (2003 and below) you're going to have to look into 3rd party libraries or perhaps learn the file format yourself to achieve this without excel installed.
Unless you have Excel installed on the Server/PC or use an external tool (which is possible without using Excel Interop, see Create Excel (.XLS and .XLSX) file from C#), it will fail. Using the interop requires Excel to be installed.
Try EPPlus if you use Excel 2007. Supports ranges, cellstyling, charts, shapes, pictures and a lot of other stuff
There are a handful of options:
NPOI - Which is free and open
source.
Aspose - Is definitely
not free but robust.
Spreadsheet
ML - Basically XML for creating spreadsheets.
Using the Interop will require that the Excel be installed on the machine from which it is running. In a server side solution, this will be awful. Instead, you should use a tool like the ones above that lets you build an Excel file without Excel being installed.
If the user does not have Excel but has a tool that will read Excel (like Open Office), then obviously they will be able to open it. Microsoft has a free Excel viewer available for those users that do not have Excel.
An interop calls something else, it's an interoperability assembly, so you're inter-operating with something...in this case Excel, the actual installed Excel.
In this case yes, it will fail to run because it depends on excel, you're just calling excel functions. If they don't have it installed...out of luck.
There are methods to generate without Excel, provided the 2007 file format is ok, here's a few:
http://excelpackage.codeplex.com/
http://simpleooxml.codeplex.com/
as I said though, this is the 2007 format, normally if anything, that's the deal-breaker.
Use OleDB, you can create, read, and edit excel files pretty easily. Read the MSDN docs for more info:
http://msdn.microsoft.com/en-us/library/aa288452(VS.71).aspx
I've used OleDB to read from excel files and I know you can create them, but I haven't done it firsthand.
You could use the ExcelStorage Class of the FileHelpers library, it's very easy and simple... you will need Excel 2000 or later installed on the machine.
The FileHelpers is a free and easy to
use .NET library to import/export
data from fixed length or delimited
records in files, strings or streams.

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