[Flex] As3xls read Excel, modify Save single table (ii)

Source: Internet
Author: User
Tags addchild

This method only uses the As3xls to read Excel's function, the modification saves independently.

<?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="Initviews (event)"Width="1024x768"height="+"> <fx:Script> <![cdata[ImportCom.as3xls.xls.ExcelFile; ImportCom.as3xls.xls.Sheet; Importmx.events.FlexEvent; Private var_headerarr:array = []; Private var_dataarr:array = []; ProtectedfunctionInitviews (event:flexevent):void            {                varFile:file =NewFile ("e:/as/examples/readandsaveexcel/src/-like table. xls"); //Read File                varStream:filestream =NewFileStream ();                Stream.open (File,filemode.read); varBa:bytearray =NewByteArray ();                Stream.readbytes (BA);                                Stream.Close (); varXls:excelfile =NewExcelfile ();                Xls.loadfrombytearray (BA);                Trace (xls.sheets.length); varSheet:sheet = xls.sheets[1]; varRowlen:int =sheet.rows; varCloumnlen:int =Sheet.cols; //Trace (Sheet.getcell (0,0). Value,sheet.getcell (0,1). Value,sheet.getcell (2,0). value);Trace (Rowlen,cloumnlen);  for(varI:int = 0;i<cloumnlen;i++) {_headerarr.push (Sheet.getcell (0, i). value); }                 for(varJ:int = 0;j<_headerarr.length;j++){                    varTitle:textfield = GetText (120,20, _headerarr[j]); Title.x= j*120+100; Title.y=0;                Container.addchild (title); }                                 for(j = 1;j<rowlen;j++){                    if(Sheet.getcell (j,i). Value = =""){                        //trace ("null");}Else{                                            }                    varObj:Object= {};  for(i = 0;i<_headerarr.length;i++){                        if(i = = 3) {Obj[_headerarr[i]]= Math.floor (Math.random () *2000). toString (); }Else{Obj[_headerarr[i]]=Sheet.getcell (j,i). value;                    }} _dataarr.push (obj); varCount:int = 0;  for(varN:int = 0;n<_headerarr.length;n++){                        varT:textfield = GetText (120,20, Obj[_headerarr[n]]); T.x= 120*count+100; T.y= 20*J; Count++;                    Container.addchild (t); } }} protectedfunctionSavebtn_clickhandler (event:mouseevent):void{Save (_dataarr,_headerarr,_headerarr); }            Private functionSave (Datas:array,headerarr:array,objarr:array):void            {                varXlsstr:string ="; Xlsstr+="<tr>";  foreachvarFieldhead:stringinchHeaderarr) {Xlsstr+="<td>"+ Fieldhead +"</td>"; } xlsstr+="</tr>";  foreachvarItemObject inchdatas) {Xlsstr+="<tr>";  foreachvarField:stringinchObjarr) {Xlsstr+="<td>"+ Item[field] +"</td>"; } xlsstr+="</tr>"; } xlsstr+="</table></body>; varBytes:bytearray =NewByteArray (); //bytes.writeutfbytes (XLSSTR);Bytes.writemultibyte (XLSSTR,"GB2312"); NewFilereference (). Save (Bytes,"Data.xlsx"); //use file to achieve the same effect without popping the Save dialog box                /*var file:file = File.desktopDirectory.resolvePath ("Data.xls");                var fs:filestream = new FileStream ();                Fs.open (file, Flash.filesystem.FileMode.WRITE);                Fs.writemultibyte (Xlsstr, "GB2312"); Fs.close ();*/            }                        Private functionGetText (w: NumberH: Number, text:string): TextField {varT:textfield =NewTextField (); T.width=W; T.height=h; //t.autosize = "center";T.selectable =false; T.border=true; T.text=text; returnT; }        ]]> </Fx:script> <fx:Declarations> <!--put non-visual elements (such as services, value objects) here--</Fx:declarations> <s:scroller width=" the"height=" the"> <s:group width="100%"height="100%"> <mx:uicomponent id="Container"Width=" the"height="100%"/> </S:group> </S:scroller> <s:button id="SAVEBTN"Label="Save"left="910"top="Ten"click="Savebtn_clickhandler (event)"> </s:button></S:windowedapplication>

[Flex] As3xls read Excel, modify Save single table (ii)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.