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
This should work for you and it's all that's happening when the process runs. the Recordset variable could have 0-80k rows. Since this script is being run as a task in SSIS I'm not sure how good of a test this will be. The behavior might be quite different.

Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports ClosedXML.Excel



Public Class ScriptMain
Public Sub Main()
    Dim FilePath As String
    Dim Filename As String
    Dim filespec As String

    Dim Recordset As Object

    Recordset = "Row1 Column1, Row1 Column2" & vbCrLf & "Row2 Column1, Row2 Column2"  'CType(Dts.Variables("gvRecordSet").Value, String)

    FilePath = "C:\Billing\"  'Dts.Variables("gvReportFileLocation").Value.ToString
    Filename = "Test_Excel.xlsx" 'Dts.Variables("gvReportFileName").Value.ToString

    filespec = (FilePath & Filename)

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

    Worksheet = Workbook.Worksheet("sheet1")

    Dim NumberOfLastRow As Integer
    Dim CellForNewData As IXLCell
    Try
        NumberOfLastRow = Worksheet.LastRowUsed().RowNumber
        CellForNewData = Worksheet.Cell(3, 1)

        CellForNewData.InsertData(Recordset.ToString)

    Catch ex As Exception
    End Try

End Sub
End Class

Viewing all articles
Browse latest Browse all 1877

Trending Articles



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