Alex Rivera | Logout

Programmatically creating Excel 2007 Sheets

Asked 2008-09-30T14:21:26.303
14

I'm trying to create Excel 2007 Documents programmatically. Now, there are two ways I've found:

Currently, I use ExcelPackage, which has some really serious drawbacks and issues. As I do not need to create overly complex Excel sheets (the most "complicated" thing is that I explicitely need to set a cell type to numeric or text), I 'm looking towards Option 1 next, but I just wonder if there are any other good and supported ways to generate Excel 2007 Sheets? Bonus Points if they can be created without having to save them to the harddrive, i.e. generate and directly output them into a stream.

.net 3.0 is the target here, no 3.5 goodness :(

Edit: Thanks so far. The XML SDK is indeed 3.5 only, but Russian Roulet... erm... COM Interop is also something I want to avoid whenever possible, especially since Excel 2007 has a somewhat complicated but still rather easy to create document format. I'll have a look at the various links and hints posted.

Edit
Report

1 Answer

2

I'm just generating HTML table, which can be opened by Excel:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd">

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Wnioski</title>
<style type="text/css">
<!--
br { mso-data-placement: same-cell; }
td { mso-number-format: \@; mso-displayed-decimal-separator: "."; }
-->
</style>

<table>
<tr style="height:15.0pt">
<td style="mso-number-format: general">474</td>
<td>474</td>

<tr>
<td>data2</td>
<td>data3</td>

<tr>
<td style="mso-number-format: &quot;yyyy-mm-dd&quot;">2008-10-01</td>
<td style="mso-number-format: standard">0.00</td>

<tr>
<td style="mso-number-format: general">line1<br>line2<br>line3</td>
<td></td>

</table>

This works well also as a data source for serial letters in Word, works with OpenOffice calc etc. And it is dead simple to generate.

answered 2008-10-01T08:30:15.687

Your Answer