问题
Maybe this is a dumb question, but I don't get it so appologize :)
I have an RTF document, and I want to change it. E.g. there is a table, I want to duplicate a row and change the text in the second row in my code in an object-oriented way.
I think pyparsing should be the way to go, but I'm fiddling around for hours and don't get it. I'm providing no example code because it's all nonsense I think :/
Am I on the right path or is there a better approach?
Anyone did something like that before?
回答1:
RTFs are text documents with special "symbols" to create the formatting. (see - http://search.cpan.org/~sburke/RTF-Writer/lib/RTF/Cookbook.pod#RTF_Document_Structure It seems that perl has a good RTF library though), so yes, PyParsing is a good way to go. You have to learn the structure and then parse (there are perl code examples in the page i mentioned. If you are lucky you can translate them in python with some effort)
There is a basic RTF module available for python. Check - http://pyrtf.sourceforge.net/
Hope that helps you a little.
来源:https://stackoverflow.com/questions/11899328/edit-rtf-file-using-python