Description
In Excel, both the 32,767-character cell limit and the 31-character sheet name limit are based on UTF-16 units. Since surrogate pairs count as two units, strings containing such characters may exceed these limits even if they appear shorter in rune length. In excelize, truncation is done by rune length, which can produce invalid files that trigger a “Problem with some content” alert in Excel.
Steps to reproduce the issue
package main
import (
"log"
"strings"
"github.com/xuri/excelize/v2"
)
func main() {
f := excelize.NewFile()
// "😀" and "𩸽" are both represented as surrogate pairs.
// The text length is 32,767 runes in Go, but 32,769 units in UTF-16.
text := strings.Repeat("A", 32767-2) + "😀𩸽"
f.SetCellValue("Sheet1", "A1", text)
if err := f.SaveAs("cell_limit_error.xlsx"); err != nil {
log.Fatalf("failed to save file: %v", err)
}
}
Run the code above, then open the generated xlsx file in Excel.
Describe the results you received
“Problem with some content” alert in Excel.
Describe the results you expected
The expected result is that when the string to be written to a cell is too long, it is properly truncated and a valid xlsx file is generated without errors.
Go version
1.25.0
Excelize version or commit ID
2.9.1
Environment
macOS 15.5 / Excel for Mac 16.93.1 (25011917)
Windows 11 Home 24H / Excel 2508
Validations
Description
In Excel, both the 32,767-character cell limit and the 31-character sheet name limit are based on UTF-16 units. Since surrogate pairs count as two units, strings containing such characters may exceed these limits even if they appear shorter in rune length. In excelize, truncation is done by rune length, which can produce invalid files that trigger a “Problem with some content” alert in Excel.
Steps to reproduce the issue
Run the code above, then open the generated xlsx file in Excel.
Describe the results you received
“Problem with some content” alert in Excel.
Describe the results you expected
The expected result is that when the string to be written to a cell is too long, it is properly truncated and a valid xlsx file is generated without errors.
Go version
1.25.0
Excelize version or commit ID
2.9.1
Environment
macOS 15.5 / Excel for Mac 16.93.1 (25011917) Windows 11 Home 24H / Excel 2508Validations