python - Error: expected str, bytes or os.PathLike object, not pyuno when opening DOCX in LibreOffice API UNO - Stack Overflow

The ClipboardMonitor system monitors the user's clipboard and processes copied text, ensuring that

The ClipboardMonitor system monitors the user's clipboard and processes copied text, ensuring that the document formatting is preserved. It uses LibreOffice via the UNO API to manipulate .docx files, converting HTML to DOCX and copying the formatted content to the clipboard.

Expected system flow:

  1. Clipboard Monitoring:

    • Clears the clipboard to avoid duplication.
    • Automatically detects when new text is copied.
  2. HTML Processing:

    • Saves the copied text as an .html file.
    • Formats the HTML to ensure compatibility.
  3. Conversion to DOCX:

    • Uses LibreOffice to convert HTML to DOCX.
  4. Opening and Copying in LibreOffice:

    • Connects to LibreOffice in headless mode.
    • Opens the .docx document.
    • Copies the formatted content to the clipboard.
  5. Pasting the Formatted Text:

    • The user can paste the text into any other program while maintaining formatting.

However, I am facing an issue that I cannot resolve. When trying to open the .docx document using the LibreOffice UNO API, I receive the following error:

❌ Error copying from LibreOffice: expected str, bytes or os.PathLike object, not pyuno

This Python script reproduces the issue by:

  1. Starting LibreOffice in headless mode.
  2. Opening a .docx file.
  3. Trying to copy its content.
import os
import time
import pyperclip
from pathlib import Path
# Configura as variáveis de ambiente do UNO para que ele seja encontrado
os.environ["URE_BOOTSTRAP"] = "vnd.sun.star.pathname:C:/Program Files/LibreOffice/program/fundamental.ini"
os.environ["UNO_PATH"] = "C:/Program Files/LibreOffice/program"
os.environ["PATH"] += os.pathsep + os.environ["UNO_PATH"]
sys.path.append(os.environ["UNO_PATH"])
from ooodev.loader.lo import Lo
from ooodev.write import Write

# Path to the DOCX file
DOCX_PATH = "C:\\caminho_arquivo_exemplo\\output.docx" 

def copy_from_libreoffice(docx_file):
    """Open LibreOffice and copy formatted text."""
    try:
        print("

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744730513a4590439.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信