Quantcast
Channel: ClosedXML - The easy way to OpenXML
Viewing all articles
Browse latest Browse all 1877

New Post: Insert Recordset to Existing Worksheet

$
0
0
Let me preface this with the fact that I'm a SQL DBA and not a programmer, so my code may not be the most efficient.

With that said, I'm moving away from Interop.Excel for many reasons but it seems I'm having problems converting some of my scripts to use ClosedXML.

My issue is not having my query results in the spreadsheet. I pass the results into the script in a variable but don't get the expected result. Before I could simply do the following.
        objWorkBook = objExcel.Workbooks.Open(strReportFileLocation & strReportFileName)

        myRecordset = Dts.Variables("gvRecordSet").Value

        objWorkSheet = objWorkBook.Worksheets("SomeCharges")

        __objWorkSheet.Cells(3, 1).CopyFromRecordset(myRecordset)__
Now with ClosedXML I'm using the following code. I do not receive any errors but I have no data on my spreadsheet either.
  Public Sub Main()
    Dim FilePath As String
    Dim Filename As String
    Dim Recordset As Object
    Dim filespec As String

    FilePath = Dts.Variables("gvReportFileLocation").Value.ToString
    Filename = Dts.Variables("gvReportFileName").Value.ToString
    Recordset = CType(Dts.Variables("gvRecordSet").Value, String)
    filespec = (FilePath & Filename)

    Dim Workbook As New XLWorkbook(filespec)
    Dim Worksheet As IXLWorksheet

    Worksheet = Workbook.Worksheet("SomeFees")

    Dim CellForNewData As IXLCell

        CellForNewData = Worksheet.Cell(3, 1)

        CellForNewData.InsertData(Recordset)
Thanks in advance for any help.

Viewing all articles
Browse latest Browse all 1877

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>