Search This Blog

Tuesday, June 22, 2021

Creating and Importing CSV to Excel

 PROBLEM

I am trying to export a Bill Of Material (BOM) as a CSV file.
Some fields appear numeric but they are not.
Excel is trimming leading zeros.
So Package type 0603 turns up on Excel as 603

Putting all values in double quotes does not work.  ,"0603",
Putting a double quoted equal sign does not work  ,"=""0603",
Putting a single quote inside the double quotes before the number does not work
eg   ,"'0603" ---> Gives '0603 and looks messy
only works when you are manually entering data from the keyboard.

 

https://superuser.com/questions/318420/formatting-a-comma-delimited-csv-to-force-excel-to-interpret-value-as-a-string

Gives some useful but also some incorrect advice. 

But it also gives this advice

Putting a tab before all values before putting double quotes around them DOES prevent conversions to dates AND DOES prevent trimming of leading or trailing zeroes and the sheet does not even show nasty warning markers in the upper left corner of each cell.

And ASCII tab is decimal 9

$myData = $myData.",".'"'.chr(9).$a.'"';




No comments:

Post a Comment