如何显示从数据库到Excel的特定列数据和行?

时间:2018-11-13 05:54:33

标签: vb.net

我要导出特定的列数据。如何仅显示带有数据的特定列?

这是我到目前为止尝试过的:

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

0 个答案:

没有答案