额外行创建导入文件(Extra Line Created Import File)
我的导入文件中正在创建一个额外的行,该行从另一个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 FunctionAn extra line is being created in my import file which is fed in from another CSV and is going to break my import file. How can I remove the extra line that was created? Thanks!
the code I use to create the file is follows
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最满意答案
问题是您必须删除由TransformProductToEdi生成的最后一个vbCrLf ,用于数组retval的最后一个条目
在TransformProductToEdi中生成vbCrLf的最后一行是
retVal &= .GeminiDepartmentId & vbCrLfthe issue is you have to remove the last vbCrLf produced by TransformProductToEdi for the last entry of the array retval
the last line that produce the vbCrLf in TransformProductToEdi is
retVal &= .GeminiDepartmentId & vbCrLf更多推荐
发布评论