Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
i want export labels texts from my form , but i cant export in order from form

in addition to

i changed all labels tabindex in order 0 to 60 but i cant get them in order

What I have tried:

    Sub ExportExcel()
         
        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
 
        With excelWorksheet 
            Dim s
            For Each lbl As Control In groupbox1.Controls
                If TypeOf lbl Is Label Then
                    If lbl.Left = 8 Then
                        s = s + 1
                        .Cells(s, 1).value = lbl.Text
                    End If
                End If
            Next lbl
            .Rows("1:" & .Rows.Count).Font.Size = 9
            .Rows("1:1").Font.FontStyle = "Bold"
            .Rows("1:1").Font.Size = 10
            .Cells.Columns.AutoFit()
            .Cells.Select()
            .Cells.EntireColumn.AutoFit()
            .Cells(1, 1).Select()
            If (Not System.IO.Directory.Exists("c:\sekreterya")) Then
                System.IO.Directory.CreateDirectory("c:\sekreterya")
            End If
            Dim misValue As Object = System.Reflection.Missing.Value

            .SaveAs("c:\sekreterya\gelirtablosu.xlsx")
        End With
        xlApp.Visible = True
        System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default
        xlApp = Nothing

    End Sub
End Class
Posted
Updated 1-Dec-19 22:19pm
v3
Comments
Maciej Los 2-Dec-19 3:54am    
Do you want to sort them by TabIndex?
Member 14588284 2-Dec-19 4:29am    
yes,

If you want to save a TabIndex value to be able to sort data based on that value...

VB
For Each lbl As Control In groupbox1.Controls
    If TypeOf lbl Is Label Then
        If lbl.Left = 8 Then
            s = s + 1
            .Cells(s, 1).value = lbl.Text
            .Cells(s, 2).value = lbl.TabIndex 'save TabIndex
        End If
    End If
Next lbl
 
Share this answer
 
i change codes like this and i solved


With excelWorksheet
    Dim s
    On Error Resume Next
    For Each lbl As Control In groupbox1.Controls
        If TypeOf lbl Is Label Then
            If lbl.Left = 8 Then
                s = s + 1
                For Each lbl2 In groupbox1.Controls
                    If lbl2.TabIndex * 1 = s - 1 And lbl.Left = 8 Then
                        ' MsgBox(lbl2.TabIndex * 1 & vbLf & s - 1)
                        .Cells(s, 1).value = lbl2.Text

                    ElseIf (lbl2.TabIndex * 1) = (s - 1) + 100 And lbl.Left = 8 Then
                        .Cells(s, 2).value = lbl2.Text * 1


                    End If
                Next
                'MsgBox(lbl.TabIndex * 1 & vbLf & s - 1)

            End If
        End If
    Next lbl
 
Share this answer
 
Comments
phil.o 2-Dec-19 4:44am    
lbl2.Text * 1
I'd be surprised this would even compile.
And what purpose do all these multiplications by one serve?
Member 14588284 2-Dec-19 4:50am    
i do that because lbl2.text getting excel text format
when i write *1 then geting number format
phil.o 2-Dec-19 5:11am    
Sooner or later, using Option Strict Off will come in and bite you hard.
You should rather use proper types and parse-functions in the first place:
Int32.Parse(lbl2.Text)
Moreover, these multiplications by one are useless when you already have an integer value (multiplying by one is an invariant operation); for example multiplying TabIndex property by one does not bring anything useful; on best case this will be trimmed by the compiler, but you shouldn't rely on that.
Member 14588284 2-Dec-19 5:20am    
Int32.Parse(lbl2.Text)
i used but it dosent work
phil.o 2-Dec-19 5:21am    
Please define "doesn't work".

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900