[Flex] as3xls读取excel,修改保存单表(一)
2015-11-10 11:23
369 查看
经过大神修改过的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>
相关文章推荐
- naive-bayesian-朴素贝叶斯
- HDU 3081 并查集 二分枚举 最大流
- 2015求职经历
- spring mvc @PathVariable绑定URI模板变量值
- Python - 开发环境Vim设置
- Ubuntu14.04编译Allwinner lichee 两个出错解决方法
- iOS_CoreFoundation_汉字转换拼音的实现
- 启动mysql服务,提示1067
- Yii2 数据操作Query Builder
- 3.UiObejct API 详细介绍
- poj 1113 Wall (凸包模板题)
- 深入PHP内核之in_array
- 源码编译安装percona-xtrabackup-2.3.2
- Linux软件raid删除
- POI检索
- 内存管理
- 微信开发获取用户信息的时候提示redirect_uri参数错误
- UWP xaml 圆形头像
- The current branch is not configured for pull No value for key branch.master.merge found in config
- Jedit 设置