如标题,现在我要把DataGrid控件中的一些数据批量输出到TXT文档中。请问该怎么实现? 我是新手哇

解决方案 »

  1.   

    最好是从绑定到 DataGrid 控件的 Recordset 对象的 GetString 方法直接获得字符串文本,然后写入文件。
      

  2.   

       '下面代码能读出所有DATAGRID中的所以数据,写到文件中就可以了,adodc1是DATAGRID的数据源
       Dim i, j
       For j = 0 To Me.Adodc1.Recordset.RecordCount - 1
       For i = 0 To Me.Adodc1.Recordset.Fields.Count - 1
       Me.DataGrid1.Row = j
       Me.DataGrid1.Col = i
       Debug.Print Me.DataGrid1.Text; "  ";
       Next i
       Debug.Print
       Next j
      

  3.   


    您好,谢谢您的答复。
    Shell "cmd /c echo   > c:\试题.txt", 0  通过这条语句我在C盘建立了一个TXT文本。
    我希望能够直接写入文本当中。   现在不懂如何写进去我很菜的,现在做一个题库管理系统,在这卡了
      

  4.   

    Dim varOutput As Variant
    varOutput = Adodc1.Recordset.GetString(adClipString)
    Open "c:\试题.txt" For Output As #1
    Print #1, varOutput
    Close #1
      

  5.   

     
       Dim i, j
       Open "c:\试题.txt" For Output As #1
       For j = 0 To Me.Adodc1.Recordset.RecordCount - 1
       For i = 0 To Me.Adodc1.Recordset.Fields.Count - 1
       Me.DataGrid1.Row = j
       Me.DataGrid1.Col = i
       Print #1, Me.DataGrid1.Text+ "  "
       Next i
       Print #1,chr(13)
       Next j
       close #1
      

  6.   


    你试过了?
    GetString 方法缺省提取记录集所有的行,行间用 vbCrLf 分隔,字段用 vbTab 分隔。
    因此,不需要循环。
      

  7.   


    你试过了?
    GetString 方法缺省提取记录集所有的行,行间用 vbCrLf 分隔,字段用 vbTab 分隔。
    因此,不需要循环。
    嗯嗯  试过了啊  只能输出第一行的数据
      

  8.   

     
       Dim i, j
       Open "c:\试题.txt" For Output As #1
       For j = 0 To Me.Adodc1.Recordset.RecordCount - 1
       For i = 0 To Me.Adodc1.Recordset.Fields.Count - 1
       Me.DataGrid1.Row = j
       Me.DataGrid1.Col = 1
       Print #1, Me.DataGrid1.Text+ "  "
       Me.DataGrid1.Row = j
       Me.DataGrid1.Col = 4
       Print #1, Me.DataGrid1.Text
       Next i
       Print #1,vbCrLf
       Next j
       close #1
      

  9.   

     
       Dim i, j
       Open "c:\试题.txt" For Output As #1
       For j = 0 To Me.Adodc1.Recordset.RecordCount - 1
          Me.DataGrid1.Row = j
          Me.DataGrid1.Col = 1
          Print #1, Me.DataGrid1.Text+ "  "
          Me.DataGrid1.Row = j
          Me.DataGrid1.Col = 4
          Print #1, Me.DataGrid1.Text
          Print #1,vbCrLf
       Next j
       close #1