Copy the contents of a DataGridView in to excel

元气小坏坏 提交于 2019-12-25 12:56:08

问题


I found some examples of how to create a excel file from a data grid view, however those just create the file. What I would like to do is have excel open, with a unsaved worksheet, and have the content of the data grid view (including header names) pasted in to the worksheet after pressing a "Export to Excel" button.

Basically I want to automate what happens when you do a copy and paste from a data grid view in to excel. Any suggestions on how to do this?


回答1:


Take a look at this tutorial, http://www.gemboxsoftware.com/LA/Import-Export-DataGrid-XLS-XLSX-CSV-HTML-.NET.htm. It shows how to generate an excel document from the datagrid export. You can then open the document which will open it in excel. I'm not entirely sure of a way to paste it into the currently open excel document but this should get you close.



来源:https://stackoverflow.com/questions/3561368/copy-the-contents-of-a-datagridview-in-to-excel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!