1

I am using as3xls library to export data tables to excel sheet in my flex application. My application is multilingual which contains utf-8 characters.

can anybody help me how to include utf-8 characters in my excel sheet?

The answer of Splash works undoubtedly when accessing the application in firefox and chrome but does not work on Safari.

Abhishek Jain
  • 356
  • 1
  • 3
  • 15

1 Answers1

1

UTF-8 encoding is not supported by the current implementation of as3xls. The saveToByteArray function uses a BIFF2 (Excel 2.x) stream for encoding which doesn't support UTF-8.

All Excel file formats up to BIFF5 contain simple byte strings. The byte string consists of the length of the string followed by the character array. ... The encoding of the character array is dependent on the current record, for example taken from the CODEPAGE record.

A quick-fix could be to change the saveToByteArray() function in ExcelFile.as to

public function saveToByteArray(codePageID: int, charSet: String):ByteArray 

Add these lines after br.writeTag(bof);

if (codePageID > 0)
{
    var codePage:Record = new Record(Type.CODEPAGE);
    codePage.data.writeShort(codePageID);
    br.writeTag(codePage);
}

and change cell.data.writeUTFBytes(value); to cell.data.writeMultiByte(value, charSet);

This way you can adjust the character set to your needs.

var xls:ExcelFile = new ExcelFile();
...
// write xls with cyrillic characters
var bytes:ByteArray = xls.saveToByteArray(28595, "iso-8859-5"); 

Further reading:

splash
  • 13,037
  • 1
  • 44
  • 67