Click here to Skip to main content
15,891,976 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
How to import xml information to excel file using asp.net and C#
Posted
Updated 28-Jun-17 9:31am
v2

1 solution

There are a variety of ways to do this. That said there are a few key questions to shape your choices. First, can your users learn to import the xml into Excel? Excel has been able to import xml for over a decade. The key to doing this successfully is to avoid attributes in xml. Just name your xml tags and place data between opening and closing tags. This is the same format you get when doing datatable/dataset.toxml().

I had one project years ago where we took an httpcontext object, set mime type to excel (look up in google) and fire out as data stream. Excel is called by machine and loads data automatically.

The other, most difficult option is to include some interop or open source excel libraries, and do as you would expect: create a file, create a sheet, load the sheet, etc. That can be done easier by having a copy of the file on the server, copying the file, loading it, then streaming the file locally.

Also, be weary that some firewalls are not excel file friendly, especially when sent as attachment to email.

One last thing, don't use a website project to move data from hard drive to excel file. If you feel you must use a program instead of data import wizard, use a WinForms or WPF or command line program. You could also look into Powershell or VBScript/Windows Scrip Host (WSH). It is not wise to upload data to website, download back to file system, and put in Excel. Just use a local program that does not need to up or download to get Excel file loaded on same hard drive or attached drive.

One other option is to look into Visual Basic for Applications (VBA) this is a Visual Basic language used to manipulate MS Office programs, ESPECIALLY Excel. These are what are called "Macros". Search google for more info on this option. Note that this stores your vb in the actual excel file, so you will have to make copies of the excel file to have access to it each time you do this method.

Happy Coding!
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900