2012年2月21日 星期二

Vb.Net Excel Cell 強制設為文字


Dim dtWork As DataTable
Dim app As Object ' Excel.Application
Dim wb As Object 'Excel.Workbook
Dim ws As Object 'Excel.Worksheet

'Store Data
For i = 0 To dtWork.Rows.Count - 1
  For j = 0 To dtWork.Columns.Count - 1
    If dtWork.Columns(j).DataType Is GetType(String) Then
      '如果資料欄位是文字,excel 的 cell 也設為文字
      ws.Cells(i + 2, j + 1).numberformat = "@"
    End If
    '剩下的 cell 使用預設值 自動

    ws.Cells(i + 2, j + 1) = dtWork.Rows(i)(j)
  Next
Next

沒有留言: