Read and write Excel files in Flex [Flex]

Have you ever thought about this possibility? Well this is it: as3xls is a cool library that enables you to import and export xls and CSV files. It can be extremely useful to your needs!

Here some little tutorials.

Here the examples (google code link is broken!).

And here and other version of the same lib, but in this one there’s a fix for the number of rows you can import. I highly suggest you to use this one then otherwise you’ll get stuck after just some thousands… ;)

Hopefully I’ll post some personal examples soon.

Happy coding!

Comments

  1. Timmy says:

    Hi,
    I am using as3xls library in my air application to read and write data to Excel file.
    I facing an issue.I am able to read an excel and in my application i will display the data so numbers to textinputs.I will modify those textinput and when i click on a button i need to update the same excel file which i read.I am bale to update the excel only one sheet. Now i try to read the same excel file which got modified now, i am getting null objetc reference errror.

    Please help me, my code given below
    Code:
    import com.as3xls.xls.ExcelFile;
    import com.as3xls.xls.Sheet;

    private function onReadButtonClick():void
    {
    var file:File = File.desktopDirectory;
    file = file.resolvePath(“test.xls”);
    var myFileStream:FileStream = new FileStream();
    myFileStream.open(file, FileMode.READ);

    var byteArray:ByteArray = new ByteArray();
    myFileStream.readBytes( byteArray, 0, 0);

    var excelFile:ExcelFile = new ExcelFile();
    excelFile.loadFromByteArray(byteArray);

    sheet0 = excelFile.sheets[0];

    myFileStream.close();

    txtAbout.text = sheet0.values[0];
    txtCost.text = sheet0.values[2][1].value;
    }

    private function btnUpdate_clickHandler(event:MouseEvent):void
    {
    sheet0.setCell(0,0,txtAbout.text);
    sheet0.setCell(2,1,txtCost.text);

    var xls:ExcelFile = new ExcelFile();
    xls.sheets.addItem(sheet0);
    var bytes:ByteArray = xls.saveToByteArray();

    var file:File = File.desktopDirectory;

    file = file.resolvePath(“test.xls”);
    var myFileStream:FileStream = new FileStream();
    myFileStream.open(file, FileMode.UPDATE);
    myFileStream.writeBytes(bytes);
    myFileStream.close();
    }

  2. Kavya says:

    Does someone has any idea on how to delete a row from the excel using flex.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>