views:

22

answers:

0

I am generating OpenXml using the DocumentFormat.OpenXML library from Microsoft. I am tring to figure out how to get this document into my clipboard so that I can paste my data into Excel (as if it were copied from Excel). I am able to see OpenXml formated data coming out of Excel, when I copy from within Excel. I need to do the reverse, copy out of a WPF application, and paste into Excel using advanced Excel formatting (hence needing OpenXML).

Here is a snippet of what I have so far:

MemoryStream documentStream = new MemoryStream();
  SpreadsheetDocument spreadsheet = SpreadsheetDocument.Create(documentStream, SpreadsheetDocumentType.Workbook, true);

  // create the workbook
  spreadsheet.AddWorkbookPart();
  Stream workbookStream = spreadsheet.WorkbookPart.GetStream();
  spreadsheet.WorkbookPart.Workbook = new Workbook();     // create the worksheet
  spreadsheet.WorkbookPart.AddNewPart<WorksheetPart>();
  spreadsheet.WorkbookPart.WorksheetParts.First().Worksheet = new Worksheet();

  ...

  const string SPREADSHEET_FORMAT = "XML Spreadsheet";
  Clipboard.SetData(SPREADSHEET_FORMAT, clipboardData);