0

我正在使用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()
4

0 回答 0