Cammyr


I'm using vb.net express to call excel with this code

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

Dim XL As Excel.Application

Dim xlwb As Excel.Workbook

Dim xlsheet As Excel.Worksheet

XL = New Excel.Application

xlwb = XL.Workbooks.Open("C:\Documents and Settings\S. Ross\My Documents\sales invoice1.xls")

xlsheet = xlwb.Worksheets(1)

XL.Visible = False

Try

xlsheet.Cells(8, 2).select()

XL.Selection.value = Me.NameComboBox.Text.ToString

xlsheet.Cells(9, 2).select()

XL.Selection.value = Me.AddressTextBox.Text.ToString

xlsheet.Cells(10, 2).select()

XL.Selection.value = (Me.CityTextBox.Text.ToString)

xlsheet.Cells(10, 3).select()

XL.Selection.value = (Me.StateTextBox.Text.ToString)

xlsheet.Cells(11, 2).select()

XL.Selection.value = Me.ZipTextBox.Text.ToString

xlsheet.Cells(4, 9).select()

XL.Selection.value = Me.InvoiceIDTextBox.Text.ToString

xlsheet.Cells(5, 9).select()

XL.Selection.value = Me.CustomerIDTextBox.Text.ToString

xlsheet.Cells(3, 9).select()

XL.Selection.value = DateTime.Today

Catch ex As Exception

End Try

Try

Dim iddatatables As DataTable = Me.RCSDataSet.InvoiceDetails

Dim idx As Integer = 1

For idx = 0 To iddatatables.Columns.Count - 1

Next

Dim row As DataRow

Dim rowidx As Integer = 15

For Each row In iddatatables.Rows

For idx = 0 To iddatatables.Columns.Count - 1

xlsheet.Cells(rowidx, idx + 1) = row(idx)

Next

rowidx = rowidx + 1

Next

Catch

End Try

xlsheet.PrintOut()

xlsheet = Nothing

xlwb = Nothing

XL.Quit()

XL = Nothing

GC.Collect()

End Sub

This prints the required invoice but only to row 36 on the excel worksheet, if I have more than 36 rows to print I need to be able to insert the rows at row 36 and push the rest of the rows down




Re: inserting row in excel

ADG


Hi

In VBA the command would be

Selection.Insert Shift:=xlDown

assuming that the currently selected row is the insertion point






Re: inserting row in excel

Cammyr

Thanks,

Will post in the visual basic language forum to see if anyone knows how to accomplish this with vb.net.