网上找了xmind,https://github.com/zhuifengshen/xmind,可以创建xmind文件,但是带格式的作者没写。还有一个问题就是这个只能用xmind8打开,我用的xmind zen,打不开。网上搜索半天,找到https://blog.csdn.net/weixin_40105587/article/details/117557740,解决了文件打不开的问题。
然后研究格式的时候,本来打算修改源码看能不能行,试了下感觉太复杂了,换个思路,直接拷贝styles.xml文件,保存进去就可以了
extract(unzip_path, os.path.join(folder, zip_name))
shutil.copyfile(folder+"/META-INF/manifest.xml", os.path.join(inf_folder, "manifest.xml"))
#放入样式文件,新加了这一行
shutil.copyfile(folder + "/META-INF/styles.xml", os.path.join(unzip_path, "styles.xml"))
os.remove(os.path.join(folder, zip_name))
import xmind.core.const as const
# id写在styles文件里,直接设置节点的格式
style_id = '3f8h34qpk8c4hrv4o7vi0mrvp1'
sub_topic3.setAttribute(const.ATTR_STYLE_ID, style_id)
sub_topic4 = sub_topic3.addSubTopic()
sub_topic4.setTitle(case.get('case_expects'))
sub_topic4.setAttribute(const.ATTR_STYLE_ID, style_id)
<?xml version="1.0" encoding="utf-8" standalone="no"?><xmap-styles xmlns="urn:xmind:xmap:xmlns:style:2.0" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:svg="http://www.w3.org/2000/svg" version="2.0"><styles><style id="3f8h34qpk8c4hrv4o7vi0mrvp1" type="topic"><topic-properties fo:text-align="left"/></style></styles></xmap-styles>
格式我只需要一个左对齐,所以只设置了这一个,要其他格式,参照正常的xmind8 styles文件里设置就行了。