I'd like to transform my XMLDocument containing what you'd call simple xml content into an xls file, possibly using XSLT (judging from what I've found so far) to transform the data, and I'd like the save the created file as an xls file to be opened with Excel whilst not being able to use Excel in the process of creating this file (thus being unable to use MS.Office.Interop.Excel from what I've heard). How exactly would I do this and which classes would I utilize to create this document?
Any help on this one would be greatly appreciated!
Thanks,
Dennis
Probably your best bet is NPOI, a .NET port of the Apache POI library.
You can't use XSLT to create a XLS file, because XLS is a binary format.
If you are talking about ExcelML, this can be done. If you want to do it by hand, I think the best way to start is the following:
Create an ExcelML file using Excel that looks like what you need. Open this file in a text editor and analyse it. Additionally, you should download the reference of the format (Open Help -> OfficeXMLSDK.chm).
There are 3 wasy to convert XML to Excel XLS.
- If the XLS file layout is simple, just transform your XML to an HTML table, and load in Excel (either from a disk file, or HTTP response). This works for many cases, however beware that column / row spanning really confuses Excel.
- If you have a complex layout, with lots of formatting / worksheets, jump into the OfficeXMLSDK, it's pretty hairy with tons of namespaces
- If you have Excel on the server, create a template document in Excel, and use the Excel.Interop
Related
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.
I have an excel spreadsheet which has one worksheet. The work sheet has 50 columns and 1000+ rows. And I want to transform the data inside the excel spreadsheet into another custom format.
Is it possible to use xml+xslt to transform the data inside the excel worksheet into another format - as I've recently read that excel data is xml under the hood?
My programming language of choice is C# (incase that is required)
Thank you
in theory yes but I think this could be rather complex...
Another approach is to use OpenXML SDK from MS - see http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=5124
For some starting points
http://msdn.microsoft.com/en-us/library/bb456488.aspx
http://www.microsoft.com/download/en/details.aspx?id=17985
http://openxmldeveloper.org/blog/b/openxmldeveloper/archive/2009/06/02/4730.aspx
http://www.codeproject.com/KB/office/ExcelOpenXMLSDK.aspx
IF you need more (like rendering to high-quality PDF etc.) then there are several 3rd-party libraries available (like Flexcel, Aspose.Cells, SpreadsheetGear...).
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
I am obtaining data from a database that is returned in an XML string. What is the best way to then store this in an Excel file? Is there an XML - Excel tool, or is there an interim step?
Thanks.
The easiest way is probably just to loop through the XML-data either with XMLDocument or XDocument (linq) and write to a csv-file. The advantage with at csv file is that its readable with any text editor or other spreadsheet software.
You can read the data using the XMLDocument and then insert the data in the excel using Microsoft.Excel namespace.
Providing you're talking about Excel 2007 or newer, the format is XML-based. Check out any resources on OpenXML such as http://openxmldeveloper.org/ for details, or there's a video tutorial here that shows it http://www.asp.net/linq/videos/how-do-i-create-excel-spreadsheets-using-linq-to-xml . There's even things like http://code.google.com/p/linqtoexcel/ and an SDK here http://www.microsoft.com/downloads/en/details.aspx?FamilyId=C6E744E5-36E9-45F5-8D8C-331DF206E0D0&displaylang=en .
I want to create XML file from my Excel file through .NET (c#). My data is in Excel and it will be added in XML file.
Thanks.
Manoj
There is good article in CodeProject about it. Generally the answer is, that Excel can be used as Data provider. Later, when you get data out, you can use XMLDom to generate XML file