I am trying to copy formatted cells from existing excel sheet to new sheet in vb.net(2010) using pastespecial method but it is pasting the cell values as picture rather than text. Any help in this regard would be highly appreciated:
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
Thanks