我有這個簡單的 VB.NET 代碼來從一個作業表復制范圍并粘貼到另一個作業表,只粘貼值:
Dim xlApp As Microsoft.Office.Interop.Excel.Application = New Microsoft.Office.Interop.Excel.Application
Dim xlWorkbook As Microsoft.Office.Interop.Excel.Workbook = xlApp.Workbooks.Open(in_Path)
'Define the Excel Source Sheet
Dim xlWorkSheetSource As Microsoft.Office.Interop.Excel.WorkSheet
xlWorkSheetSource = CType(xlWorkbook.Sheets(in_WorkSheetSource),Microsoft.Office.Interop.Excel.WorkSheet)
'Activate the Source Worksheet
xlWorkSheetSource.Activate()
Dim xlRange1 As Microsoft.Office.Interop.Excel.Range
xlRange1 = xlWorkSheetSource.Range("A13:O20")
xlRange1.Copy()
'Define the Excel Destination Sheet
Dim xlWorkSheetDestination As Microsoft.Office.Interop.Excel.WorkSheet
xlWorkSheetDestination = CType(xlWorkbook.Sheets(in_WorkSheetDestination),Microsoft.Office.Interop.Excel.WorkSheet)
'Activate the Source Worksheet
xlWorkSheetDestination.Activate()
xlWorkSheetDestination.Range("A1").PasteSpecial(xlPasteValues)
xlWorkbook.Save
xlWorkbook.Close
但我有這個錯誤:
No compiled code to run
error BC30451: 'xlPasteValues' is not declared. It may be inaccessible due to its protection level. At line 21
顯然,xlPasteValues不是要宣告的 var。
有沒有其他方法可以完成它?
我正在使用命名空間:
Microsoft.Office.Interop.Excel
uj5u.com熱心網友回復:
在 VB.Net(與 VBA 不同)中,您必須限定列舉值。所以改變這一行:
xlWorkSheetDestination.Range("A1").PasteSpecial(xlPasteValues)
對此:
xlWorkSheetDestination.Range("A1").PasteSpecial(xlPasteType.xlPasteValues)
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/367241.html
上一篇:Python通過部分匹配使用pandas過濾Excel資料
下一篇:Excel讀取單元格為空?
