我的导入文件中正在创建一个额外的行,该行从另一个CSV输入,并将打破我的导入文件。如何删除创建的额外行?谢谢!
我用来创建文件的代码如下
Friend Function ImportFile(ByVal filename As String) As infoEDIProduct()
Dim retVal() As infoEDIProduct
Try
Dim actualFileName As String = IO.Path.GetFileName(filename)
Catch e1 As IO.IOException
MsgBox("File is already open please check file.")
End Try
Dim streamReader As New IO.StreamReader(filename)
Dim streamWriter As New IO.StreamWriter(filename & ".csv")
streamWriter.AutoFlush = True
streamWriter.WriteLine(TabDeliminatedHeaders)
Dim lineIn As String = ""
Do While Not streamReader.EndOfStream
retVal = Resize(retVal)
retVal(retVal.Length - 1) = TransformToEDIProduct(streamReader)
streamWriter.Write(TransformEDIproductIntoTabDeliminated(retVal(retVal.Length - 1)))
Loop
streamWriter.Close()
streamWriter.Dispose()
streamReader.Close()
streamReader.Dispose()
Return retVal
Private Function TransformEDIproductIntoTabDeliminated(ByVal EDIproduct As infoEDIProduct) As String
Dim retVal As String = ""
With EDIproduct
retVal = .lineNumber & vbTab
retVal &= .UPCcode & vbTab
retVal &= .sketchersStyleNumber & vbTab
retVal &= .colourDescription & vbTab
retVal &= .size & vbTab
retVal &= .sketchersDivisionDescription & vbTab
retVal &= .sketchersColourCode & vbTab
retVal &= .sketchersDivisionCode & vbTab
retVal &= .department & vbTab
retVal &= .subDepartment & vbTab
retVal &= .gender & vbTab
retVal &= .productShortDescription & vbTab
retVal &= .productDescription & vbTab
retVal &= .costPrice & vbTab
retVal &= .retailPrice & vbTab
retVal &= .DiscountPrice & vbTab
retVal &= .GeminiDepartmentId
End With
Return retVal
End Function
Private Function TransformProductToEdi(ByVal EDIproduct As infoEDIProduct) As String
Dim retVal As String = ""
With EDIproduct
retVal = .lineNumber & vbCrLf
retVal &= .UPCcode & vbCrLf
retVal &= .sketchersStyleNumber & vbCrLf
retVal &= .colourDescription & vbCrLf
retVal &= .size & vbCrLf
retVal &= .sketchersDivisionDescription & vbCrLf
retVal &= .sketchersColourCode & vbCrLf
retVal &= .sketchersDivisionCode & vbCrLf
retVal &= .department & vbCrLf
retVal &= .subDepartment & vbCrLf
retVal &= .gender & vbCrLf
retVal &= .productShortDescription & vbCrLf
retVal &= .productDescription & vbCrLf
retVal &= .costPrice & vbCrLf
retVal &= .retailPrice & vbCrLf
retVal &= .DiscountPrice & vbCrLf
retVal &= .GeminiDepartmentId & vbCrLf
End With
Return retVal
End Function
答案 0 :(得分:0)
问题是您必须删除vbCrLf
为数组的最后一个条目TransformProductToEdi
生成的最后retval
在vbCrLf
中生成TransformProductToEdi
的最后一行是
retVal &= .GeminiDepartmentId & vbCrLf