Include formatting information in windows clipboard copy buffer for pasting into Excel Include formatting information in windows clipboard copy buffer for pasting into Excel windows windows

Include formatting information in windows clipboard copy buffer for pasting into Excel


Yes, it's possible (obviously, you can copy formatted Excel data from one running instance of Excel to another via the clipboard, so it must be possible!)

Remember that the Windows clipboard can hold things in more than one format at the same time. The format you want for Excel formatted grid stuff is called BIFF, that is, The Binary Interchange File Format. It's the same format as Excel actually stores files in. A reasonable source of BIFF documentation is available from Open Office.

Once you figure out the basics of BIFF, you'll find that the easiest way to generate the BIFF you want is to copy a model of the cells you want from an Excel spreadsheet and examine what's in the clipboard.


The solution is to write a small program that dumps the contents of the clipboard, including all the different formats. Then, copy some Excel into the clipboard, dump the clipboard, and you will see revealed how to format the data.

Here is the output from an app that I wrote, so I can paste a table to rich text apps:

xC0FC:Version:0.9StartHTML:00000120EndHTML:00000686StartFragment:00000154EndFragment:00000650SourceURL:about:blank<html><body><!--StartFragment--><table style="max-width: 50%; background: rgb(255, 255, 255);">  <tbody>    <tr>      <td valign="center" style="background-color: #cccccc;" width="180"><b><font size="-1">Enter in "Name"<br>          </font></b></td>      <td valign="center">XXX YYY</td>    </tr>    <tr>      <td valign="center" bgcolor="#cccccc" width="300"><b><font size="-1">Enter in "Registration Key"<br>          </font></b></td>      <td valign="center">123456</td>    </tr>  </tbody></table><!--EndFragment--></body></html>

The Start/End are byte offsets. The "C0FC" text type code seems to vary from day to day according to a pattern I haven't figured out. You'll have to experiment and use trial & error.