online cheap medications order generic bactrim price, and buy cheap online buy cheap discount lasix, and cheap pharmacy lipitor without rx, and online ordering accutane review, and order cheap how much acyclovir to kill, and buy cheapest synthroid order online, and pharmacy cheapest cheap baclofen pill, and order online directions for taking clomid, and online cheap medications cheap hydrochlorothiazide without rx, and cheap pharmacy purchase amoxil cod overnight delivery, and cheap pharmacy arimidex online overnight, and buy cheap online buy buy zithromax pill online, and order online online valtrex prescription in utah, and buy cheapest buy cheap discount online flagyl, and buy online zovirax (acyclovir) cheapest, and buy cheap how to buy prozac online without a rx, and cheap pharmacy cash on delivery paxil, and cheap pharmacy diflucan cod delivery next day, and purchase no prescription propecia cancer prevention, and generic medications neurontin and online overnight delivery, and purchase no prescription norvasc fedex shipping, and online ordering purchase doxycycline next day cod, and ordering online feminizing effects of premarin, and buy cheap online buspar and wellbutrin, and online cheap medications order overnight retin-a, and

CSV Export with AlivePDF

Just a quick update done in AlivePDF this morning, some people requested CSV export through the Grid class, so here it is :)

The API is really simple :

// export the grid content as a CSV
var bytes:ByteArray = grid.export( Export.CSV );

And voilà!, all you have to do is save this ByteArray as a .csv file, just like you do with the PDF ByteArray and you'll get a file like this.

Just import it in Microsoft Excel and you'll get a nice table :)

Note that the Grid.columns property has to be set to enable CSV export. Column order has to be preserved in the CSV exported and is provided this way, through a GridColumn array :

// create columns to specify the column order
var gridColumnAge:GridColumn = new GridColumn("City", "city", 20, Align.LEFT, Align.LEFT);
var gridColumnEmail:GridColumn = new GridColumn("E-Mail", "email", 20, Align.LEFT, Align.LEFT);
var gridColumnFirstName:GridColumn = new GridColumn("First Name", "firstName", 40, Align.LEFT, Align.LEFT);
var gridColumnLastName:GridColumn = new GridColumn("Last Name", "lastName", 45, Align.LEFT, Align.LEFT);

// create a columns Array
// it determines the order shown in the PDF
var columns:Array = new Array ( gridColumnAge, gridColumnEmail, gridColumnFirstName, gridColumnLastName );

// create a Grid object as usual
var grid:Grid = new Grid( dp.toArray(), 200, 120, new RGBColor ( 0xCCCCCC ), new RGBColor (0xFFFFFF), new RGBColor (0xFFFFFF), true, new RGBColor(0x000000) );

// pass the columns
grid.columns = columns;

// add a page

// styling
p.textStyle( new RGBColor(0), 1 );
p.setFont ( new CoreFont ( FontFamily.HELVETICA ) );

// add the grid
p.addGrid( grid );

// export the grid content as a CSV
var bytes:ByteArray = grid.export( Export.CSV );

If column order is changing at runtime, you can just loop over the DataGrid.columns array and recreate an appropriate columns array (GridColumn) and set it again to the Grid.columns property.

You can find this feature in the latest AlivePDF version on SVN.

Comments 22

  1. Lance Wilcox wrote:

    Great work! This is really, really helpful to me.

    One slight enhancement to CSVExport class: Change delimiter to “,” (instead of “;”) so that the data can be arranged in columns in Excel. (CSV files are comma delimited, not semi-colon delimited.)

    Again, great, great work on all this.

    Posted 26 Aug 2009 at 10:42 pm
  2. Thibault Imbert wrote:

    Hi Lance,

    Happy to hear you like it :)

    Good idea for the delimiter, I will add a way to specify manually the delimiter so that you guys can change it really easily when needed.



    Posted 27 Aug 2009 at 8:30 am
  3. dada wrote:

    Hello Thibault,

    Thanks for this package. :)

    Just one thing : I’m using FDT under Linux, and I had a parse error in cause of this at line 3455 :
    var month:*= myDate.getMonth()…

    FDT thinks “*=” is the operator.

    FDT needs a space here to parse it correctly :
    var month:*= myDate.getMonth()…

    Maybe this little modification can save some minutes to FDT users. :-)

    Thanks again.

    Posted 08 Sep 2009 at 12:22 pm
  4. dada wrote:

    Edit :

    FDT needs a space here to parse it correctly :
    var month:* = myDate.getMonth()…

    Posted 08 Sep 2009 at 12:23 pm
  5. Thibault Imbert wrote:

    Hi dada,

    Thanks for the fix, I will update that right now !


    Posted 08 Sep 2009 at 8:16 pm
  6. Joel wrote:

    How do I make sure the column headers are exported to the csv?

    Posted 09 Sep 2009 at 10:29 pm
  7. Joel wrote:

    I have added a loop of the columns inside the CSVExport class’ serialize() function to make sure the column header text is appended to the first row of the file. Thanks, this is a nice API to work with.

    Posted 09 Sep 2009 at 11:03 pm
  8. Jonas357 wrote:

    What package to import for “Export.CSV” ?

    Posted 21 Sep 2009 at 9:29 am
  9. Jonas357 wrote:

    It is a Beta release that can be found in the SVN repository for now…

    Posted 21 Sep 2009 at 10:04 am
  10. Beto wrote:

    I’ve been trying CSV Export, and it works really good, but there is a problem when the user open the CSV document in Excel, and the data contains accents or “ñ”.

    ex: data: BEGOÑA -> excel show: BEGOÑA

    (Note: Onening the generated csv in notepad works OK)

    Anyone know if it’s possible to generate a XSL
    file directly from ALIVEPDF in a similar way that CSV is generated?

    Thanks in advance.

    Posted 19 Oct 2009 at 4:22 pm
  11. Nathan wrote:

    Love this feature! However, My grid does not start at the top of the page when it starts. When there is more data that one page can handle it (like it should) spills over to the next page!!!
    But, thats where the problem starts. The next part starts at the same place on the page that the first part started at. I need it to start at the top of the page on the continuing pages.

    Posted 11 Nov 2009 at 3:33 am
  12. Chris wrote:

    Is there a Comma ” , ” fix to the Semicolon ” ; ” issue yet? This API looks really great but I need the data to open in different coumns in Excel (which doesnt work with Semicolons)


    Posted 22 Mar 2010 at 6:06 pm
  13. Mike Marcavage wrote:

    I am new to Flex and alivePDF.
    I am not able to get this sample working?
    can someone provide a complete working sample PLEASE!!!!

    Posted 29 Mar 2010 at 3:56 pm
  14. Raj wrote:

    Hi Thibault Imbert,

    I’m generating a pdf. Everything is fine. But i’m tyring to create a grid that is similar in look to my datagrid in application, which has different column colors, like few columns have gary color and other columns have cyan color. I tried to extend GridColumn class and build my custom derived class but seems like this base class is declared final. Is there a way to address my goal. Will Alivepdf generate uniform styled grid??


    Posted 04 May 2010 at 8:59 pm
  15. Samrat wrote:

    Hi Thibault Imbert Sir,

    I need to export my Flex datagrid to excel.So kindly do something for this.Right now I am using your AlivePdf for pdf export and It’s really very cool. very very thanks to you for such a nice work.

    Posted 07 Jun 2010 at 12:45 pm
  16. Thibault Imbert wrote:

    Hi Samrat,

    Great to hear you use it and find it useful!



    Posted 08 Jun 2010 at 6:32 am
  17. Khadeer wrote:

    Hi I want to Export the Contents of Flex to Excel it may be CSV or XLS. can I implement the above solution?

    Also i need to export the Datagrid with Background colors form Flex to CSV or XLS

    Can you provide some samples

    Thanks in Advance

    Posted 22 Jul 2010 at 2:00 pm
  18. Vijay Dixon wrote:


    to make sure the header is also added to CSV i added something like this

    // My modification to add header field
    for each (var c:GridColumn in _columns)
    buffer += c.headerText + delimiter;
    buffer += “\n”;

    Just before adding other stuff(before the for each loop) in the CSVExport’s serialize() function

    Posted 12 Aug 2010 at 12:20 pm
  19. John wrote:

    I’m trying to export a CSV from Flash (Player version 9) to the browser for download with AlivePDF. I got what was written in the example but I don’t understand how do you save the ByteArray as a .csv file… Can anyone shed some light?

    Posted 07 Oct 2010 at 12:02 pm
  20. jeff spicer wrote:

    if the first column has null data, a needed semicolon is omitted. if the data is {address: “”, id: 1234, name: joe}, then the resultant csv data will be
    instead of

    Posted 18 Oct 2012 at 1:41 am
  21. jeff spicer wrote:

    i think it’s in, line 37:

    line += line.length > 0 ? delimiter+field : field;

    (feel free to erase this extra comment. if i find a fix, i’ll send it)

    Posted 18 Oct 2012 at 1:47 am
  22. jeff spicer wrote:

    i believe this works for, line 37:
    line += i < lng – 1 ? field + delimiter : field;

    (adding field+delimiter instead of delimiter+field and omitting the final delimiter)

    Posted 18 Oct 2012 at 2:02 am

Post a Comment

Your email is never published nor shared. Required fields are marked *