如何配置PyCharm以开发LibreOffice Python宏? [英] How to configure PyCharm to develop LibreOffice Python macros?

查看:85
本文介绍了如何配置PyCharm以开发LibreOffice Python宏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为我的所有Python项目在Win7(x64)中默认安装了Python 3.5.1.

我使用PyCharm 5.0.5社区版来开发Python脚本,其默认设置将默认项目解释器"设置为"3.5.1(C:\ Python35 \ python.exe)"

在我的工作中,我们正在从MS Office 2007/2010迁移到LibreOffice-5.尽管我对VB并不热衷,但我还是在VBA中编写了一些宏.Basic缺少良好的数据结构,例如列表(我喜欢列表理解),字典,集合和元组.因此,我想重写LibreOffice-5 Python脚本宏中的VBA宏.

LibreOffice-5安装在3.3.5版的"C:\ Program Files(x86)\ LibreOffice 5 \ program" 中具有自己的嵌入式Python.LibreOffice-5安装中的Python脚本位于:

  • Libre Office宏;"C:\ Program Files(x86)\ LibreOffice 5 \ share \ Scripts \ python"
  • 我的宏;"C:\ Users \ trimax \ AppData \ Roaming \ LibreOffice \ 4 \ user \ Scripts \ python"

问题很简单:
我需要配置PyCharm设置,以使用嵌入式python版本开发LibreOffice宏的python脚本.我不知道我是否需要设置虚拟环境,或者是否只能设置项目解释器.

顺便问一下,是否有任何方法可以在文档中插入宏,并与VBA项目模块一起与文档共享?

解决方案

来自

它在 com 导入语句下划线,尽管它实际上不是错误.PyCharm确实可以识别其他声明,例如 uno.Any .

要运行,请转到 Run->运行.它运行成功,并按预期打印了结果.

我通常只使用文本编辑器来代替IDE.从我所看到的来看,许多IDE工具(语法突出显示,自动完成,调试)无论如何都不能与UNO一起很好地工作.使用Java会更好,但这是一个不同的话题.

顺便问一下,是否有任何方法可以在文档中插入宏以与文档[...]共享?

要将Python代码嵌入文档中,请解压缩.odt文件,然后按照说明这里.

I've installed Python 3.5.1 as default in Win7(x64) for all my projects in Python.

I use PyCharm 5.0.5 community edition for develop Python scripts and its default settings has "Default Project Interpreter" as "3.5.1 (C:\Python35\python.exe)"

At my work we are migrating from MS Office 2007/2010 to LibreOffice-5. I wrote some macros in VBA, despite of I'm not a VB enthusiastic. Basic lacks good data structures, such as lists (I love list comprehensions), dictionaries, sets and tuples. So, I want to rewrite the VBA macros in LibreOffice-5 Python script macros.

LibreOffice-5 installation has its own embebed Python at "C:\Program Files (x86)\LibreOffice 5\program", version 3.3.5. Scripts of Python in LibreOffice-5 installation is at :

  • Libre Office Macros; "C:\Program Files (x86)\LibreOffice 5\share\Scripts\python"
  • My Macros; "C:\Users\trimax\AppData\Roaming\LibreOffice\4\user\Scripts\python"

The question is simple:
I need configure PyCharm settings to develop the python scripts of LibreOffice macros with the embebed python version. I don't know if I need to set a virtual environment or if I can just to set the Project Interpreter.

By the way, are there any method to insert macros in the document, to share it with the document, as the VBA Project Modules?

解决方案

From the PyCharm documentation, it sounds like you could use a virtual environment to target LibreOffice (likely Python 3) and OpenOffice (likely Python 2) in two different projects. Otherwise it looks like a local interpreter is enough.

To test PyCharm, I did the following:

  1. Download PyCharm and create a new project.
  2. It asks which interpreter to use. Click on the gear icon and specify Add Local. Browse to C:\Program Files (x86)\LibreOffice 5\program\python.exe.
  3. Create a new python file.

Then add this code:

import uno
from com.sun.star.awt import Point

p = Point(2,3)
print(p.X)
points = uno.Any("[]com.sun.star.awt.Point", (p,))
print(repr(points))

It underlined the com import statement, although it's not actually an error. PyCharm did recognize the other statements such as uno.Any.

To run, go to Run -> Run. It ran successfully and printed results as expected.

Instead of an IDE, I typically just use a text editor. From what I have seen, a lot of the IDE tools (syntax highlighting, auto completion, debugging) do not work very well with UNO anyway. It is better with Java, but that is a different topic.

By the way, are there any method to insert macros in the document, to share it with the document [...]?

To embed Python code into a document, unzip the .odt file and follow the instructions here.

这篇关于如何配置PyCharm以开发LibreOffice Python宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆