我们很高兴宣布 GroupDocs.Assembly for Python v26.11 已于 2026年11月 发布。此版本带来了主要平台支持的改进——包括首个 Linux 和 macOS 的 wheel——以及原生 Python 数据源支持、增强的错误处理和升级的依赖项。它还引入了若干新功能和破坏性更改,以符合现代 Python 实践和 .NET 10。

本次发布的新功能

  • [Feature] 为 Linux x64 和 macOS(Intel 和 Apple Silicon)添加 wheel (ASSEMBLYPYTHON-26)
  • [Feature] 支持将 Python dict 或 list 作为数据源 (ASSEMBLYPYTHON-27)
  • [Feature] 为文档表加载添加 Python 处理程序 (IDocumentTableLoadHandler) (ASSEMBLYPYTHON-28)
  • [Feature] 在 API 需要 .NET Type 的地方支持 Python 类型(DocumentTableColumn.type、known_types) (ASSEMBLYPYTHON-29)
  • [Feature] 支持从 GROUPDOCS_LIC_PATH 环境变量应用许可证 (ASSEMBLYPYTHON-30)
  • [Enhancement] 将 GroupDocs.Assembly 更新至 26.7,嵌入式运行时更新至 .NET 10.0.14 (ASSEMBLYPYTHON-31)
  • [Enhancement] 为 Python 3.5 – 3.14 提供纯 Python 包,取代编译扩展 (ASSEMBLYPYTHON-32)
  • [Enhancement] assemble_document() 接受单个 DataSourceInfo 以及列表 (ASSEMBLYPYTHON-33)
  • [Enhancement] 对于缺失文件抛出 FileNotFoundError,对于无法应用的许可证抛出 LicenseError,对于其他引擎错误抛出 GroupDocsAssemblyException (ASSEMBLYPYTHON-34)
  • [Enhancement] 将 BarcodeSettings.x_resolution/y_resolution 重命名为 xresolution/yresolution,并将 use_reflection_optimization 设为类属性 (ASSEMBLYPYTHON-35)
  • [Enhancement] 移除 32 位 Windows wheel (ASSEMBLYPYTHON-36)
  • [Fix] 修复 25.5.1 中的 CVE 问题:zlib 1.2.11 → 1.2.12(+4 个更多) (ASSEMBLYPYTHON-11)

公共 API 更改

升级者需要将 x_resolution/y_resolution 和 set_use_reflection_optimization() 重命名,并在原先捕获 RuntimeError 的位置捕获 GroupDocsAssemblyException 和 LicenseError。其他均为新增。

新类和成员

  • groupdocs.assembly:FontSettings、FolderFontSource、IFontSource、SearchOption、OoxmlCompliance、GroupDocsAssemblyException、LicenseError、LicenseWarning。
  • LoadSaveOptions:ooxml_compliance。
  • KnownTypeSet:append()。
  • DocumentTableCollection、DocumentTableColumnCollection:get()。
  • DocumentTableRelationCollection:append()、get()。

已重命名

  • BarcodeSettings.x_resolution → BarcodeSettings.xresolution
  • BarcodeSettings.y_resolution → BarcodeSettings.yresolution

旧名称在读取和赋值时会抛出带有 “Did you mean” 提示的 AttributeError。

已移除

  • DocumentAssembler.set_use_reflection_optimization():请改为直接赋值类属性,例如 DocumentAssembler.use_reflection_optimization = False。

已更改

  • DataSourceInfo 接受 dict 或 list。
  • assemble_document() 接受单个 DataSourceInfo 或列表。
  • DocumentTableSet(path, load_handler) 接受 Python 函数或具有 handle(args) 方法的对象。
  • DocumentTableColumn.type 和 KnownTypeSet.add() 接受 Python 类型。
  • 引擎错误会抛出 FileNotFoundError、RuntimeError、LicenseError 或 GroupDocsAssemblyException。except Exception 能捕获两个版本的错误。

新功能

Linux 和 macOS

26.11 为 Linux x64(manylinux_2_27_x86_64,glibc 2.27 或更高)以及 macOS 12 或更高的 Intel(macosx_12_0_x86_64)和 Apple Silicon(macosx_12_0_arm64)提供 wheel,此外还有 Windows x64。25.5 仅提供 Windows wheel。pip 20.3 或更高会自动选择对应平台的 wheel。在 Linux 上 .NET 运行时需要 ICU,呈现模板需要 libgdiplus(见 Requirements)。

pip install groupdocs-assembly-net==26.11.0

将 Python 数据作为数据源

DataSourceInfo 可以直接接受 dict、dict 列表或值列表;25.5 对 dict 会抛出 TypeError。包装器会根据数据结构将其转换为相应的 .NET 对象,因此数字、字符串、bool、datetime、date 和 Decimal 值在模板中拥有相应的类型:<<[o.OrderDate.Month]>> 和 <<if [c.Vip]>> 的行为与在 .NET 对象上相同。同一列表中的 dict 共享一个类型,其键的并集决定该类型。

from groupdocs.assembly import DataSourceInfo, DocumentAssembler

orders = [
    {"Number": 10001, "Product": "Harbor Blend whole bean coffee", "Quantity": 30, "Price": 552.0},
    {"Number": 10004, "Product": "Aged harbour cheddar", "Quantity": 8, "Price": 132.0},
]

# order-table.docx: a table whose row <<foreach [o in orders]>><<[o.Number]>> ... <</foreach>> repeats per order
DocumentAssembler().assemble_document("order-table.docx", "order-table-report.docx", [
    DataSourceInfo("Quayside Bistro", "customer"),
    DataSourceInfo(orders, "orders"),
])

单个数据源无需列表

assemble_document() 可以接受单个 DataSourceInfo 或它们的列表,行为等同于 .NET 的 params DataSourceInfo[]。25.5 必须使用列表,且对单个 DataSourceInfo 会抛出 TypeError: can't build Array value from 'groupdocs.assembly.DataSourceInfo'。

from groupdocs.assembly import DataSourceInfo, DocumentAssembler

customer = {"Name": "Quayside Bistro", "Product": "Harbor Blend whole bean coffee"}
DocumentAssembler().assemble_document("hello-world.docx", "hello-world-report.docx", DataSourceInfo(customer, "customer"))

表加载处理程序

DocumentTableSet(path, load_handler) 接受 Python 函数 (args),或具有 handle(args) 方法的对象,并在文档加载每个表之前调用它。处理程序可以设置该表的 args.options,或通过 args.is_loaded = False 跳过该表;args.table_index 表示当前表的索引。25.5 对 Python 函数会抛出 TypeError。

from groupdocs.assembly.data import DocumentTableOptions, DocumentTableSet


def on_table(args):
    options = DocumentTableOptions()
    options.first_row_contains_column_names = True
    args.options = options


tables = DocumentTableSet("contracts.xlsx", on_table)
for table in tables.tables:
    print(table.name, [column.name for column in table.columns])

在 API 需要 .NET 类型的地方使用 Python 类型

Python 类型对应成员所需的 .NET 类型:例如 float 对应 System.Double,int、str、bool、datetime 等。文档表的列可以设为数值型,以便在图表中求和,known_types 允许模板调用类型的静态成员;它同样接受 .NET 类型名称。25.5 会抛出 TypeError: can't build Type value from 'type'。

from groupdocs.assembly import DataSourceInfo, DocumentAssembler
from groupdocs.assembly.data import DocumentTable, DocumentTableOptions

options = DocumentTableOptions()
options.first_row_contains_column_names = True
contracts = DocumentTable("contracts.xlsx", 0, options)
contracts.columns["Price"].type = float

assembler = DocumentAssembler()
assembler.known_types.add("System.Math")  # templates can call <<[Math.Round(x, 1)]>>
assembler.assemble_document("table-row.docx", "table-row-report.docx", DataSourceInfo(contracts, "contracts"))

从环境变量获取许可证

将 GROUPDOCS_LIC_PATH 设置为许可证文件的路径,或指向提供许可证的 URL,许可证将在首次引擎调用时自动应用,无需许可证代码;25.5 未读取该变量。如果许可证无法应用(文件缺失、订阅过期、许可证针对其他产品),每次引擎调用都会抛出 LicenseError,并说明变量及引擎原因,直至通过 License().set_license() 应用许可证。将 GROUPDOCS_LIC_STRICT=0 可仅产生一个 LicenseWarning 并进入评估模式。

from groupdocs.assembly import DataSourceInfo, DocumentAssembler, LicenseError

customer = {"Name": "Quayside Bistro", "Product": "Harbor Blend whole bean coffee"}
try:
    DocumentAssembler().assemble_document("hello-world.docx", "hello-world-report.docx", DataSourceInfo(customer, "customer"))
except LicenseError as e:
    print(e)  # GROUPDOCS_LIC_PATH=... could not be applied: <reason>

按类型划分的错误

25.5 对每个引擎错误都会抛出裸 RuntimeError("Proxy error(<.NET exception>): ...")。26.11 对缺失的模板或数据文件抛出 FileNotFoundError(仍继承自 RuntimeError);对模板错误或数据缺失的成员仅抛出 RuntimeError 并附带引擎消息;对无法应用的许可证抛出 LicenseError;对其他引擎错误抛出 GroupDocsAssemblyException。LicenseError 和 GroupDocsAssemblyException 可从 groupdocs.assembly 导入,且不继承自 RuntimeError。

from groupdocs.assembly import DataSourceInfo, DocumentAssembler, GroupDocsAssemblyException

try:
    DocumentAssembler().assemble_document("no-such-template.docx", "report.docx", DataSourceInfo({"Name": "A"}, "customer"))
except FileNotFoundError as e:
    print("missing:", e)
except (RuntimeError, GroupDocsAssemblyException) as e:
    print("engine:", e)

代码示例

from groupdocs.assembly import DataSourceInfo, DocumentAssembler, FileFormat, LoadSaveOptions, OoxmlCompliance

options = LoadSaveOptions(FileFormat.DOCX)
options.ooxml_compliance = OoxmlCompliance.STRICT
customer = {"Name": "Quayside Bistro", "Product": "Harbor Blend whole bean coffee"}
DocumentAssembler().assemble_document("hello-world.docx", "hello-world-strict.docx", options, DataSourceInfo(customer, "customer"))

如何获取更新

PyPI

通过 PyPI 升级到最新包:

groupdocs-assembly-net 26.11.0

pip install groupdocs-assembly-net==26.11.0

直接下载

从 GroupDocs.Assembly for Python v26.11 页面下载适用于您平台的 wheel。

资源