Sheetjs: Sheet names cannot exceed 31 chars

Created on 3 Nov 2017  路  4Comments  路  Source: SheetJS/sheetjs

I have a situation where some of my worksheet names exceed 31 characters. In this situation, it throws me the error Sheet names cannot exceed 31 chars.
It went through the code in the library and came through a function which throws the above error:
var badchars = "][*?\/\\".split(""); function check_ws_name(n, safe) { if(n.length > 31) { if(safe) return false; throw new Error("Sheet names cannot exceed 31 chars"); } var _good = true; badchars.forEach(function(c) { if(n.indexOf(c) == -1) return; if(!safe) throw new Error("Sheet name cannot contain : \\ / ? * [ ]"); _good = false; }); return _good; }

Is it worksheet names can't exceed 31 characters ? If this is the case, how can I allow worksheet names more than 31 characters for not throwing the above error ?

Most helpful comment

Q: SheetJS & Error: Sheet names cannot exceed 31 chars

image

A: my solution

just wrap the title and pass a short title for the sheetjs lib.

    const short_mock_title = `xgqfrms`;
    let result = ``;
    try {
        let elt = document.querySelector(uid),
            wb = XLSX.utils.table_to_book(
                elt,
                {
                    // sheet: title,
                    // fixed bug: error =  Error: Sheet names cannot exceed 31 chars
                    sheet: short_mock_title,
                }
            );
        if (debug) {
            console.log(`document.querySelector(uid) = `, elt);
        }
        result = XLSX.writeFile(
            wb,
            `${title}.${type}`,
            // true title name
        );
        return result;
    } catch (error) {
        console.log(`error = `, error);
    }

more details, seeing
https://www.cnblogs.com/xgqfrms/p/9920588.html

All 4 comments

That's an Excel limitation: https://support.office.com/en-us/article/Rename-a-worksheet-3F1F7148-EE83-404D-8EF0-9FF99FBAD1F9

IMPORTANT: Worksheet names cannot:

Contain more than 31 characters.

Contain any of the following characters: / \ ? * : [ ]

@reviewher - That means we can't do anything with Excel limitations.

Q: SheetJS & Error: Sheet names cannot exceed 31 chars

image

A: my solution

just wrap the title and pass a short title for the sheetjs lib.

    const short_mock_title = `xgqfrms`;
    let result = ``;
    try {
        let elt = document.querySelector(uid),
            wb = XLSX.utils.table_to_book(
                elt,
                {
                    // sheet: title,
                    // fixed bug: error =  Error: Sheet names cannot exceed 31 chars
                    sheet: short_mock_title,
                }
            );
        if (debug) {
            console.log(`document.querySelector(uid) = `, elt);
        }
        result = XLSX.writeFile(
            wb,
            `${title}.${type}`,
            // true title name
        );
        return result;
    } catch (error) {
        console.log(`error = `, error);
    }

more details, seeing
https://www.cnblogs.com/xgqfrms/p/9920588.html

Was this page helpful?
0 / 5 - 0 ratings

Related issues

seanmcilvenna picture seanmcilvenna  路  3Comments

eyalcohen4 picture eyalcohen4  路  3Comments

sangpuion picture sangpuion  路  3Comments

magtuan picture magtuan  路  3Comments

m-ketan picture m-ketan  路  3Comments