Excel PasteSpecial函数粘贴为图像

时间:2013-08-02 11:31:22

标签: vb.net visual-studio-2010 excel vba

我正在尝试使用pastespecial方法将格式化的单元格从现有的Excel工作表复制到vb.net(2010)中的新工作表,但它将单元格值粘贴为图片而不是文本。 在这方面的任何帮助将受到高度赞赏:

    Public Sub set_header(ByVal r As Integer, ByVal c As Integer, ByVal dt1 As Date, ByVal dt2 As Date, ByVal sheetname As String)

    Dim wbCopy As Excel.Workbook
    Dim wsCopy As Excel.Worksheet
    Dim rngCopy As Excel.Range
    Dim wbPaste As Excel.Workbook
    Dim wsPaste As Excel.Worksheet
    Dim rngPaste As Excel.Range
    Dim xlsApp As Excel.Application
    xlsApp = New Excel.Application
    wbCopy = xlsApp.Workbooks.Open("C:\Windows\rta2.xlsx") 
    wsCopy = wbCopy.Worksheets(sheetname)
    rngCopy = wsCopy.Range("A7:O9")
    Dim addr As Object
    addr = ExcelSheet.Cells(r, c).Address(False, False)
    rngPaste = ExcelSheet.Range(addr) 
    rngCopy.Copy()
    rngPaste.PasteSpecial(Excel.XlPasteType.xlPasteAll, Excel.XlPasteSpecialOperation.xlPasteSpecialOperationNone,false,false)
    ExcelSheet.Cells(r + 2, c + 4) = "from " & dt1 & " to " & dt2
    Set wbCopy = Nothing
    Set wsCopy = Nothing
    Set rngCopy = Nothing
    Set wbPaste = Nothing
    Set wsPaste = Nothing
    Set rngPaste = Nothing
    ExcelApp.Quit
   End sub

由于

1 个答案:

答案 0 :(得分:0)

我有同样的问题。 我首先检查剪贴板的内容是否为excel格式。 如果是,我将使用Excel的PasteSpecial作为值 如果不是,我将使用MSForms.DataObject

从剪贴板粘贴值

下面是我的代码,你可以看看它是否解决了这个问题:

{{1}}