阅读背景:

vb.net导出CSV文件

来源:互联网 
Public   Function   WriteToCSV(ByVal   dataTable   As   DataTable,   ByVal   filePath   As   String,   ByVal   records   As   ArrayList)   As   Boolean   
          Dim   fileStream   As   System.IO.FileStream   
          Dim   streamReader   As   System.IO.StreamReader   
          Dim   streamWriter   As   System.IO.StreamWriter   
          Dim   i,   j   As   Integer   
          Dim   strRow   As   String   
    
          Try   
                  If   (System.IO.File.Exists(filePath))   Then   
                          System.IO.File.Delete(filePath)   
                  End   If   
    
                  fileStream   =   New   FileStream(filePath,   System.IO.FileMode.CreateNew,   System.IO.FileAccess.Write)   
    
                  If   Not   dataTable   Is   Nothing   Then   
                          streamWriter   =   New   StreamWriter(fileStream,   System.Text.Encoding.Default)   
    
                          For   i   =   0   To   dataTable.Rows.Count   -   1   
                                  strRow   =   ""   
                                  For   j   =   0   To   dataTable.Columns.Count   -   1   
                                          strRow   +=   dataTable(i)(j)   
                                          If   j   <   dataTable.Columns.Count   -   1   Then   
                                                  strRow   +=   ","   
                                          Else   
                                Next   
                                  streamWriter.WriteLine(strRow)   
                          Next   
                          streamWriter.Close()   
                  End   If   
    
                  fileStream.Close()   
    
                  Return   True   
          Catch   ex   As   Exception   
    
                  Return   False   
          End   Try   
    
  End   Function 
Public   Function   WriteToCSV(ByVal   data



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: