将数据从datagridview提取到CSV文件,并提示用户保存 [英] Extract data from datagridview to CSV file and prompt the user to save

查看:67
本文介绍了将数据从datagridview提取到CSV文件,并提示用户保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi Gurus,

我在Google上进行了大量搜索,但是找不到有关如何将数据从datagridview下载到CSV并要求用户将文件保存在本地驱动器上的相关简短信息.

I have searched a lot on google but couldn't find the relevant and short info on how to download the data from datagridview to CSV and ask the user to save the file on local drive.

你们可以在这方面指导我吗?我也可以下载PDF格式的数据吗?如果您也可以指导我,那将是很好的.

Can you guys please guide me on this ? Can I also download the data in PDF format ? If you could guide me on that also then it would be great.

对此表示赞赏.

谢谢

Srini

推荐答案

尝试一下:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim sb As New System.Text.StringBuilder
    For y As Integer = 0 To DataGridView1.Rows.Count - 1
        sb.AppendLine(String.Join(",", DataGridView1.Rows(y).Cells.Cast(Of DataGridViewTextBoxCell).Select(Function(c) If(c.Value IsNot Nothing, c.Value.ToString, ""))))
    Next
    IO.File.WriteAllText("test.csv", sb.ToString)
    Process.Start("test.csv")
End Sub



这篇关于将数据从datagridview提取到CSV文件,并提示用户保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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