Write to CSV - Encoding Problem?

Write to CSV - Encoding Problem?

bmohler
Contributor Contributor
684 Views
2 Replies
Message 1 of 3

Write to CSV - Encoding Problem?

bmohler
Contributor
Contributor

I have a script that exports parts list data to an Excel template to create a BOM. From that BOM, the script reads data and writes it to a .csv file to be imported into our ERP system. My issue is that whenever there is a diameter symbol in a part description, the .csv file has "ø" instead of the diameter symbol (we use alt+0248 to create ø). Is there anything that can be done about this?

 

Here is the part of my code that creates the .csv:

SyntaxEditor Code Snippet

'Export to .csv
		Dim oFile As System.IO.File
		Dim oWrite As System.IO.StreamWriter
		csv_filename = filepath & name & ".csv"
		oWrite = oFile.CreateText(csv_filename)
			For rownum = 1 To 1000
			exportdata = GoExcel.CellValues(filepath & name & ".xlsx", "Export", "A" & CStr(rownum), "I" & CStr(rownum))
				If GoExcel.CellValue(filepath & name & ".xlsx", "Export", "A" & CStr(rownum)) = " "
					GoTo Skip
				Else
				oWrite.Write(exportdata.Item(0) & ",")
				oWrite.Write(",")
					For i As Integer = 1 To exportdata.Count - 1
						oWrite.Write(exportdata.Item(i) & ",")
						Logger.Debug(exportdata.Item(i))
					Next
					oWrite.WriteLine()
				End If
			Next
		skip :		
		oWrite.Close()

 Using the log I am able to see that the diameter symbol appears correctly up to the point where the data is written to the csv. The problem with the translation occurs in the owrite command.

0 Likes
Accepted solutions (1)
685 Views
2 Replies
Replies (2)
Message 2 of 3

vladimir_michl
Advisor
Advisor

The encoding problem is probably already in the XLS file - how do you create it?

 

Vladimir Michl, www.cadstudio.cz  www.cadforum.cz

 

0 Likes
Message 3 of 3

w.pepping
Advocate
Advocate
Accepted solution

I had the same problem back a while.

You can solve it by using this line of code:

Dim csv_filename As String = filepath & name & ".csv"
Dim objStreamwriter As New StreamWriter(csv_filename, False, System.Text.Encoding.Default)

 

Get control of your sheet metal files.
Download the app from matprop.com