问题
I want to create a flowchart in OpenOffice Draw.
Since there's a lot of steps to show (and may change in future) but I can extract the data, I want to automate the creation with the following steps:
- Create a new ODG document with specified page settings.
- Insert flow chart shapes with specified properties.
- Connect those things with arrows.
- Ideally, auto-organise things into sensible positions.
I don't want to spend hours reading about some "UNO" thing - I just want code examples that I can adapt as required.
Not bothered if the example code uses the OO API, or just modify XML files inside a zipped template - so long as it lets me do the above things easily enough.
I'm doing this with Railo (CFML), but I can also work with Java, or convert snippets from other readable languages.
Any suggestions how to go about this?
Update:
I've started playing with the XML route - I saved an empty file, and a file with a single object, and compared the two (treating as zips) to see the difference, then repeated a few times with different changes to help understand what's going on.
I have some very basic (and incomplete) code which can create shapes and connect them, which can be seen here: http://gist.github.com/634306
It's very crude, but I can probably work out a way to use what I've got now to produce what I need - but I'm still hoping that someone can point me towards a better way of doing this - particularly since I'll need to figure out some way of positioning the shapes appropriately, which wont be trivial.
I've created a distinct question for this fourth point:
How do I auto-layout boxes on a flowchart?
Update 2:
From that other question, I have discovered GraphViz which can visualise graphs from data - and I've created a 'digraph' from my data - so all I need is a way to convert the output of GraphViz into something which OpenOffice Draw can accept. The obvious thought there would be SVG, but it seems OpenOffice hasn't implemented SVG properly yet, so I need to come up with another plan.
回答1:
You could try api.openoffice.org. Let me know how that worked out for you.
回答2:
You can checkout my post about how to create an OO Spreadsheet. The example is .NET but should be easily portable to Java. I haven't done it before but I would assume that you can replace writer8
with draw8
to access the OpenOffice Draw engine instead of the spreadsheet engine. If you have successfully created a Spreadsheet that way, then you can checkout the API about how to add Shapes and Figures.
来源:https://stackoverflow.com/questions/3961734/how-do-i-generate-an-openoffice-draw-document