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:
- Download the ZIP file CSV/Excel to YAML Generator v2 & unzip it.
- Change the model name
- If you need an explicit ‘NestedSet: true‘ declaration, then set NestedSet? cell to ‘Y‘ or ‘true‘
- 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.
- 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. - Replace the column names for your model, starting from the 3rd column.
- Start entering your data
- Please don’t forget the 2 ‘end‘ markers to mark the end of columns & rows.
- Press the ‘Generate‘ button
- Copy the data and paste it into the fixtures.yml file
Additional information:
- 1st column (level) denotes the level in the nested-set. When using for flat structures, set level = 0 (zero) for all records.
- 2nd column is the key, that you define for every record in the fixture. This is not saved 🙂
- Again, please don’t forget the 2 ‘end‘ markers to mark the end of columns & rows.
- 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.
- After you press the ‘Generate‘ button, existing data is first deleted – so don’t take the extra pain.
- 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 🙁
- To enter dates, you might need an extra tick to escape the first one. So ”2004-10-09′ will output ‘2004-10-09’
Roadmap:
- Data from all sheets should be printed at once.
If you need any more features, feel free to ask for it OR develop & share.
License:
None, just focus on using & improving it 🙂
Request:
- 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 🙂
Mirror: http://www.box.net/shared/8alqsfzc1o
great work………..!
awesom awesome awesome awesome!
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.
Yes, you will have to edit the Macro
and i am excepting output is like this (Could you please send a new excel macro file dude)
fixtures1=[
query1:[
query:
[type:’Miscellaneous Query – Site’, comments:’Automation Test Query’],
recipient:
[type:’To:’, name:’Automation’, faxnum:’1-555-555-1212′]
],
query2:[
query:
[type:’Missing Test Transfer’, comments:’Automation Test Query’],
recipient:
[type:’To:’, name:’Remove_Me’, faxnum:’1-555-555-1212′]
]
]