我正在尝试使用AIR应用程序中的as3xls库将一些xliff转换文件整理到一个XLS文件中。我可以成功地将所有数据加载,解析和组合成文档,除了希腊语内容主要显示为问号(???)而不是正确的字符集。下面我列出了编写电子表格的方法,以及将文件写入本地磁盘。
private function enumerateTranslations ():void
{
var key:String;
var j:int;
var en:String;
var tx:String;
var txBytes:ByteArray;
var cell:Cell;
_sheet.setCell(0, 0, "English, US (en)");
for(var i:int = 0; i < _sortedKeyList.length; i++)
{
j = 1;
key = _sortedKeyList[i];
_currentSource = _sources[key];
_sheet.setCell(0, i + 1, key);
for(var prop:String in _currentSource)
{
var charsetA:String = "ISO 8859-7";
var charsetB:String = "ISO 3166-1";
var charsetC:String = "Windows-1253";
en = removeTags(prop);
tx = removeTags(_currentSource[prop]);
txBytes = new ByteArray();
// Writes almost successful data, with charset control
//txBytes.writeMultiByte(tx, charsetA);
// Writes almost successful data
//txBytes.writeUTFBytes(tx);
// Does nothing useful
//txBytes.writeObject(tx);
// Writes prepending byte-length word, rotates entire table, very bad
//txBytes.writeUTF(tx);
// Writes low-level literal 8-bit gibberish
/*
for(var k:int = 0; k < tx.length; k++)
{
txBytes.writeByte(tx.charCodeAt(k));
}
*/
cell = _sheet.getCell(j, 0);
cell.value = en;
cell = _sheet.getCell(j, i + 1);
cell.value = tx;
//_sheet.setCell(j, 0, en);
//_sheet.setCell(j, i + 1, txBytes);
if(key == "de" || key == "da" || key == "el")
{
trace(txBytes);
}
j++;
}
}
_table.sheets.addItem(_sheet);
}
private function writeExcelDocumentToLocalVolume (useStream:Boolean = false):void
{
var fileBytes:ByteArray = _table.saveToByteArray();
if(_file != null)
{
_file = null;
}
if(useStream == true)
{
try
{
_file = new File(_folderURI + _archiveName + ".xls");
var fs:FileStream = new FileStream();
fs.open(_file, FileMode.WRITE);
fs.writeBytes(fileBytes);
fs.close();
showOutputSuccessfulMessage();
}
catch ( err:Error )
{
showOutputErrorMessage(err.message + "\n\n" + err.getStackTrace().substr(0, 512));
}
}
else
{
_file = new File(_folderURI);
_file.save(fileBytes, _archiveName + ".xls");
}
}