How to Keep Leading Zeros When Opening a CSV in LibreOffice Calc

Import ZIP codes, SKUs, and account IDs as text, check that 00517 still has five characters, and verify the zeros survive a CSV export.
Follow these steps at your own pace. Check product terms and prices directly with providers before purchasing.
Quick answer
In Calc’s Text Import dialog, select the ZIP code, SKU, or account ID column in the preview. Set Column type to Text before clicking OK. Calc will keep 00517 as five characters. Leave prices and quantities on Standard so you can still calculate with them.
Check whether the source still contains the zeros
Open the original CSV in a plain-text editor and find a record you recognize. Suppose the header is item_id,quantity and the next line is 00517,12. Both zeros are in the source, so a fresh import can recover them. A line that reads 517,12 contains no record of the original width. Check the source system or an earlier export before deciding how many characters belong in that identifier.
Set the column type while opening the file
- In Calc, choose File → Open and select the CSV. For a file with a different extension, choose Text CSV as the file type. Select Edit filter settings if available, then click Open.
- Check the preview. The example should show
item_idandquantityin separate columns. If the whole row occupies one column, choose Separated by and select the actual delimiter, such as Comma. - Click the preview column containing the IDs. Choose Text under Column type. Its preview heading should now read Text. Repeat for any other identifiers, including postal codes and telephone extensions.
- Click OK. If Calc previously skipped the dialog, Edit filter settings reopens it for this import. Enable Always show on import if you regularly receive files whose column order changes.
Prove the ID is text
If the first ID is in A2, enter =ISTEXT(A2) in an unused cell. Expect TRUE. In another blank cell, enter =LEN(A2) and check for 5. Compare A2 with the original line. These tests catch a custom five-digit number format that displays 00517 even though the cell contains the number 517. Remove the temporary checks before exporting.
If some codes still lose zeros
- The file was already open. Reopen the original CSV with the import settings above. Applying a Text format afterward cannot tell Calc whether
517began as0517or00517. - Only quoted IDs survived. The option to format quoted fields as text applies to fully quoted fields. Set the entire identifier column to Text to cover unquoted entries as well. Turning off Detect special numbers alone still allows ordinary digit strings to become numbers.
Save an ODS working copy to retain the column types. If your quantities also came in as text and a report counts them, repair the pivot’s amount field while keeping identifier columns as text. If the recipient needs CSV, export a separate UTF-8 CSV and check 00517 in a text editor. A CSV carries the characters. The recipient’s spreadsheet may also need to import that field as text.
LibreOffice’s Text Import options · Formatting numbers as text in Calc
Comments
Read or join the discussion.