Spire.Office for Python 11.5.0 已正式发布。该版本带来了多项强大功能提升:Spire.Doc 现在支持将 Word 文档转换为 Excel,Spire.PDF 在替换文本时可以指定文字颜色,Spire.XLS 实现了 Markdown 与 Excel 之间的无缝转换,Spire.OCR 则可与 AI 模型集成,提高识别准确率并增强图像文字识别能力。此外,所有核心组件(Spire.OCR除外)现在均支持 macOS ARM 通用架构。
除了这些新功能外,本版本还修复了大量与 Word、Excel、PDF 和 PowerPoint 文件的转换、处理及保存相关的已知问题,提供了更加稳定可靠的使用体验。更多详细信息请见下文。
获取 Spire.Office for Python 11.5.0,请点击:
https://www.e-iceblue.cn/Downloads/Spire-Office-Python.html
Spire.Doc for Python
优化:
- Chart 命名空间调整:
旧命名(已废弃):from spire.doc.charts import ChartType
新命名(请使用):from spire.doc.charts.ChartType import ChartType
新功能:
- Bookmark 类新增 FirstColumn 和 LastColumn 属性,支持获取书签在表格中的首末列索引。
- TableFormat 类新增 Style、StyleOptions 和 StyleName 属性支持操作表格样式。
- Style 类新增 RemoveSelf 方法支持移除样式。
- 增强 Document 类功能,含页面提取 ExtractPages、首节访问 FirstSection 及断字词典注册/注销支持(RegisterHyphenationDictionary, UnregisterHyphenationDictionary, IsHyphenationDictionaryRegistered)等。
- 新增对 ARM 架构 macOS 的支持。
- 支持将 MHTML 转换为 PDF。
- 支持将 Word 数学公式导出为标准 MathML,以确保在 HTML 中正确渲染。
- 支持将 Word 转换为 Excel。
doc = Document()
doc.LoadFromFile(inputFile)
firstColumn = doc.Bookmarks["t_insert"].FirstColumn
lastColumn = doc.Bookmarks["t_insert"].LastColumn
doc = Document()
tableStyle = doc.Styles.Add(StyleType.TableStyle, "TestTableStyle3")
tableStyle.LeftIndent = 55
tableStyle.Borders.Color = Color.get_Green()
tableStyle.HorizontalAlignment = RowAlignment.Right
tableStyle.Borders.BorderType = BorderStyle.Single
section = doc.AddSection()
table = section.AddTable()
table.ResetCells(3, 3)
table.Rows[0].Cells[0].AddParagraph().AppendText("Aligned according to left indent")
table.PreferredWidth = PreferredWidth.FromPoints(300)
table.Format.StyleName = "TestTableStyle3"
style = doc.Styles.FindByName("TestTableStyle3")
if (style is not None) and isinstance(style, TableStyle):
tableStyle = style
tableStyle.Borders.Color = Color.get_Black()
tableStyle.Borders.BorderType = BorderStyle.Double
tableStyle.RowStripe = 3
tableStyle.ConditionalStyles[TableConditionalStyleType.OddRowStripe].Shading.BackgroundPatternColor = Color.get_LightBlue()
tableStyle.ConditionalStyles[TableConditionalStyleType.EvenRowStripe].Shading.BackgroundPatternColor = Color.get_LightCyan()
tableStyle.ColumnStripe = 1
tableStyle.ConditionalStyles[TableConditionalStyleType.EvenColumnStripe].Shading.BackgroundPatternColor = Color.get_LightPink()
table.ApplyStyle(tableStyle)
table.Format.StyleOptions = table.Format.StyleOptions | TableStyleOptions.ColumnStripe
doc.SaveToFile(outputFile, FileFormat.Docx)
style = doc.Styles.FindByName("TestTableStyle3")
style.RemoveSelf()
document = Document()
document.LoadFromFile("input.mhtml")
document.SaveToFile("output.pdf", FileFormat.PDF)
document.Close()
HtmlExportOptions options = doc.HtmlExportOptions
options.OfficeMathOutputMode = HtmlOfficeMathOutputMode.MathML
document = Document()
document.LoadFromFile("input.docx")
document.SaveToFile("output.xlsx", FileFormat.XLSX)
document.Close()
问题修复:
- 修复了启用修订并替换内容,结果不正确的问题。
- 修复了在 Python v3.14 环境中获取文档属性时,程序抛出 “NotImplementedError” 异常的问题。
- 修复了在 macOS 系统中设置 CharacterFormat.FontSize 时,程序抛出 “RuntimeError: ffi_prep_cif_var failed” 异常的问题。
- 修复了向图表添加系列时程序抛出异常的问题。
- 修复了将 Word 转换为 PDF 时添加数字签名失败的问题。
Spire.XLS for Python
新功能:
- 新增对 ARM 架构 macOS 的支持。
- 支持隐藏数据透视表字段列表。
- 支持转换 Excel 到 Markdown。
- 支持转换 Markdown 到 Excel。
workbook.HidePivotFieldList = true;
workbook = Workbook()
workbook.LoadFromFile(inputFile)
markdownOptions = MarkdownOptions()
markdownOptions.SavePicInRelativePath = False
markdownOptions.SaveHyperlinkAsRef = False
workbook.SaveToMarkdown(outputFile, markdownOptions)
workbook.Dispose()
workbook = Workbook()
workbook.LoadFromFile(inputFile)
wb.SaveToFile("out.xlsx", ExcelVersion.Version2010);
问题修复:
- 修复了复制的 OLE 对象在 WPS 中显示不正确的问题。
- 修复了删除宏效果不正确的问题
- 修复了当错误设置 workbook.ConverterSetting.Xdpi 时没有错误提示的问题(正确设置应为 workbook.ConverterSetting.XDpi)。
- 修复了文本格式值转为数字格式失败的问题。
- 修复了 Excel 文档保存到 EMF 时抛出异常的问题。
- 修复了设置单元格的 Value2 值时程序抛异常的问题。
- 修复了在 Python 3.14.2 环境下运行产品包时,程序抛出 “NotImplementedError: There is currently no support for "str | None"” 异常的问题。
- 修复了透视表 ShowValuesRow 置为 False 不生效的问题。
- 修复了创建透视表时指定较大的数据源范围时程序抛异常的问题。
- 修复了数据透视表单元格中文本换行无效的问题。
- 将枚举类名称从 SortComparsionType 更正为 SortComparisonType。
Spire.Presentation for Python
新功能:
- 新增对 ARM 架构 macOS 的支持。
问题修复:
- 修复了在macOS上使用Python V12+时出现的“ffi_prep_cif_var failed”错误。
- 修复了在使用AddFromSVGAsShapes导入时出现的SVG效果不正确的问题。
- 修复了在将PPTX转换为PDF时发现图表内容不一致的问题。
- 修复了在将PPTX转换为PDF时图表丢失的问题。
- 修复了 PPT 转图片时内容丢失的问题。
- 修复了将 PowerPoint 文档转换为图像时程序可能挂起的问题。
Spire.PDF for Python
新功能:
- 提供 PdfCustomAppearance 类支持自定义签名外观。
- 完成对 Mac M 系列芯片(ARM64 架构)的兼容性适配。
- 支持获取文本的字体样式。
- ReplaceText 接口新增颜色参数重载。
class MyPdfCustomAppearance(IPdfSignatureAppearance):
def __init__(self):
pass
def Generate(self, g: PdfCanvas):
x = 0.0
y = 0.0
fontSize = 10.0
font = PdfTrueTypeFont("SimSun", fontSize, PdfFontStyle.Regular, True)
lineHeight = fontSize
image = PdfImage.FromFile(inputImage)
g.DrawImage(image, x, y)
x = float(image.Width)
g.DrawString("Signer: Gary", font, PdfBrushes.get_Red(), PointF(x, y))
y += lineHeight + 5
g.DrawString("Phone: +86 12345678", font, PdfBrushes.get_Black(), PointF(x, y))
y += lineHeight + 5
g.DrawString("Address: Sichuan Province, China", font, PdfBrushes.get_Black(), PointF(x, y))
doc = PdfDocument()
doc.LoadFromFile(inputFile)
signatureMaker = PdfOrdinarySignatureMaker(doc, inputFile_pfx, "e-iceblue")
my_appearance = MyPdfCustomAppearance()
customAppearance = PdfCustomAppearance(my_appearance)
signatureMaker.MakeSignature("Signer", doc.Pages.get_Item(0), 90.0, 550.0, 270.0, 640.0, customAppearance)
doc.SaveToFile(outputFile)
doc.Close()
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(inputFile);
// 定义一个矩形
RectangleF rctg = new RectangleF(0, 0, 200, 300);
var page = doc.Pages[0];
PdfTextFinder finder = new PdfTextFinder(page);
finder.Options.Parameter = TextFindParameter.None;
finder.Options.Area = rctg;
// 再矩形中查找特定文本
List<PdfTextFragment> findouts = finder.FindAllText();
StringBuilder sb = new StringBuilder();
foreach (PdfTextFragment find in findouts)
{
sb.AppendLine(find.Text);
sb.AppendLine(find.TextStates[0].FontName);
sb.AppendLine(find.TextStates[0].FontSize.ToString("F2"));
}
File.WriteAllText(outputFile, sb.ToString());
textReplacer.ReplaceText("文档", "文件", Color.get_Blue())
问题修复:
- 修复了替换文本不正确的问题。
- 修复了在 Mac 机器上运行 Python 部分功能,程序抛出“ffi_prep_cif_var failed”的问题。
- 修复了转换 PDF 到 PDF/A2B,结果文档的内容拷贝出来不正确的问题。
- 修复了替换文本时设置了颜色,但显示效果不符合预期。
Spire.Barcode for Python
新功能:
- 新增对 ARM 架构 macOS 的支持。
Spire.OCR for Python
新功能:
- 支持接入云端 AI 模型(如豆包、千问、DeepSeek 等)进行图片文本识别。(注:用户需自行在 AI 平台获取 API Key)
def _run_ai_test(self):
filename = "1.png"
output_file = "scan.txt"
file_path = r"F:\3.3.0AI\AI\ocr.xml"
model = "AIModel"
api_key = "ApiKey"
api_url = "ApiUrl"
self._update_ocr_config(file_path, model, api_key, api_url)
self._scan_img(filename, output_file)
def _scan_img(self, filename, output_file):
scanner = OcrScanner()
configure_options = ConfigureOptions()
configure_options.ModelPath = r"F:\3.3.0AI\AI"
configure_options.Language = "Japanese"
scanner.ConfigureDependencies(configure_options)
scanner.Scan(filename)
text = scanner.Text.ToString()
with open(output_file, "w", encoding="utf-8") as f:
f.write(text)
def _update_ocr_config(self, file_path, model, api_key, api_url):
tree = ET.parse(file_path)
root = tree.getroot()
model_node = root.find('./configs/model')
api_key_node = root.find('./configs/apiKey')
api_url_node = root.find('./configs/apiUrl')
if model_node is not None:
model_node.text = model
if api_key_node is not None:
api_key_node.text = api_key
if api_url_node is not None:
api_url_node.text = api_url
tree.write(file_path, encoding='utf-8', xml_declaration=True)
print("XML更新成功!")







