Contact

LibreOffice Calc · CSV import · Beginner

Keep Leading Zeros in Calc CSV Imports and Pasted Product Codes

Preserve exact product codes in LibreOffice Calc by importing or pasting them as text, then check their type, length and characters before sharing.

Worked example tested in LibreOffice Calc 26.8.1.1 · Editorial standards

For product codes such as 000184, set the incoming column to Text before Calc converts it. For a CSV, use the Text Import column type. For copied plain text, use Paste Special’s text-import route and set that column to Text there too. Changing an already damaged value’s format cannot recover missing digits.

An identifier is a string of exact characters, even when it contains only digits. Quantities and prices can remain numeric in separate columns.

Start with the original characters

Use desktop Calc and keep an untouched source file or source text. These steps follow LibreOffice 26.8 Help and standard menus. Save the working result as ODS because CSV cannot store cell types or formatting.

The existing practice CSV with SKUs contains:

sku quantity description
000184 12 White paper
00402 5 Blue folder
A007 3 Black pens

These are synthetic codes. The first two have different intended lengths, so a single fixed-width number format is not a general solution.

1. Preserve codes when opening the CSV

  1. Choose File → Open and select the original practice CSV.
  2. In Text Import, choose comma as the separator and check that the preview has three columns.
  3. Click the sku column heading in the preview, then set Column type to Text. Do not merely select one data cell.
  4. Leave quantity numeric and description as ordinary text. Confirm the preview’s column heading identifies sku as Text.
  5. Finish importing and immediately run the checks below before saving or joining this table to anything else.

Select a screenshot to open the full-size image.

Calc CSV Text Import uses comma separation and assigns the selected sku preview column the Text type before conversion.

Native Calc 26.8.1.1: assign Text to the identifier column before importing. This practice file contains ASCII characters.

If the dialog is suppressed, use Edit filter settings in the File Open dialog where offered. Do not assume yesterday’s import choices match today’s file. LibreOffice’s Text Import documentation covers preview column types and the dialog-display option.

2. Preserve codes copied from a web page or text file

For a controlled paste test, copy these three lines as plain text, without adding apostrophes:

000184
00402
A007

Use an empty area or a new sheet so no existing data can be overwritten.

  1. Select A1 in the destination sheet.
  2. Choose Edit → Paste Special → Paste Special rather than a normal rich-text paste.
  3. If a format chooser appears, choose Use text import dialog where offered. In the tested Calc 26.8.1.1 chooser, it is a separate selectable row alongside Unformatted text, not a checkbox. For the three-line plain-text test, Unformatted text also opened Text Import; the long-ID test explicitly selected Use text import dialog. Clipboard formats vary by source; the goal is the Text Import preview, not an HTML table paste.
  4. In Text Import, confirm the preview shows one column and three rows. Select that column’s heading and choose Text.
  5. Complete the paste. Check the top cell before continuing: =LEN(A1) should be 6 and =ISTEXT(A1) should be TRUE.

The general Paste Special documentation explains that available formats depend on the clipboard source and provides the Text Import option. If the expected import route does not appear, cancel rather than guessing: paste into a plain-text editor, verify the original characters, then copy that plain text and repeat, or save it as a text/CSV file and use the file-import procedure.

The native Paste Special format chooser has Use text import dialog selected as a separate row.

This explicit chooser selection was used for the long-ID test copied from the Mousepad plain-text editor.

A different dialog when copying Calc cells is normal. Calc’s own Paste Special has Text, Numbers, Formulas and other content selections. Its Text checkbox means “paste cells whose contents are text”; it is not a conversion command that turns numeric 184 into the original 000184. A Values Only paste also cannot reconstruct zeros absent from the source. See Paste Special (Calc). In the native negative control, copying numeric 184 with only Text selected left the empty destination blank. Values Only pasted numeric 184, with no recovered zeros.

3. For manual entry, prepare Text cells first

For a few codes you are typing yourself, select the empty destination cells and choose Format → Cells → Numbers → Text before entry. Alternatively type a leading apostrophe, for example '000184; Calc uses it as an entry marker and displays 000184.

This is a manual-entry method, not a reason to prepend apostrophes to every field in an external CSV. An apostrophe that is literal source data can become an extra character. When importing a file, use its column type instead. See Formatting Numbers as Text.

Preformatting a destination is also not a blanket guarantee for every clipboard format. A normal paste from another spreadsheet can carry values and formatting from its source. Use the explicit import route for raw copied text and verify the result.

4. Check the stored identifier, not just its display

For the CSV example, the first code is in A2. Put these formulas in spare cells:

=LEN(A2)
=ISTEXT(A2)
=EXACT(A2;"000184")

Expect 6, TRUE and TRUE. The next two rows should have lengths 5 and 4 and both remain text. If your function argument separator is comma, adapt the EXACT formula accordingly.

Use LEN for character count, ISTEXT for type and EXACT for the literal comparison. Type and characters answer different questions: ISTEXT alone could be TRUE for the already damaged text 184.

For a long-ID stress test, paste the synthetic string 0001234567890123456789 through the Text Import route. Its length must be 22, ISTEXT must be TRUE, and an EXACT comparison with that quoted string must be TRUE. Do not convert it to a number as an intermediate step. A long numeric identifier can lose precision as well as leading zeros; returning it to Text afterward cannot recover altered characters.

Plain-text clipboard import preserves the three short codes and the 22-character long identifier with correct lengths and TRUE text and exact-match checks.

The stress identifier retains all 22 characters as text, including its leading zeros.

Can number formatting restore zeros?

A six-digit number format can make numeric 184 look like 000184, but it remains the number 184. That can be appropriate for a genuinely numeric fixed-width display, not for recovering an unknown original code. LibreOffice distinguishes text entry from zero-filled number display in Entering a Number with Leading Zeros.

If the original lengths vary, you cannot know whether 184 was 184, 0184 or 000184 without the source or an explicit identifier rule. Reopen or recopy the original and select Text before conversion. Do not fabricate missing digits.

Share without triggering another conversion

  1. Keep an ODS master with verified text cells.
  2. If another system requires CSV, export a separate copy and retain the master.
  3. Inspect the exported raw text for representative codes, then reopen it with the identifier column explicitly set to Text and repeat the length/type checks.
  4. Tell the receiving workflow which fields are identifiers. CSV quotations do not impose a universal text type on every application; import settings still matter.

In the native test, the three-code sheet was exported as a separate CSV, its raw text checked, then reimported with sku explicitly Text. Fresh LEN, ISTEXT, EXACT and quantity-type formulas in empty cells all passed. Recompute the checks after reimport; imported TRUE values alone are not evidence of a new calculation. The export also contained the check columns as calculated values. The separate 22-character clipboard ID remained in the ODS master and was not included in this CSV round trip.

After CSV reimport with sku as Text, freshly entered formulas show lengths 6, 5 and 4, TRUE text and exact checks, and numeric quantities.

Fresh formulas in rows 7–9 validate the reimported data rather than relying on the check values exported earlier.

Related: stop CSV values from becoming dates and convert actual quantities from text.

Common problems

  • Detect special numbers is off but zeros still vanish: ordinary decimal-looking digit strings can still be interpreted numerically. Set the identifier column explicitly to Text.
  • The preview has one wide column for the three-field CSV: choose the correct delimiter before assigning column types.
  • LEN is right but the code differs: inspect spaces, a literal apostrophe, letter case or another changed character with EXACT and the source text.
  • A pasted number uses scientific notation: do not infer exact digits from the display. Return to the original and import as text.
  • Only formatting was changed after loss: undo if the original is still recoverable, otherwise reload the source. Text format is not historical recovery.

Verification: original CSV import with sku set to Text, real plain-text clipboard import from Mousepad, the 22-character stress ID, the numeric-cell Paste Special negative control, and actual ODS save/close/reopen were tested in LibreOffice Calc 26.8.1.1 on Linux (English interface, English USA locale) on 16 October 2026. The three original codes were separately CSV-exported, inspected as raw text, reimported as Text and validated with fresh formulas; quantities remained numeric. The stress ID was checked after clipboard import and ODS reopen, but was not CSV-exported/reimported. Screenshots are unchanged native captures, and the original practice CSV is unchanged. Web/HTML clipboard formats, other locales/platforms, non-ASCII encoding, manual apostrophe entry, zero-filled numeric display, all-fields-quoted export and external recipient applications were not tested; those alternatives and cautions remain documentation-based.