Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

adding value from textbox to excel

$
0
0

Hi,

I have a code that generates ab excel file from a listview. After the last row, I need to add a value to column I. This value will written out of a textbox. Will this be possible? This value sums up the numbers in that column I.

Code:

Dim rowsTotal, colsTotal As Short
        System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
        Dim xlApp As New Excel.Application

        Try

Dim excelBook As Excel.Workbook = xlApp.Workbooks.Add
            Dim excelWorksheet As Excel.Worksheet = CType(excelBook.Worksheets(1), Excel.Worksheet)
            xlApp.Visible = True

            rowsTotal = ListView1.Items.Count - 1
            colsTotal = ListView1.Columns.Count
            With excelWorksheet
                .Cells.Select()
                .Cells.Delete()
                Dim lvi As ListViewItem
                For intCol = 0 To colsTotal - 1
                    excelWorksheet.Cells(1, intCol + 1) = ListView1.Columns(intCol).Text
                Next
                For Each lvi In ListView1.Items
                    rowsTotal -= 1
                    For intCol = 0 To lvi.SubItems.Count - 1
                        excelWorksheet.Cells(rowsTotal + 3, intCol + 1) = lvi.SubItems(intCol).Text
                    Next
                Next
                .Rows("1:1").Font.FontStyle = "Bold"
                .Rows("1:1").Font.Size = 12

                .Cells.Columns.AutoFit()
                .Cells.Select()
                .Cells.EntireColumn.AutoFit()
                .Cells(1, 1).Select()
            End With

 Catch ex As Exception
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default
            xlApp = Nothing
        End Try

Thank you



Viewing all articles
Browse latest Browse all 2535

Trending Articles



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