Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I'm trying to save a converted xls file in csv.

--> after convert process
VB
Dim _Out() As String = csvData.Split("\n")

   Dim _OutPut As String = targetFile 'path and filename to save in local
   Dim _csv As StreamWriter = New StreamWriter(_OutPut, False)
   _csv.Write(csvData)
   _csv.Close(

)


Gives me this ressult below:
VB
ABCReferenceNo,ChequeDate,ChequeNo,DocRate,HouseBankCode,BankAcct,Project,ProjectName,Customer_OR_VendorCode,Customer_OR_VendorName,DocumentCurrency,Balance,\nABCRef1,20120131,1234,1,ABC01 USD,4808507000-22,A01102,Lente-Serenity Tower,V-J1036,CORJUVIT TRADING & CONSTRUCTION,USD,#VALUE!\nABCRef2,20120131,1235,1,ABC01 USD,4808507000-22,A01102,Lente-Serenity Tower,V-U1001,USAUK INC.,USD,#VALUE!\nABCRef3,20120131,1236,1,ABC01 USD,4808507000-22,A03101,ASIA oOne Corall Way,V-S1058,STARGATE MANUFACTURING CORP.,USD,#VALUE!\nABCRef4,20120131,1237,1,ABC01 USD,4808507000-22,A03101,ASIA oOne Corall Way,V-N1010,"NUEVA JAPAN HUMAN RESOURCES BUILDERS GROUP,INC.",USD,#VALUE!\n,,,,,,,,,,,,\n,,,,,,,,,,,,\n,,,,,,,,,,,,\n,,,,,,,,,,,,\n,,,,,,,,,,,,\n,,,,,,,,,,,,\n,,,,,,,,,,,,\n,,,,,,,,,,,,\n,,,,,,,,,,,,\n,,,,,,,,,,,,\n,,,,,,,,,,,,\n,,,,,,,,,,,,\n,,,,,,,,,,,,\n,,,,,,,,,,,,\n,,,,,,,,,,,,\n,,,,,,,,,,,,\n,,,,,,,,,,,,\n,,,,,,,,,,,,\n,,,,,,,,,,,,\n,,,,,,,,,,,,\n,,,,,,,,,,,,\n,,,,,,,,,,,,\n,,,,,,,,,,,,\n,,,,,,,,,,,,\n,,,,,,,,,,,,\n,,,,,,,,,,,,\n


The result that should be is like this below:
VB
ABCReferenceNo,ChequeDate,ChequeNo,DocRate,HouseBankCode,BankAcct,Project,ProjectName,Customer_OR_VendorCode,Customer_OR_VendorName,DocumentCurrency,Balance
ABCRef1,20120131,1234,1,ABC01 USD,4808507000-22,A01102,Lente-Serenity Tower,V-J1036,CORJUVIT TRADING & CONSTRUCTION,USD,#VALUE!
ABCRef2,20120131,1235,1,ABC01 USD,4808507000-22,A01102,Lente-Serenity Tower,V-U1001,USAUK INC.,USD,#VALUE!
ABCRef3,20120131,1236,1,ABC01 USD,4808507000-22,A03101,ASIA oOne Corall Way,V-S1058,STARGATE MANUFACTURING CORP.,USD,#VALUE!
ABCRef4,20120131,1237,1,ABC01 USD,4808507000-22,A03101,ASIA oOne Corall Way,V-N1010,"NUEVA JAPAN HUMAN RESOURCES BUILDERS GROUP,INC.",USD,#VALUE!



I'm using VB2005. Please Help me
Posted

1 solution

I've got the solution.

in the While process, after reading the whole line, i then save it per line using streamwriter writeline like this;

SQL
While row_no < rCount ''(_Result.Tables(0).Rows.Count - 1)

            For i As Integer = 0 To cCount

                csvData += _Result.Tables(0).Rows(row_no)(i).ToString() + ","


            Next

            Dim _OutPut As String = targetFile

            Dim swE As New System.IO.StreamWriter(_OutPut, True)

            swE.WriteLine(csvData)

            row_no = row_no + 1

            csvData = ""

            swE.Flush()
            swE.Close()

End While
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900