I want to copy tabular data to Excel from my app. The most simple way I found so far was using HTML as the intermediary format. After reading this question, I could preserve the formatting of my data. Is there a way to keep the width of the columns, too? I tried to set the style in various ways:
<td style="width:100;">...</td>
<td style="width:100px;">...</td>
<td style="width:100pt;">...</td>
but to no avail. Any ideas?
For bonus points, is there a place where I can find a description of Excel's HTML "format"?
[EDIT] Update: I've written a small tool to dump the transfer type "XML Stylesheet". This is a self contained XML document. It also contains column widths. But a quick test shows that Excel ignores the column widths completely, even when I cut&paste between two tables :( So unless someone can tell me an option to change this behavior, I guess it's simply not possible to format the columns while pasting.
[EDIT2] I've found a way. After pasting, you get a little icon in the lower right corner which looks like the paste button in the toolbar. Here, you can select some options. One is "Keep width of source table".
I recommend the XML Spreadsheet format (the old 2002/2003 one--simpler to generate) over Excel's ability to import HTML.
I've done both and written libraries to export both directly from .NET, and the XML format is definitely less likely to make you lose sleep.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With