额外行创建导入文件(Extra Line Created Import File)

编程入门 行业动态 更新时间:2024-10-11 09:26:53
额外行创建导入文件(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 Function

An 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 & vbCrLf

the 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

更多推荐

本文发布于:2023-08-07 05:00:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1460675.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   Extra   Line   File   Import

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!