natergj / excel4node

Node module to allow for easy Excel file creation
MIT License
1.38k stars 215 forks source link

Parsing fails when string contains emojis #75

Open bhuvanaurora opened 8 years ago

amekkawi commented 8 years ago

Can you provide a gist that reproduces this issue? Thanks!

mschnee commented 6 years ago
const workbook = new excel.Workbook();
const worksheet = workbook.addWorksheet('Sheet 1');
worksheet.cell(1, 1).string('😂');
workbook.writeToBuffer();
Invalid Character for XML "�" in string "😂"

This is caused by stringSetter in source/lib/cell/index.js

    let chars, chr;
    chars = /[\u0000-\u0008\u000B-\u000C\u000E-\u001F\uD800-\uDFFF\uFFFE-\uFFFF]/;
    chr = val.match(chars);
    if (chr) {
        logger.warn('Invalid Character for XML "' + chr + '" in string "' + val + '"');
        val = val.replace(chr, '');
    }