Writing to CSV file in AS3

半腔热情 提交于 2019-12-25 06:29:19

问题


I have looked far and wide but I can't find any resources on how to write to CSV files from flash AS3. I know that flash cannot write to it alone. I have used PHP before to write to a txt file but now I need to open a csv and insert/edit entries that are already in it.

How can I do this?


回答1:


There is no built in support for CSV, although it can be done manually:

//dummy data
var data:Array = [];
for(var i:int = 0 ; i < 100 ; i++) data[i] = {a:Math.random() * 100,b:Math.random() * 100,c:Math.random()};
//make a csv string
var csv:String = '';
for(i = 0 ; i < 100 ; i++) csv += data[i].a + ',' + data[i].b + ',' + data[i].c+'\n';
//write to disk
stage.doubleClickEnabled = true;
stage.addEventListener(MouseEvent.DOUBLE_CLICK,writeCSV);
function writeCSV(event:MouseEvent) {
    var file:FileReference = new FileReference();
    var bytes:ByteArray = new ByteArray();
    bytes.writeUTFBytes(csv);
    file.save(bytes,'test.csv');
}

Still, there is an as3 csv library out there.

I need to open a csv and insert/edit entries that are already in it.

Have a look at Data functions and manipulations on the csvlib wiki.

HTH



来源:https://stackoverflow.com/questions/7316416/writing-to-csv-file-in-as3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!