开发者

c# save datagridview to XML for later excel viewing

开发者 https://www.devze.com 2023-01-24 11:38 出处:网络
i would like to save the contents of a datagridview to an xml file i will then want to open the xml file using excel

i would like to save the contents of a datagridview to an xml file

i will then want to open the xml file using excel

perhaps i should be exporting it to CSV file instead of XML?

i dont care what method to use, i just need the simplest and fastest

i guess the process should be

  1. c开发者_JS百科opy the datagridview data into a datatable
  2. save the datatable to a csv/xml

how would i accomplish this?

please note that i do not want to save the datasource of the datagridview (because i make changes to datagridview in runtime), i want to make sure to iterate through the datagridview and save the data that way


  1. Set the DataGridView's Datasource as the datatable: DataGridView.DataSource

  2. Create a Datastream and export the Datatable using the built in Serialization: DataTable.WriteXML(stream)

I understand that you want the Datagridview table to export to a Datatable which then exports to a XML file. Consider that you can bind the Datatable to the Datagridview before Displaying your form. The Datatable will update along with your DataGridView as it acts a bindable source.

moreto follow

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号