Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
vb.net通过数组将datagrid值导出到excel_Vb.net - Fatal编程技术网

vb.net通过数组将datagrid值导出到excel

vb.net通过数组将datagrid值导出到excel,vb.net,Vb.net,我正在尝试使用数组将datagrid值导出到excel。。 我在以下行中收到一个错误“ComException未处理”: xlWorkSheet.Range("A1").Resize(DataGridView1.Rows.Count, DataGridView1.Columns.Count).Value = myArray 有关更多信息,请参阅。试试下面的方法 Dim myRange as Excel.Range = xlWorkSheet.Range("A1", Reflectio

我正在尝试使用数组将datagrid值导出到excel。。 我在以下行中收到一个错误“
ComException未处理”

 xlWorkSheet.Range("A1").Resize(DataGridView1.Rows.Count, DataGridView1.Columns.Count).Value = myArray
有关更多信息,请参阅。试试下面的方法

    Dim myRange as Excel.Range = xlWorkSheet.Range("A1", Reflection.Missing.Value)
    myRange.Resize(DataGridView1.Rows.Count, DataGridView1.Columns.Count)
    myRange.Value = myArray

这是假设您的
myArray
是一个二维数组。

谢谢。。。我仍然得到一个错误选项,严格禁止将“Microsoft.Office.Interop.Excel.Range”隐式转换为“Excel.Range”。@user2444712然后将我回答中的
Excel.Range
更改为
Microsoft.Office.Interop.Excel.Range
-您可以导入
Microsoft.Office.Tools
命名空间。还要确保Excel应用程序对象和工作表“
xlWorksheet
”也来自
Microsoft.Office.Interop.Excel
namespace仍然存在错误“必须将属性访问权限分配给属性或使用其值。”并带有行“myRange.Resize”(DataGridView1.Rows.Count、DataGridView1.Columns.Count)我有导入程序micorsoft.office.interop.excel,我已将Dim xlApp声明为Microsoft.office.interop.excel.Application Dim xlWorkBook声明为Microsoft.office.interop.excel.工作簿Dim XLWORKER声明为Microsoft.office.interop.excel.Workshe对象为Dim misValue=System.Reflection.Missing.Value