c# 将datagridview保存到XML以便以后excel查看
我想将 datagridview 的内容保存到 xml 文件,
然后我想使用 excel 打开 xml 文件
,也许我应该将其导出到 CSV 文件而不是 XML?
我不在乎使用什么方法,我只需要最简单和最快的方法,
我想这个过程应该是将
- datagridview 数据复制到数据表中,
- 将数据表保存到 csv/xml
我将如何实现这一点?
请注意,我不想保存 datagridview 的数据源(因为我在运行时对 datagridview 进行更改),我想确保迭代 datagridview 并以这种方式保存数据
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
- copy the datagridview data into a datatable
- 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将DataGridView的数据源设置为数据表: DataGridView.DataSource
使用内置序列化创建数据流并导出数据表:DataTable.WriteXML(stream)
我了解您希望将 Datagridview 表导出到 Datatable,然后再导出到 XML 文件。考虑到您可以在显示表单之前将数据表绑定到 Datagridview。数据表将与您的 DataGridView 一起更新,因为它充当可绑定源。
更多关注
Set the DataGridView's Datasource as the datatable: DataGridView.DataSource
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