c#:将excel工作簿复制到其他工作簿
我已经编写了将工作表副本复制到新excel文件的代码。下面是我的C#代码,问题是缺少一些命名单元格,我在Excel-2010中对此进行了检查 C#代码: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 '
如果需要复制命名的单元格,可以使用以下代码示例
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