views:

468

answers:

3

Hey guys, i dont have a clear definition of what my client wants but i figured i could get a dialogue going.

so my client wants to take some html from a page and convert it to and xls form. all the data and content is from their own website/portal and they just need the reports converted to xls for accounting or something.

Oh yeah, id like to keep this in .NET C# please...

has anybody done this? What options are there?

Thanks guys!

A: 

You can highlight any table and copy/paste it into Excel and Excel should handle the conversion nicely.

You can also provide .CSV versions of your reports.

ceejayoz
+1  A: 

You can grab that external page by using XHR, parse it's HTML and to return your data with content-type = "application/vnd.ms-excel"

Rubens Farias
can you explain, i get the content-type, but what would be the process to take the data coming from the DB that is populated the datagrid, and create a download that has that corresponding data in an xls file.
sia
Sorry, I thought that data are from a remote webserver; since you get database access, you just need to render a datagrid into a page and download it with appropriate content-type. Take a look here: http://www.c-sharpcorner.com/UploadFile/DipalChoksi/ExportASPNetDataGridToExcel11222005041447AM/ExportASPNetDataGridToExcel.aspx
Rubens Farias
hahaha thanks for the link, i actually was looking at before i read your comment and saved the link....
sia
A: 

The easiest approach is to to just output a html table, and set the mime-type to application/vnd.ms-excel as @Rubens Farias said. If you have access to the existing application it's easy to extend, if not you must grab the html and parse it.

Excel can parse html tables without problems, even with formatting:

<html>
   <body>
      <table border="1">
         <tr>
            <td style="background-color: red">Content in cell</td>
            <td>Cell 2</td>
         </tr>
      </table>
   </body>
</html>
Mikael Svenson