Edit RTF file using Python

二次信任 提交于 2021-01-27 13:19:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!