telosse

WORK - copas xls from datagrid csharp

Feb 17th, 2016
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. private void copyAlltoClipboard()
  2. {
  3. dataGridView1.SelectAll();
  4. DataObject dataObj = dataGridView1.GetClipboardContent();
  5. if (dataObj != null)
  6. Clipboard.SetDataObject(dataObj);
  7. }
  8. private void button3_Click_1(object sender, EventArgs e)
  9. {
  10. copyAlltoClipboard();
  11. Microsoft.Office.Interop.Excel.Application xlexcel;
  12. Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
  13. Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;
  14. object misValue = System.Reflection.Missing.Value;
  15. xlexcel = new Excel.Application();
  16. xlexcel.Visible = true;
  17. xlWorkBook = xlexcel.Workbooks.Add(misValue);
  18. xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
  19. Excel.Range CR = (Excel.Range)xlWorkSheet.Cells[1, 1];
  20. CR.Select();
  21. xlWorkSheet.PasteSpecial(CR, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true);
  22. }
Advertisement
Add Comment
Please, Sign In to add comment