我要导出特定的列数据。如何仅显示带有数据的特定列?
这是我到目前为止尝试过的:
For Each dc In datatableMain.Columns
colIndex = colIndex + 1
oSheet.Cells(1, colIndex1) = dc.ColumnName
oSheet.Cells(1, colIndex2) = dc.ColumnName
oSheet.Cells(1, colIndex3) = dc.ColumnName
oSheet.Cells(1, colIndex4) = dc.ColumnName
oSheet.Cells(1, colIndex5) = dc.ColumnName
Next
For Each dr In datatableMain.Rows
rowIndex = rowIndex + 1
colIndex = 0
For Each dc In datatableMain.Columns
colIndex = colIndex + 1
oSheet.Cells(rowIndex + 1, colIndex) = dr(dc.ColumnName)
Next
Next