【问题标题】:Export from DataGridView从 DataGridView 导出
【发布时间】:2020-06-23 04:32:43
【问题描述】:

我需要在 PowerShell GUI 上创建一个按钮,以便在按下时保存 DataGridView 的内容。这需要打开一个文件对话框来选择目的地并给它一个文件名。

查看我已经尝试过的代码

$btnSave_Click={
    $saveFile = New-Object System.Windows.Forms.SaveFileDialog
    $saveFile.Filter = "Comma Delimited (*.csv) | *.csv "
    $saveFile.FileName
    if ($saveFile.ShowDialog() -eq 'OK')
    {
        $results.SelectAll()
        $results.ClipboardCopyMode = 'EnableAlwaysIncludeHeaderText'
        $results.GetClipboardContent().GetData('Text') | Out-File 
    $saveFile.FileName
    }
}

收到的错误是

ERROR: You cannot call a method on a null-valued expression.
ERROR: char:4
ERROR: +             $results.SelectAll()
ERROR: +             ~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR:     + CategoryInfo          : InvalidOperation: (:) [],     
RuntimeException
ERROR:     + FullyQualifiedErrorId : InvokeMethodOnNull
ERROR:
ERROR: The property 'ClipboardCopyMode' cannot be found on this object.  
Verify that the property exists and can be set.
ERROR: char:4
ERROR: +             $results.ClipboardCopyMode   
= 'EnableAlwaysIncludeHea ...
ERROR: +                
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR:     + CategoryInfo          : InvalidOperation: (:) [],   
RuntimeException
ERROR:     + FullyQualifiedErrorId : PropertyNotFound
ERROR:
ERROR: You cannot call a method on a null-valued expression.
ERROR: char:4
ERROR: +             $results.GetClipboardContent().GetData('Text') | 
Out ...
ERROR: +             
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR:     + CategoryInfo          : InvalidOperation: (:) [], 
RuntimeException
ERROR:     + FullyQualifiedErrorId : InvokeMethodOnNull
ERROR:

【问题讨论】:

  • 你没有保存$results所以变量不存在...
  • 首先你需要验证'$results'变量,错误表明它为NULL。

标签: powershell datagridview


【解决方案1】:

也许你的意思

$result = $DataGridViewdata.selectall()

【讨论】:

  • 如果您解释了您提供的代码如何回答问题,这将是一个更好的答案。
猜你喜欢
  • 2016-04-16
  • 1970-01-01
  • 2018-10-03
  • 2016-10-09
  • 1970-01-01
  • 1970-01-01
  • 2012-03-30
  • 1970-01-01
  • 2012-10-28
相关资源
最近更新 更多