如何将datagridview内容保存到文件中 [英] How to save the datagridview content into a file

查看:117
本文介绍了如何将datagridview内容保存到文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好...我想知道是否可以将datagridview的内容保存到文件中...也想知道如何在关闭文件后将该文件加载到我的datagridview中...谢谢...可能是Vb.NET或C#

hello... i want to know if it is possible to save the content of a datagridview into a file... also want to know how to load that file to my datagridview after closing it... thanks... it could be Vb.NET or C#

推荐答案

一些说明如何导出到excel(从datagridview)的文章-

在.NET 2.0中将DataGridView导出到Excel(C#代码) [ http://stam.blogs.com/8bits/2010/09/c- datagridview-to-excel.html [ ^ ]
Some articles that explain exporting to excel (from a datagridview) -

Exporting a DataGridView to Excel in .NET 2.0 (C# code)[^]
http://stam.blogs.com/8bits/2010/09/c-datagridview-to-excel.html[^]


我自己是通过以下简单方式完成的:
I did this myself on the simple way:
dim rows as integer = 'set rowcount
dim col as integer  = 'set column count     
dim regel1 as string = Nothing
For i = 0 To rows
   For j = 0 To columns
       regel1 += DataGridView1.Rows(i).Cells(j).Value + vbCrLf
   Next
Next
Dim objWriter20 As New System.IO.StreamWriter("somefile.txt")
objWriter20.WriteLine(regel1)
objWriter20.Close()



并再次阅读:



and read again:

Infile = IO.File.OpenText("somefile.txt")
For i = 0 To rows
    For j = 0 To columns
      DataGridView1.Rows(i).Cells(j).Value = Infile.ReadLine()
    Next
Next
Infile.Close()


我到处都是
I got all over here

Let me know for further information.


这篇关于如何将datagridview内容保存到文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆