首先要確定SQL語句的執行環境。以下是VB裡的資料匯出程式碼,已假設建立了一個adodc控制元件:Dim i, j As IntegerDim ex As ObjectDim exwbook As ObjectDim exsheet As ObjectSet ex = CreateObject("Excel.Application") "建立EXCEL物件Set exwbook = ex.Workbooks.Add "開啟檔案ex.Visible = TrueSet exsheet = exwbook.Worksheets("sheet1") "設定工作表With Adodc1.RecordsetFor j = 2 To .Fields.Count exsheet.Cells(1, 1) = "序號" exsheet.Cells(1, j) = .Fields(j - 1).NameNext.MoveFirstFor i = 1 To .RecordCount For j = 2 To .Fields.Count exsheet.Cells(i + 1, 1) = i exsheet.Cells(i + 1, j) = .Fields(j - 1).Value Next.MoveNextNext iEnd With
首先要確定SQL語句的執行環境。以下是VB裡的資料匯出程式碼,已假設建立了一個adodc控制元件:Dim i, j As IntegerDim ex As ObjectDim exwbook As ObjectDim exsheet As ObjectSet ex = CreateObject("Excel.Application") "建立EXCEL物件Set exwbook = ex.Workbooks.Add "開啟檔案ex.Visible = TrueSet exsheet = exwbook.Worksheets("sheet1") "設定工作表With Adodc1.RecordsetFor j = 2 To .Fields.Count exsheet.Cells(1, 1) = "序號" exsheet.Cells(1, j) = .Fields(j - 1).NameNext.MoveFirstFor i = 1 To .RecordCount For j = 2 To .Fields.Count exsheet.Cells(i + 1, 1) = i exsheet.Cells(i + 1, j) = .Fields(j - 1).Value Next.MoveNextNext iEnd With