Excel Cell Contains More Than 32767 Characters Error
Excel allows 32767 characters per cell and draws only 1024. See what happens to longer text on import, export and in scripts, and where to store it.

A CSV export from a logging table opens in Excel and half the rows below row 40 are shifted. A report written by a script opens with a repair prompt. A cell shows what looks like the beginning of a long article and nothing after it. The common cause is text longer than Excel allows in a cell: 32,767 characters. The limit is fixed, and it is documented in Microsoft's specifications. This post covers what the limit is, what each way of getting text into Excel does when it is exceeded, and where to put the text instead. It is a spoke of understanding Excel errors when data comes from code.
The limits
Excel's published limits for text are:
| Item | Limit |
|---|---|
| Characters in a cell | 32,767 |
| Characters displayed in a cell | 1,024 |
| Characters in a formula | 8,192 |
| Characters in a sheet name | 31 |
| Characters in a header or footer | 255 |
The 1,024 figure is about display. A cell holding 5,000 characters stores all 5,000, but draws only the first 1,024 in the grid. The formula bar shows the whole content. People see a cut-off cell and assume the data was lost; the data is intact and can be read with LEN or by code.
A related limit catches formulas: text constants inside a formula are limited to 255 characters each. A formula such as ="…long string…" fails if the quoted part is over 255. Break it into pieces joined with &.
What each path does with long text
Opening a CSV. Excel reads a quoted field, and if it exceeds 32,767 characters it cuts the field at the limit and continues reading the rest as the next cell or row. The result is a file with more rows than the CSV had records, the later columns misaligned, and no warning in some versions. The signature is a column of values that are suddenly in the wrong place after one particular row. Check by comparing the row count with the number of records in the source (Excel row and column limits covers the row side).
Power Query. It can load text longer than the cell limit into the Data Model, but loading to a sheet truncates at 32,767 characters. A column over the limit loaded to a Table drops the excess.
openpyxl. It writes the string as given. It does not check the length, so a string over 32,767 characters produces a cell that Excel finds unreadable and offers to repair, removing the cell (fixing Excel found unreadable content after a script export).
XlsxWriter. It truncates strings longer than 32,767 characters and emits a warning. The behavior is stated in its documentation. Silent truncation under a warning that nobody reads is no better than a corrupt file.
pandas. to_excel hands the string to the engine, so the result depends on whether you chose openpyxl or XlsxWriter.
Copy and paste. Pasting a very long text into a cell cuts it at the limit.
Find the long cells
In Excel, add a helper column =LEN(A2) and sort descending, or use conditional formatting with a formula =LEN(A2)>32000. In pandas:
import pandas as pd
df = pd.read_csv("export.csv", dtype=str)
lengths = df.apply(lambda col: col.str.len())
too_long = (lengths > 32767).any()
print(too_long[too_long]) # which columns
print(df.loc[(lengths > 32767).any(axis=1)].index.tolist()[:20]) # which rowsThe check finds oversize cells before they reach the writer. Count them. A handful of cells in a million rows suggests data to fix; a whole column suggests the column does not belong in a spreadsheet.
Keep in mind that Excel counts UTF-16 code units. A character outside the Basic Multilingual Plane, such as many emoji, counts as two. A string of 20,000 emoji is 40,000 units. Python's len counts code points, so for text with such characters measure with len(s.encode("utf-16-le")) // 2.
Options when the text is too long
Choose by what the text is for.
Split it across cells. Chop the text into chunks of 30,000 characters in consecutive columns or rows, with a sequence number. This keeps everything in the workbook but is awkward to read and to rejoin. It suits a rare outlier, not a column.
Truncate on purpose. For a preview, keep the first 1,000 characters and add a suffix such as
... [truncated]. Say so in the header or a note. Truncation that is announced is a design; truncation that is silent is a bug.Write the text to files. Save each long value as a
.txtfile named by the row key and put the file name or a hyperlink in the cell. Readers follow the link.Move the text to a database. A
TEXTcolumn in PostgreSQL holds up to a gigabyte, MySQLLONGTEXTup to four. Excel holds the key and perhaps an excerpt, and a query returns the full text on request.Use another format. JSON Lines or Parquet carry long strings without a cell limit. If the consumer is a program, do not use Excel at all (converting Excel to JSON with Python and the other direction).
For logs, emails, documents, HTML, JSON blobs and stack traces, the answer is nearly always to keep them out of the sheet.
Importing a long-text CSV safely
If you must open a CSV with long fields, do not double-click it. Use Data, From Text/CSV, and load to the Data Model or only as a connection, which does not truncate. Or read it with pandas and decide what to do with the long values:
df["body_excerpt"] = df["body"].str.slice(0, 1000)
df["body_chars"] = df["body"].str.len()
df.drop(columns="body").to_excel("summary.xlsx", index=False)The workbook then holds an excerpt and the length, which is enough to review rows, and the full text stays in the CSV or the database. Keep a key column on both sides so the two can be joined.
Make the writer safe
A report generator that could meet long strings should clamp them itself and say so.
MAX = 32767
def fit(value):
if isinstance(value, str) and len(value) > MAX:
return value[: MAX - 14] + " [truncated]"
return valueApply it to every string cell, and count how many were clamped; write the count into a log or a note on the sheet. Remove control characters at the same step. The combination of a length clamp and an illegal-character filter removes most causes of unreadable generated workbooks.
Checks
After writing, reopen the file with a reader and compare the count of non-empty cells in the text columns with the source. Check the maximum length in the result: it should be at most 32,767. Open the file in Excel once with the longest value selected and look at the formula bar. For a CSV import, count rows in the sheet and in the source file: they should agree.
When long text should not be in a spreadsheet
The text is the data. If the workbook exists to hold documents, comments or transcripts, it is a misuse of a grid. A database or a document store is the right home.
Readers need to search it. A search over 100,000-character cells in Excel is slow and unreliable. Use a text index.
It must round-trip. If a value has to come back unchanged, any truncation loses it. Do not export it to Excel and re-import.
The file will be shared. Long cells make files large and slow to open (why Excel files get huge). Share a summary.
Microsoft lists the limits in Excel specifications and limits, and XlsxWriter documents its string handling in the worksheet reference. To convert a short extract to JSON, use the CSV to JSON converter.


