Skip to content

Issue with cell character count limitation #2205

Description

@torotake

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.

Image

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

  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • The provided reproduction is a minimal reproducible example of the bug.

Activity

  1. added
    bugSomething isn't working
    on Sep 1, 2025
  2. added theissue type on Sep 1, 2025
  3. moved this to Bugfix in Excelize v2.10.0on Sep 1, 2025
  4. added a commit that references this issue on Sep 1, 2025
    2e1d05f
  5. added a commit that references this issue on Jun 15, 2026
    e1808fb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions