Экспорт выбранных столбцов в excel экспортирует только выбранные столбцы и данные не фильтруются или не выбираются
The Below is the code i used to filter the selected columns to excel. However, the contents (Data) that it exports in excel is not filtered only the column headernames. Private Sub DATAGRIDVIEW_TO_EXCEL(ByVal DGV As DataGridView) Try Dim DTB = New DataTable, RWS As Integer, CLS As Integer For Each Col As DataGridViewColumn In DGV.Columns If CheckBox1.Checked = True And Col.Name = GSIS.Name Then DTB.Columns.Add(Col.Name.ToString) End If If CheckBox2.Checked = True And Col.Name = PAGIBIG.Name Then DTB.Columns.Add(Col.Name.ToString) End If If CheckBox3.Checked = True And Col.Name = PHILHEALTH.Name Then DTB.Columns.Add(Col.Name.ToString) End If If CheckBox4.Checked = True And Col.Name = SSS.Name Then DTB.Columns.Add(Col.Name.ToString) End If If CheckBox5.Checked = True And Col.Name = TIN.Name Then DTB.Columns.Add(Col.Name.ToString) End If If CheckBox6.Checked = True And Col.Name = AgencyEmployeeNo.Name Then DTB.Columns.Add(Col.Name.ToString) End If If CheckBox7.Checked = True And Col.Name = FirstName.Name Then DTB.Columns.Add(Col.Name.ToString) End If If CheckBox8.Checked = True And Col.Name = MiddleName.Name Then DTB.Columns.Add(Col.Name.ToString) End If If CheckBox9.Checked = True And Col.Name = LastName.Name Then DTB.Columns.Add(Col.Name.ToString) End If Next Dim DRW As DataRow For RWS = 0 To DGV.Rows.Count - 1 DRW = DTB.NewRow For CLS = 0 To DGV.ColumnCount - 1 Try DRW(DTB.Columns(CLS).ColumnName.ToString) = DGV.Rows(RWS).Cells(CLS).Value.ToString Catch ex As Exception End Try Next DTB.Rows.Add(DRW) Next DTB.AcceptChanges() Dim DST As New DataSet DST.Tables.Add(DTB) Dim FLE As String = "E:\Export\Export.xml" DTB.WriteXml(FLE) Dim EXL As String = "C:\Program Files\Microsoft Office\Office15\EXCEL.exe" Shell(Chr(34) & EXL & Chr(34) & " " & Chr(34) & FLE & Chr(34), vbNormalFocus) ' OPEN XML WITH EXCEL Catch ex As Exception MsgBox(ex.ToString) End Try '------------------------------------------------------Excel--------------------------------------------------------' End Sub Here is the Datagridview with selected Columns that will be exported http://imgur.com/E4fQ6GG And here is the output of the excel file which the contents are not filtered only the headernames http://imgur.com/Wed0Xha Credits to :@Mederic for helping me previously
Что я уже пробовал:
Последнее, что я пробовал, - это проверить, установлен ли флажок assiciated и col.name затем добавьте его в datatable, как показано в цикле выше.