2

I'd like to programmatically copy tabular data (both formatting and formulas) to the clipboard from an HTA (HTML Application), to paste into Excel. Excel supports a text format called SYLK for accomplishing this task, but I've run into a snag with over-validation in window.clipboardData.setData(format, data) where format is restricted to either "Text" or "URL", giving the error "Unexpected call to method or property access" if format is set to anything else, and Excel only recognizes SYLK text if format is set to "SYLK", otherwise it pastes as normal text.

I'm wondering if there's another way to set clipboard data from an HTA, such as through a COM control that comes preinstalled with either Windows or Office, that would let me copy SYLK data to the clipboard.

I know I could write a custom COM control and install it on each client, but at that point I might be better off just writing to a file and opening the file instead of using the clipboard.

David
  • 2,164
  • 13
  • 11
  • 1
    Is there any reason why you don't want to just use COM to create an Excel workbook and fill it directly? – Todd Feb 23 '11 at 17:23
  • Previously, it was generating tab delimited text to copy to the clipboard, and the text was generated server-side, with only a few lines of code on the client side to call setClipboardData on it. Automating Excel would add a lot more complexity on the client side, plus outputting the table and formatting info as script from the server side instead of a single string, but I guess it's probably not worse than generating SYLK on the server side and using client side hacks. – David Feb 23 '11 at 21:53
  • Aha, you did say client before but didn't mention a server so I thought this was all being done in one HTA. Is this an XHR arrangement? Excel automation still seems like a reasonable approach. The server could still just return a delimited string which the client would split up for proper stuffing into the worksheet. Given that I don't know much about your setup. How are you getting the HTA to each client? You may also be able to provide a WSC component the same way, or simply another VBScript module that the HTA loads from a script tag. – Todd Feb 25 '11 at 04:09

0 Answers0