功能 - 数据 - UI:将数据网格导出到CSV文件

powershell
阅读 40 收藏 0 点赞 0 评论 0

export-dgv2csv.ps1
function export-DGV2CSV ([Windows.Forms.DataGridView] $grid, [String] $File)
<#
  .SYNOPSIS
  Export basic datagrid to CSV file

  .PARAMETER grid
  Datagrid object
  .PARAMETER file
  Path to CSV file
#>
{
  if ($grid.RowCount -eq 0) { return } # nothing to do
  
  $row = New-Object Windows.Forms.DataGridViewRow
  $sw  = new-object System.IO.StreamWriter($File)
        
  #Write header line
  $sw.WriteLine( ($grid.Columns | % { $_.HeaderText } ) -join ',' )

  #Export contents
  $grid.Rows | % {
    $sw.WriteLine(
      ($_.Cells | % { $_.Value }) -join ','
      )
    }
  $sw.Close()
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号