标签:
经过大神修改过的as3xls支持中文,并可以修改保存单一sheet,保存后原有的excel样式均会消失,目前仅能如此。
<?xml version="1.0" encoding="utf-8"?> <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" creationComplete="windowedapplication1_creationCompleteHandler(event)"> <fx:Script> <![CDATA[ import com.as3xls.xls.ExcelFile; import com.as3xls.xls.Sheet; import mx.events.FlexEvent; private var _mbytes:ByteArray; private var _excelFile:ExcelFile; private var _sheet:Sheet; private var _xls:ExcelFile; protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void { var file:File = new File("E:/AS/Examples/ReadExcel/src/样表.xls"); //读取文件 var stream:FileStream = new FileStream(); stream.open(file,FileMode.READ); var ba:ByteArray = new ByteArray(); stream.readBytes(ba); stream.close(); _xls = new ExcelFile(); _xls.loadFromByteArray(ba); var sheet:Sheet = _xls.sheets[1]; var rows:int = sheet.rows; trace(rows); trace(sheet.getCell(0,0)); //修改表值 for(var i:int = 1;i<rows;i++){ sheet.setCell(i,3,Math.floor(Math.random()*2000).toString()); } } private function saveData():void { //写文件 _mbytes = _xls.saveToByteArray(1,"GB2312");//目前只能保存单个sheet数据 var file:File = File.desktopDirectory.resolvePath("data.xls"); var fs:FileStream = new FileStream(); fs.open(file, flash.filesystem.FileMode.WRITE); fs.writeBytes(_mbytes); fs.close(); } protected function saveBtn_clickHandler(event:MouseEvent):void { saveData(); } ]]> </fx:Script> <fx:Declarations> <!-- 将非可视元素(例如服务、值对象)放在此处 --> </fx:Declarations> <s:Button id="saveBtn" label="保存" left="10" top="10" click="saveBtn_clickHandler(event)"> </s:Button> </s:WindowedApplication>
[Flex] as3xls读取excel,修改保存单表(一)
标签:
原文地址:http://www.cnblogs.com/frost-yen/p/4952328.html