Im exporting datagrid data in excel and an unexpected error pop out because i want to export the data to excel by date and time
i have an error
An unhandled exception of type 'System.NotSupportedException' occurred in mscorlib.dll
Additional information: The given path's format is not supported.
Sub ExportToExcelGroupByGradeLevel()
Dim dt As DataTable = New DataTable()
For Each column As DataGridViewColumn In dgvExportData.Columns
dt.Columns.Add(column.HeaderText, column.ValueType)
Next
For Each row As DataGridViewRow In dgvExportData.Rows
dt.Rows.Add()
For Each cell As DataGridViewCell In row.Cells
dt.Rows(dt.Rows.Count - 1)(cell.ColumnIndex) = cell.Value.ToString()
Next
Next
Dim result = From rows In dt.AsEnumerable()
Group rows By groupByKey = New With {Key .GradeLevel = rows("Grade Level")} Into Group
Select Group
Dim folderPath As String = "C:\Excel\School Year\" & frmServerPanel.lblSchoolYear.Text & "\Enrolled\Reports\"
If Not Directory.Exists(folderPath) Then
Directory.CreateDirectory(folderPath)
End If
Using wb As XLWorkbook = New XLWorkbook()
For Each item In result
wb.Worksheets.Add(item.CopyToDataTable(), item.CopyToDataTable().Rows(0)("Grade Level").ToString())
Next
wb.SaveAs(folderPath & Convert.ToString(lbltime.Text & "S-DB-" & frmServerPanel.lblSchoolYear.Text & " " & "Group-By-Grade-Level.xlsx"))
MessageBox.Show("Export Sucessfully.", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Using
End Sub
#End Region
Private Sub btnExport_Click(sender As Object, e As EventArgs) Handles btnExport.Click
If cbFilterExport.Text = "Per Grade Level" Then
ExportToExcelGroupByGradeLevel()
End If
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
lbltime.Text = DateTime.Now.ToString("dd/MM/yyyy h:mm:ss tt")
End Sub
thank you for help well appreciated