At times, some requirements come out to be too tricky to implement. I am talking about exporting the data from C1List to an Excel file. Now I know there are lots of geniuses sitting out there saying that it’s pretty simple to work around it. But my purpose of writing this blog is to help those users who are fairly new to our ComponentOne Suite and needs a quick start guide to such basic requirements. This implementation will use C1Excel control along with C1List to export the data. This is a simple technique and requires traversing the cells in C1List control and writing their values to the C1Excel file sheet. See the implementation code below.
Public Sub ExportData(ByVal exportHeaderCondition As Boolean) Dim excelSheet As C1.C1Excel.XLSheet = C1XLBook1.Sheets(0) If excelSheet IsNot Nothing Then Dim excelRow As Integer = 0 'Exporting Headers If exportHeaderCondition = True Then For i As Integer = 0 To C1List1.Columns.Count - 1 excelSheet(excelRow, i).Value = C1List1.Columns(i).Caption Next excelRow += 1 End If 'Export Cell Values For row As Integer = 0 To C1List1.ListCount - 1 For col As Integer = 0 To C1List1.Columns.Count - 1 Dim cellValue As Object = C1List1.GetDisplayText(row, col) excelSheet(excelRow, col).Value = cellValue Next excelRow += 1 Next End If C1XLBook1.Save("C:\\GeneratedReport.xls") Process.Start("C:\\GeneratedReport.xls") End Sub
Save the Excel file to the disk and it is ready to be used. You can find a sample application attached. Download Sample