Streamwriter在VB.NET中截断Excel导出数据

时间:2013-05-01 06:09:37

标签: vb.net excel filestream

我正在使用streamwriter和文件流编写Excel工作表,它可以很好地处理小数据,但对于大型Excel文件,它可以截断数据。这是我的代码:

'Increment unlimited
Using (objStreamWriter)
   For Each info As DataFileInfo In list
      If ((Not vendor.ExportByDivision And Not vendor.ExportBySubDivision) Or ((vendor.ExportByDivision And prevDivisionID = info.DivisionID) Or blnFirstRecord) Or ((vendor.ExportBySubDivision And prevSubDivisionID = info.SubDivisionID) Or blnFirstRecord)) Then
         objStreamWriter.WriteLine(InsertExportInfo(companyID, info, delimiter, vendor.DetailInvoiceExport))
         blnFirstRe cord = False
      Else 
         FileNumber = FileNumber + 1
         objStreamWriter.Close()
         objFileStream.Close()
         fileName = String.Format("{0}\{1}_{2}.{3}", Me.TempPath, vendor.ID, FileNumber, CType(vendor.DataExportType, VendorInfo.VendorDataExportType).ToString().ToLower())
         objFileStream = New FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write)
         'If the company contains unicode text
         If IsUnicodeCompany(companyID) Then
            objStreamWriter = New StreamWriter(objFileStream, System.Text.Encoding.Unicode)
         Else
            objStreamWriter = New StreamWriter(objFileStream)
         End If
         If vendor.DataExportType = VendorInfo.VendorDataExportType.XLS Then
             If vendor.DetailInvoiceExport = True Then
               objStreamWriter.WriteLine(String.Format(Me.GetDataExcelExportDetailHeader(companyID), delimiter))
             Else
               objStreamWriter.WriteLine(String.Format(Me.GetDataExcelExportHeader(companyID), delimiter))
             End If
         End If
         objStreamWriter.WriteLine(InsertExportInfo(companyID, info, delimiter, vendor.DetailInvoiceExport))
      End If
      prevDivisionID = info.DivisionID
      prevSubDivisionID = info.SubDivisionID
      objStreamWriter.Flush()
      objFileStream.Flush()
   Next
End Using
objStreamWriter.Close()
objFileStream.Close()

0 个答案:

没有答案