I am exporting a table from DB in csv format. I have numbers starting with 0, such as 04596 or 059438.
If I open this csv in LibreOffice or Excel, the 0 will be thrown away and numbers are shown as 4596 and 59438.
I am exporting numbers as text, and if I open csv file in notepad++ the 0s are there, all of them.
Is there a workaround to make numbers visible as they are in file?
2
Answers
convert it to string such as :
echo "'".$number."'";
When you open your CSV file in Calc manually, you see the text import filter settings window. Take your time to click OK, don’t skip this step!
Select the columns that should not be recognized as numbers, but should remain text with a leading zero and specify their type as Text. Also set the correct types for the rest of the columns. You can specify Hide for columns that you do not need. Check the status of the rest of the parameters – code page, language, type of quotes for text fields, and so on.
Just now click OK. Make sure the import went as you expected.
Now run this simple macro
This macro uses the getValArg helper function, here is its text
As a result, you will receive such a message.
Pay attention to the underlined line. If you use just such a parameter for your files (regardless of the programming language that you use to open the file in Calc), then the result will be correct in most cases.