Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/256.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
c#:将excel工作簿复制到其他工作簿_C#_Excel_Excel 2010 - Fatal编程技术网

c#:将excel工作簿复制到其他工作簿

c#:将excel工作簿复制到其他工作簿,c#,excel,excel-2010,C#,Excel,Excel 2010,我已经编写了将工作表副本复制到新excel文件的代码。下面是我的C#代码,问题是缺少一些命名单元格,我在Excel-2010中对此进行了检查 C#代码: 如果需要复制命名的单元格,可以使用以下代码示例 Sub Copy_All_Defined_Names() ' Loop through all of the defined names in the active ' workbook. For Each x In ActiveWorkbook.Names '

我已经编写了将工作表副本复制到新excel文件的代码。下面是我的C#代码,问题是缺少一些命名单元格,我在Excel-2010中对此进行了检查

C#代码:


如果需要复制命名的单元格,可以使用以下代码示例

Sub Copy_All_Defined_Names()
   ' Loop through all of the defined names in the active
   ' workbook.
     For Each x In ActiveWorkbook.Names
      ' Add each defined name from the active workbook to
      ' the target workbook ("Book2.xls" or "Book2.xlsm").
      ' "x.value" refers to the cell references the
      ' defined name points to.
      Workbooks("Book2.xls").Names.Add Name:=x.Name, _
         RefersTo:=x.Value
   Next x
End Sub

缺少的单元格有什么独特之处?我们在工作表中命名了单元格,与默认的A1、A2 s不同。单元格名称类似于“Doc.A.1”等。
Sub Copy_All_Defined_Names()
   ' Loop through all of the defined names in the active
   ' workbook.
     For Each x In ActiveWorkbook.Names
      ' Add each defined name from the active workbook to
      ' the target workbook ("Book2.xls" or "Book2.xlsm").
      ' "x.value" refers to the cell references the
      ' defined name points to.
      Workbooks("Book2.xls").Names.Add Name:=x.Name, _
         RefersTo:=x.Value
   Next x
End Sub