Displaying csv file with "leading-0" in Ubuntu LibreOffice
1. Make the special column as "text" when opening it in LibreOffice
When you use LibreOffice to open the csv file with columns with leading-0 as in column "BoekstukNr" as below. You will have a setting page when you open the csv file. Except the general settings for all the columns (number will be recognized as number without leading-0, strings will be recognized as strings) in "Separator options" and "Other options", it is important that you still need to set more in Fields. Otherwise LibreOffice will not know that you want to display a column in a specific type. Especially for a date type, it is recognized as number in LibreOffice and MS excel. In the Fields part, you first select the column with leading-0, then change the "Column type " in place 2 to "Text", then after you open it, the leading-0 will be kept.
Note: if you do not set it here and opened the csv file, then the leading-0s are already gone. Even you set in again in the Data tab in the opened file, it dose not work anymore.
2. Change the php script to make the special column to be marked as "text"
You need to use the single quote "'" at the beginning of the column, e.g, 09082013 as '09083013, then it will be keeped in the csv file as a string, and when the file is opened in LibreOffice and MS excel, the single quote will be gone and the "leading -0" will be kept.
Code in php should be like this:
When it is one var:
$date = "'$day"
When using several vars to form a new var, pls do not using "." to connect the variables as normal case , as the dot will become part of the string:
$date = "'$day$periodMonth$periodYear";
Comments
Post a Comment