Export to C1FlexGridClassic data Excel using C1XLBook

Posted by: skm.mas on 15 July 2020, 4:57 am EST

    • Post Options:
    • Link

    Posted 15 July 2020, 4:57 am EST

    Export to C1FlexGridClassic data Excel using C1XLBook but numeric data exported as text in excel.

    
    Public Sub C1ExportToExcel(ByVal GridName As C1.Win.C1FlexGrid.Classic.C1FlexGridClassic, ByVal SaveDialog As System.Windows.Forms.SaveFileDialog, Optional ByVal lngStartRow As Long = -1, Optional ByVal lngEndRow As Long = -1, Optional ByVal lngStartCol As Long = -1, Optional ByVal lngEndCol As Long = -1)
        Try
          If GridName.Rows > 1 Then
            If (MsgBox("Do You Want to Export the Data To Excel Sheet", MsgBoxStyle.YesNoCancel, "DetaSys") = MsgBoxResult.Yes) Then
              Dim XlsApp As New C1XLBook
              Dim XlsWB As XLSheet = XlsApp.Sheets(0)
              Dim intRow, intCol As Integer
              Dim str As String
              SaveDialog.ShowDialog()
              str = SaveDialog.FileName + ".xlsx"
              If Len(str) > 0 Then
                For intRow = 0 To GridName.Rows - 1
                  For intCol = 0 To GridName.Cols - 1
                    XlsWB(intRow, intCol).Value = GridName.get_TextMatrix(intRow, intCol)
                  Next
                Next
                XlsApp.Save(str)
                ReleaseObject(XlsWB)
                MsgBox("Export To Excel Sheet Completed Successfull", MsgBoxStyle.OkOnly, "DetaSys")
              End If
            Else
            End If
          Else
            MsgBox("No Data For Export To Excel Sheet", MsgBoxStyle.OkOnly, "DetaSys")
          End If
        Catch ex As Exception
          MsgBox(ex.Message, MsgBoxStyle.Information, "DetaSys")
        End Try
      End Sub
    
    Private Sub ReleaseObject(ByVal obj As Object)
        Try
          System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
          obj = Nothing
        Catch ex As Exception
          obj = Nothing
        Finally
          GC.Collect()
        End Try
      End Sub
    
    
  • Posted 15 July 2020, 6:38 pm EST

    Hi,

    The method that you are using just copies the data, not the formatting that is why it is assuming all the values as string.

    You can look at the product sample “FlexGridExcel” implementing the same, please have a look into it. The sample is located at:

    .\Documents\ComponentOne Samples\WinForms\v4.5.2\C1Excel\CS\FlexGridExcel



    Regards,

    Prabhat Sharma.

  • Posted 16 July 2020, 3:12 pm EST

    Ok, Let install a new version and check currently

  • Posted 18 July 2020, 2:25 am EST

    Hi Prabhat,

    Can you please provide the complete path of sample

  • Posted 19 July 2020, 3:48 pm EST

    Hi,

    When you install the product via ComponentOneControlPanel utility by checking the Install Samples option, you can see the product samples in the Documents folder of your system. It will create a folder named ComponentOne Samples where you can see the sample and the C1NWind DB file.

    I have attached the sample for your reference, please have a look.

    Regards,

    Prabhat Sharma.

    FlexGridExcel.zip

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels