Pad Text with Spaces for Fixed-Width Files in Excel
Question details
Create left-aligned, space-padded text fields of a specified width for a fixed-width text file.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Names, addresses, or other variable-length values must occupy fixed-width fields in an ASCII or text export.
- Observed behavior
- Spreadsheet column alignment does not carry over as the required spaces in the exported text file.
Check the required width and field order for each column, as well as the file's encoding requirements. Decide how to handle values longer than their allotted width before applying a formula.
Pad and truncate each field with an Excel formula
Use this formula when each text field must occupy an exact number of characters.
REPT adds spaces to the value, and LEFT returns exactly the specified number of characters. Values longer than the field width are truncated.
For a value in A2 that must occupy 30 characters, enter =LEFT(A2&REPT(" ",30),30) in an empty cell such as B2.
Drag the fill handle down to apply the formula to other rows. For another field width, replace both instances of 30 with the required number.
If a record contains multiple padded fields, join their formula cells in the required order. For example, enter =B2&C2 to combine the fields in B2 and C2 without a separator.
Copy the completed record cells, paste them into a plain-text editor, and save the file in the required encoding. Check the field boundaries and confirm that spaces, including trailing spaces, are preserved.

Create Space-Padded Fields in WPS Spreadsheets
Use LEFT and REPT in WPS Spreadsheets to create fixed-width fields, combine them into records, and check the resulting text in an editor.
- 1. Open the spreadsheet: Open WPS Spreadsheets and select Open to load the workbook containing your data.
- 2. Pad a field: In an empty cell, enter =LEFT(A2&REPT(" ",30),30) to make the value in A2 exactly 30 characters wide.
- 3. Fill and combine: Drag the fill handle down, then use a formula such as =B2&C2 to join padded fields in the required order.
- 4. Save and verify the text: Copy the completed records into a plain-text editor, save them using the required encoding, and check that field widths and trailing spaces are preserved.

Frequently Asked Questions
What happens if a name is longer than the field width?
The LEFT part of =LEFT(A2&REPT(" ",30),30) keeps only the first 30 characters. Review long values before using the formula if truncation is not allowed.
Can I pad a numeric field with spaces?
Yes. Convert the number to the required text representation first. For example, =LEFT(TEXT(A2,"0")&REPT(" ",8),8) creates an eight-character field for an integer.
Why doesn't changing the spreadsheet column width fix the text file?
Column width controls the spreadsheet display, not the spaces stored in cell values. Add spaces with a formula, then check the exported or pasted text in a plain-text editor.
Does this formula guarantee a fixed number of bytes?
No. LEFT counts characters, while byte length depends on the file encoding. If the specification requires ASCII, check that all field values contain permitted ASCII characters.




