Converting CSV/Excel data to Doctrine YAML fixtures

I had done some research on this topic and found that some script was available in Python. With no knowledge of Python execution, I sought help from stackoverflow & got the answer there pointed to the same Python script 🙁 I decided I had to do something on my own! Ensuring the right no of spaces in the YAML could be a real pain – I haven’t found the error messages to be very friendly.

My challenge was to be able to generate a YAML for a table/schema using the nested-set behaviour in Doctrine. Instead of losing my mind on devising a human-readable format, I reverse engineered. I checked the resulting schema in the database and used that as the base for my CSV. Following this I wrote a simple macro that will output in the required format. This has evolved over a week or so, and has been thoroughly tested. I am sharing this file with 2 examples: one for the JobeetJob schema & other from the Hierarchical Data page on Doctrine.

Let me know if this helps! Vote for the answer on StackOverflow.

To start using:

  1. Download the ZIP file CSV/Excel to YAML Generator v2 & unzip it.
  2. Change the model name
  3. If you need an explicit ‘NestedSet: true‘ declaration, then set NestedSet? cell to ‘Y‘ or ‘true
  4. If you wish to add any PHP scripts at the beginning and end of data, you can paste it in the respective cells. I often use this to loop for a number of tenants.
  5. Specify the sheet where you want the output to the generated.
    If an invalid or empty sheet name is specified, data is printed to the “Output” sheet. Hence, do not delete it.
  6. Replace the column names for your model, starting from the 3rd column.
  7. Start entering your data
  8. Please don’t forget the 2 ‘end‘ markers to mark the end of columns & rows.
  9. Press the ‘Generate‘ button
  10. Copy the data and paste it into the fixtures.yml file

Additional information:

  1. 1st column (level) denotes the level in the nested-set. When using for flat structures, set level = 0 (zero) for all records.
  2. 2nd column is the key, that you define for every record in the fixture. This is not saved 🙂
  3. Again, please don’t forget the 2 ‘end‘ markers to mark the end of columns & rows.
  4. If you need to convert data for more than one model, simply ‘Copy’ the worksheet. As long as it caries the ‘Generate‘ button, the macro will intelligently output the data.
  5. After you press the ‘Generate‘ button, existing data is first deleted – so don’t take the extra pain.
  6. Data types are not handled in any way! So if your column is formatted as a date in some non-standard format, the macro will print it as is 🙁
  7. To enter dates, you might need an extra tick to escape the first one. So ”2004-10-09′ will output ‘2004-10-09’


  • Data from all sheets should be printed at once.

If you need any more features, feel free to ask for it OR develop & share.


None, just focus on using & improving it 🙂


  • If you host this file elsewhere, please post a link as a Comment on this page; it will help others!
  • Also, if someone can move the macro to OpenOffice, this will be truly OpenSource 🙂
  • If this helps, Vote for the answer on StackOverflow.

PS: This is my first real technology post 🙂

6 thoughts on “Converting CSV/Excel data to Doctrine YAML fixtures”

  1. dear sir, its really aweson, but i need to do custom style like adding data in ur sheet and convert to fixtures (YAML) , is this possible, please let me know.

  2. and i am excepting output is like this (Could you please send a new excel macro file dude)

    [type:’Miscellaneous Query – Site’, comments:’Automation Test Query’],
    [type:’To:’, name:’Automation’, faxnum:’1-555-555-1212′]
    [type:’Missing Test Transfer’, comments:’Automation Test Query’],
    [type:’To:’, name:’Remove_Me’, faxnum:’1-555-555-1212′]

Comments are closed.