Spire.XLS 14.2.1 现已发布。该版本支持设置页眉页脚图片的剪切位置,同时也修复了一些在转换转换XLSX文档到PDF文档和图片时出现的一些问题。新功能及问题修复详情如下。
新功能:
sheet.PageSetup.LeftHeaderPictureCropTop=6.15;
sheet.PageSetup.LeftHeaderPictureCropBottom=7.15;
sheet.PageSetup.LeftHeaderPictureCropLeft =7.15;
sheet.PageSetup.LeftHeaderPictureCropRight = 6.15;
sheet.PageSetup.LeftFooterPictureCropTop=0.15;
sheet.PageSetup.LeftFooterPictureCropBottom=0.15;
sheet.PageSetup.LeftFooterPictureCropLeft =0.15;
sheet.PageSetup.LeftFooterPictureCropRight =0.15;
sheet.PageSetup.CenterHeaderPictureCropTop=0.15;
sheet,PageSetup.CenterHeaderPictureCropBottom=0.15;
sheet.PageSetup.CenterHeaderPictureCropLeft=0.15;
sheet.PageSetup.CenterHeaderPictureCropRight =0.15;
sheet.PageSetup.CenterFooterPictureCropTop=0.15;
sheet.PageSetup.CenterFooterPictureCropBottom=0.15;
sheet.PageSetup.CenterFooterPictureCropLeft =0.15;
sheet.PageSetup.CenterFooterPictureCropRight=0.15;
sheet.PageSetup.RightHeaderPictureCropTop=0.15;
sheet.PageSetup.RightHeaderPictureCropBottom=0.15;
sheet.PageSetup.RightHeaderPictureCropLeft=0.15;
sheet.PageSetup.RightHeaderPictureCropRight=0.15;
sheet.PageSetup.RightFooterPictureCropTop=0.15;
sheet.PageSetup.RightFooterPictureCropBottom=0.15;
sheet.PageSetup.RightFooterPictureCropLeft=0.15;问题修复:
Spire.Presentation for Java 9.2.2 已发布。本次更新新增获取和设置颜色透明度和亮度的方法,同时增强了 PPT 到 PDF 的转换功能。此外,一些已知问题也在该版本中成功修复,如获取出的文本的对齐方式不正确的问题。详情请阅读以下内容。
新功能:
问题修复:
https://www.e-iceblue.cn/Downloads/Spire-Presentation-JAVA.html
我们很高兴地宣布 Spire.PDF for Java 10.2.0 正式发布。该版本修复了一些已知问题,如从 PDF 文档中获取的创建时间有误的问题,以及将提取的图像重新绘制到页面失败的问题。更多详情如下。
问题修复:
Spire.PDF 10.2.2 已发布。本次更新增强了 PDF 到 PDF/A、OFD 以及图片的转换功能。此外,一些已知问题也在该版本中成功修复,如查找文本并高亮不生效的问题。详情请阅读以下内容。
问题修复:
在 Excel 中,接受修订和拒绝修订是确保数据完整性和文档准确性的重要步骤。接受修订使我们能够无缝地将其他用户所做的修改合并到电子表格中,从而确保数据的准确性。而拒绝修订则允许我们保留原始内容并忽略不需要的修改,以防止错误或不必要的信息被包含进来。通过这些操作,我们能够有效地协作,控制文档的最终版本,并生成准确可靠的结果。这篇文章将介绍如何 使用 Python 和 Spire.XLS for Python 接受或拒绝 Excel 中的修订。
本教程需要 Spire.XLS for Python 和 plum-dispatch v1.7.4。您可以通过以下 pip 命令将它们轻松安装到 Windows 中。
pip install Spire.XLS如果您不确定如何安装,请参考此教程: 如何在 Windows 中安装 Spire.XLS for Python
Spire.XLS for Python 提供了 Workbook.HasTrackedChanges 属性,用于判断 Excel 工作簿是否具有修订。如果该属性返回 True,你可以使用 Workbook.AcceptAllTrackedChanges() 方法一次性接受这些修订。
以下步骤展示了如何使用 Spire.XLS for Python 接受 Excel 工作簿中的所有修订:
from spire.xls.common import *
from spire.xls import *
# 指定输入和输出文档路径
inputFile = "示例.xlsx"
outputFile = "接受修订.xlsx"
# 创建Workbook对象
workbook = Workbook()
# 加载Excel文档
workbook.LoadFromFile(inputFile)
# 检查该文档是否具有修订
if workbook.HasTrackedChanges:
# 接受文档中的所有修订
workbook.AcceptAllTrackedChanges()
# 保存结果文档
workbook.SaveToFile(outputFile, FileFormat.Version2013)
workbook.Dispose()
当其他贡献者对电子表格进行修改时,可能会出现错误的修订。这些修订可能会导致数据不准确或产生其他问题。在这种情况下,拒绝修订可以防止错误的修改被应用到最终版本中。Spire.XLS for Python 提供了 Workbook.RejectAllTrackedChanges() 方法,用于拒绝 Excel 工作簿中的所有修订。
以下步骤展示了如何使用 Spire.XLS for Python 拒绝 Excel 工作簿中的所有修订:
from spire.xls.common import *
from spire.xls import *
# 指定输入和输出文档路径
inputFile = "示例.xlsx"
outputFile = "拒绝修订.xlsx"
# 创建Workbook对象
workbook = Workbook()
# 加载Excel文档
workbook.LoadFromFile(inputFile)
# 检查该文档是否具有修订
if workbook.HasTrackedChanges:
# 拒绝文档中的所有修订
workbook.RejectAllTrackedChanges()
# 保存结果文档
workbook.SaveToFile(outputFile, FileFormat.Version2013)
workbook.Dispose()
如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。
PDF/A 是一种专为电子文档的长期归档和保存而设计的文档格式。它能保证文档的内容、结构和视觉外观随着时间的推移保持不变。通过将 PDF 文件转换为 PDF/A 格式,可以确保文档的长期可访问性,而不受软件、操作系统或未来技术进步的影响。相反,将 PDF/A 文件转换为标准 PDF 格式,可以更轻松地编辑、共享和协作文档,确保不同应用程序、设备和平台之间更好的兼容性。本文将介绍如何使用 Spire.PDF for Python 在 Python 中实现 PDF 和 PDF/A 格式之间的相互转换。
本教程需要用到 Spire.PDF for Python 和 plum-dispatch v1.7.4。可以通过以下 pip 命令将它们轻松安装到 Windows 中。
pip install Spire.PDF如果您不清楚如何安装,请参考: 如何在 Windows 中安装 Spire.PDF for Python
Spire.PDF for Python 提供的 PdfStandardsConverter 类支持将 PDF 转换为各种 PDF/A 格式,包括 PDF/A-1a、2a、3a、1b、2b 和 3b。此外,它还支持将 PDF 转换为 PDF/X-1a:2001。具体步骤如下:
from spire.pdf.common import *
from spire.pdf import *
inputFile = "示例文档.pdf"
outputFolder = "转换/"
# 创建PdfStandardsConverter类的对象
converter = PdfStandardsConverter(inputFile)
# 将PDF文件转换为PdfA1A
converter.ToPdfA1A(outputFolder + "ToPdfA1A.pdf")
# 将PDF文件转换为PdfA1B
converter.ToPdfA1B(outputFolder + "ToPdfA1B.pdf")
# 将PDF文件转换为PdfA2A
converter.ToPdfA2A(outputFolder + "ToPdfA2A.pdf")
# 将PDF文件转换为PdfA2B
converter.ToPdfA2B(outputFolder + "ToPdfA2B.pdf")
# 将PDF文件转换为PdfA3A
converter.ToPdfA3A(outputFolder + "ToPdfA3A.pdf")
# 将PDF文件转换为PdfA3B
converter.ToPdfA3B(outputFolder + "ToPdfA3B.pdf")
# 将PDF文件转换为PDF/X-1a:2001
converter.ToPdfX1A2001(outputFolder + "ToPdfX1a.pdf")
要将 PDF/A 文件转换回标准PDF文件格式,需要创建一个新的标准 PDF 文件,然后将 PDF/A 文件的页面内容绘制到新创建的 PDF 文件中。具体步骤如下:
from spire.pdf.common import *
from spire.pdf import *
inputFile = "转换/ToPdfA1A.pdf"
outputFile = "PdfA转Pdf.pdf"
# 创建PdfDocument对象
doc = PdfDocument()
# 加载PDF文件
doc.LoadFromFile(inputFile)
# 创建一个新的标准PDF文件
newDoc = PdfNewDocument()
newDoc.CompressionLevel = PdfCompressionLevel.none
# 在新创建的PDF中添加页面,并将已加载PDF的页面内容绘制到新创建PDF的相应页面上
for i in range(doc.Pages.Count):
page = doc.Pages.get_Item(i)
size = page.Size
p = newDoc.Pages.Add(size, PdfMargins(0.0))
page.CreateTemplate().Draw(p, 0.0, 0.0)
# 保存新创建的PDF文件
fileStream = Stream(outputFile)
newDoc.Save(fileStream)
fileStream.Close()
newDoc.Close(True)
如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。
列表是一种非常有用的工具,可以帮助我们以结构化和有序的方式呈现信息。无论是制作项目清单、步骤指南,还是总结重要观点,使用列表都可以显著提升文档的可读性和视觉吸引力,使读者更加轻松地浏览和理解文档的内容。本文将介绍如何使用 Python 和 Spire.Doc for Python 在 Word 文档中创建各种类型的列表。
本教程需要用到 Spire.Doc for Python 和 plum-dispatch v1.7.4。可以通过以下 pip 命令将它们轻松安装到 Windows 中。
pip install Spire.Doc如果您不确定如何安装,请参考:如何在 Windows 中安装 Spire.Doc for Python
Spire.Doc for Python 提供了 ListStyle 类,用于创建编号列表样式或项目符号列表样式。创建后,你可以使用 Paragraph.ListFormat.ApplyStyle() 方法将列表样式应用到段落。创建编号列表的步骤如下:
from spire.doc import *
from spire.doc.common import *
# 创建一个Document对象
doc = Document()
# 添加一个章节
section = doc.AddSection()
# 创建一个编号列表样式
listStyle = doc.Styles.Add(ListType.Numbered, "numberList")
Levels = listStyle.ListRef.Levels
Levels[0].PatternType = ListPatternType.Arabic
Levels[0].TextPosition = 20
# 添加一个段落
paragraph = section.AddParagraph()
textRange = paragraph.AppendText("所需的Web开发技能:")
textRange.CharacterFormat.FontName = "宋体"
textRange.CharacterFormat.Bold = True
textRange.CharacterFormat.FontSize = 12.0
paragraph.Format.AfterSpacing = 5.0
# 添加一个段落并将编号列表样式应用于它
paragraph = section.AddParagraph()
paragraph.AppendText("HTML")
paragraph.ListFormat.ApplyStyle(listStyle.Name)
paragraph.ListFormat.ListLevelNumber = 0
# 添加另外四个段落并将编号列表样式应用于它们
paragraph = section.AddParagraph()
paragraph.AppendText("CSS")
paragraph.ListFormat.ApplyStyle(listStyle.Name)
paragraph.ListFormat.ListLevelNumber = 0
paragraph = section.AddParagraph()
paragraph.AppendText("JavaScript")
paragraph.ListFormat.ApplyStyle(listStyle.Name)
paragraph.ListFormat.ListLevelNumber = 0
paragraph = section.AddParagraph()
paragraph.AppendText("Python")
paragraph.ListFormat.ApplyStyle(listStyle.Name)
paragraph.ListFormat.ListLevelNumber = 0
paragraph = section.AddParagraph()
paragraph.AppendText("MySQL")
paragraph.ListFormat.ApplyStyle(listStyle.Name)
paragraph.ListFormat.ListLevelNumber = 0
# 将文档保存到文件
doc.SaveToFile("编号列表.docx", FileFormat.Docx2016)
doc.Dispose()
创建项目符号列表的过程与创建编号列表类似,主要区别在于需要将列表类型指定为 Bulleted 并为其设置一个项目符号。以下是详细步骤:
from spire.doc import *
from spire.doc.common import *
# 创建一个Document对象
doc = Document()
# 添加一个章节
section = doc.AddSection()
# 创建一个项目符号列表样式
listStyle = doc.Styles.Add(ListType.Bulleted,"bulletedList")
Levels = listStyle.ListRef.Levels
Levels[0].BulletCharacter = "\u00B7"
Levels[0].CharacterFormat.FontName = "Symbol"
Levels[0].TextPosition = 20
# 添加一个段落
paragraph = section.AddParagraph()
textRange = paragraph.AppendText("计算机科学学科:")
textRange.CharacterFormat.FontName = "宋体"
textRange.CharacterFormat.Bold = True
textRange.CharacterFormat.FontSize = 12.0
paragraph.Format.AfterSpacing = 5.0
# 添加一个段落并将项目符号列表样式应用于它
paragraph = section.AddParagraph()
textRange = paragraph.AppendText("数据结构")
textRange.CharacterFormat.FontName = "宋体"
textRange.CharacterFormat.FontSize = 12.0
paragraph.ListFormat.ApplyStyle(listStyle.Name)
paragraph.ListFormat.ListLevelNumber = 0
# 添加另外五个段落并将项目符号列表样式应用于它们
paragraph = section.AddParagraph()
textRange = paragraph.AppendText("算法")
textRange.CharacterFormat.FontName = "宋体"
textRange.CharacterFormat.FontSize = 12.0
paragraph.ListFormat.ApplyStyle(listStyle.Name)
paragraph.ListFormat.ListLevelNumber = 0
paragraph = section.AddParagraph()
textRange = paragraph.AppendText("计算机网络")
textRange.CharacterFormat.FontName = "宋体"
textRange.CharacterFormat.FontSize = 12.0
paragraph.ListFormat.ApplyStyle(listStyle.Name)
paragraph.ListFormat.ListLevelNumber = 0
paragraph = section.AddParagraph()
textRange = paragraph.AppendText("操作系统")
textRange.CharacterFormat.FontName = "宋体"
textRange.CharacterFormat.FontSize = 12.0
paragraph.ListFormat.ApplyStyle(listStyle.Name)
paragraph.ListFormat.ListLevelNumber = 0
paragraph = section.AddParagraph()
textRange = paragraph.AppendText("C编程")
textRange.CharacterFormat.FontName = "宋体"
textRange.CharacterFormat.FontSize = 12.0
paragraph.ListFormat.ApplyStyle(listStyle.Name)
paragraph.ListFormat.ListLevelNumber = 0
paragraph = section.AddParagraph()
textRange = paragraph.AppendText("计算理论")
textRange.CharacterFormat.FontName = "宋体"
textRange.CharacterFormat.FontSize = 12.0
paragraph.ListFormat.ApplyStyle(listStyle.Name)
paragraph.ListFormat.ListLevelNumber = 0
# 将文档保存到文件
doc.SaveToFile("项目符号列表.docx", FileFormat.Docx2016)
doc.Dispose()
多级列表由至少两个不同的级别组成。你可以使用 ListStyle.Levels[index] 属性访问嵌套列表的特定级别,并为其设置编号类型和前缀。以下是创建多级编号列表的步骤:
from spire.doc import *
from spire.doc.common import *
# 创建一个Document对象
doc = Document()
# 添加一个章节
section = doc.AddSection()
# 创建一个编号列表样式,指定每个级别的编号前缀和模式类型
listStyle = doc.Styles.Add(ListType.Numbered,"levelstyle")
Levels = listStyle.ListRef.Levels
Levels[0].PatternType = ListPatternType.Arabic
Levels[0].TextPosition = 20.0
Levels[1].NumberPrefix = "%1."
Levels[1].PatternType = ListPatternType.Arabic
Levels[2].NumberPrefix = "%1.%2."
Levels[2].PatternType = ListPatternType.Arabic
# 添加一个段落
paragraph = section.AddParagraph()
textRange = paragraph.AppendText("这是一个多级编号列表:")
textRange.CharacterFormat.FontName = "宋体"
textRange.CharacterFormat.Bold = True
textRange.CharacterFormat.FontSize = 12.0
paragraph.Format.AfterSpacing = 5.0
# 添加一个段落并将编号列表样式应用于它
paragraph = section.AddParagraph()
textRange = paragraph.AppendText("第一项")
textRange.CharacterFormat.FontName = "宋体"
textRange.CharacterFormat.FontSize = 12.0
paragraph.ListFormat.ApplyStyle("levelstyle")
paragraph.ListFormat.ListLevelNumber = 0
# 添加另外五个段落并将编号列表样式应用于它们
paragraph = section.AddParagraph()
textRange = paragraph.AppendText("第二项")
textRange.CharacterFormat.FontName = "宋体"
textRange.CharacterFormat.FontSize = 12.0
paragraph.ListFormat.ApplyStyle("levelstyle")
paragraph.ListFormat.ListLevelNumber = 0
paragraph = section.AddParagraph()
textRange = paragraph.AppendText("第一子项")
textRange.CharacterFormat.FontName = "宋体"
textRange.CharacterFormat.FontSize = 12.0
paragraph.ListFormat.ApplyStyle("levelstyle")
paragraph.ListFormat.ListLevelNumber = 1
paragraph = section.AddParagraph()
textRange = paragraph.AppendText("第二子项")
textRange.CharacterFormat.FontName = "宋体"
textRange.CharacterFormat.FontSize = 12.0
paragraph.ListFormat.ContinueListNumbering()
paragraph.ListFormat.ApplyStyle("levelstyle")
paragraph = section.AddParagraph()
textRange = paragraph.AppendText("子子项")
textRange.CharacterFormat.FontName = "宋体"
textRange.CharacterFormat.FontSize = 12.0
paragraph.ListFormat.ApplyStyle("levelstyle")
paragraph.ListFormat.ListLevelNumber = 2
paragraph = section.AddParagraph()
textRange = paragraph.AppendText("第三项")
textRange.CharacterFormat.FontName = "宋体"
textRange.CharacterFormat.FontSize = 12.0
paragraph.ListFormat.ApplyStyle("levelstyle")
paragraph.ListFormat.ListLevelNumber = 0
# 将文档保存到文件
doc.SaveToFile("多级编号列表.docx", FileFormat.Docx2016)
doc.Dispose()
要在多级列表中结合数字和符号项目符号,你需要创建单独的列表样式(编号和项目符号),并将它们应用于不同的段落。具体步骤如下:
from spire.doc import *
from spire.doc.common import *
# 创建一个Document对象
doc = Document()
# 添加一个章节
section = doc.AddSection()
# 创建一个编号列表样式
numberList = doc.Styles.Add(ListType.Numbered, "numberedStyle")
Levels = numberList.ListRef.Levels
Levels[0].PatternType = ListPatternType.Arabic
Levels[0].TextPosition = 20
Levels[1].PatternType = ListPatternType.LowLetter
# 创建一个项目符号列表样式
bulletedListStyle = doc.Styles.Add(ListType.Bulleted, "bulletedStyle")
Levels = bulletedListStyle.ListRef.Levels
Levels[2].BulletCharacter = "\u002A"
Levels[2].CharacterFormat.FontName = "Symbol"
# 添加一个段落
paragraph = section.AddParagraph()
textRange = paragraph.AppendText("这是一个多级混合列表:")
textRange.CharacterFormat.FontName = "宋体"
textRange.CharacterFormat.Bold = True
textRange.CharacterFormat.FontSize = 12.0
paragraph.Format.AfterSpacing = 5.0
# 添加一个段落并将编号列表样式应用于它
paragraph = section.AddParagraph()
textRange = paragraph.AppendText("第一项")
textRange.CharacterFormat.FontName = "宋体"
textRange.CharacterFormat.FontSize = 12.0
paragraph.ListFormat.ApplyStyle("numberedStyle")
paragraph.ListFormat.ListLevelNumber = 0
# 添加另外五个段落并应用不同的列表样式
paragraph = section.AddParagraph()
textRange = paragraph.AppendText("第一子项")
textRange.CharacterFormat.FontName = "宋体"
textRange.CharacterFormat.FontSize = 12.0
paragraph.ListFormat.ApplyStyle("numberedStyle")
paragraph.ListFormat.ListLevelNumber = 1
paragraph = section.AddParagraph()
textRange = paragraph.AppendText("第二子项")
textRange.CharacterFormat.FontName = "宋体"
textRange.CharacterFormat.FontSize = 12.0
paragraph.ListFormat.ListLevelNumber = 1
paragraph.ListFormat.ApplyStyle("numberedStyle")
paragraph = section.AddParagraph()
textRange = paragraph.AppendText("第一子子项")
textRange.CharacterFormat.FontName = "宋体"
textRange.CharacterFormat.FontSize = 12.0
paragraph.ListFormat.ApplyStyle("bulletedStyle")
paragraph.ListFormat.ListLevelNumber = 2
paragraph = section.AddParagraph()
textRange = paragraph.AppendText("第二子子项")
textRange.CharacterFormat.FontName = "宋体"
textRange.CharacterFormat.FontSize = 12.0
paragraph.ListFormat.ApplyStyle("bulletedStyle")
paragraph.ListFormat.ListLevelNumber = 2
paragraph = section.AddParagraph()
textRange = paragraph.AppendText("第二项")
textRange.CharacterFormat.FontName = "宋体"
textRange.CharacterFormat.FontSize = 12.0
paragraph.ListFormat.ApplyStyle("numberedStyle")
paragraph.ListFormat.ListLevelNumber = 0
# 将文档保存到文件
doc.SaveToFile("多级混合列表.docx", FileFormat.Docx2016)
doc.Dispose()
如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。
Spire.Doc 12.1.17已发布。在该版本中,段落的左右缩进功能支持设置字符个数的选项。同时也增强了从Word到PDF和HTML的转换功能。此外,还修复了一些已知问题,如修复了转换Word文档到PDF文档时内容格式不正确的问题。详情请阅读以下内容。
新功能:
//按字符数设置左缩进
paragraph.Format.LeftIndentChars = 10;
//按字符数设置右缩进
paragraph.Format.RightIndentChars = 10;问题修复:
Spire.Cloud 9.1.6 已发布。本次更新支持在 Word 修订显示模式为无标记和原始状态下编辑文档,以及在 Word 修订无标记模式下插入表格行或者列。此外,一些已知问题也在该版本中成功修复,如 Word 可编辑区域外的内容能被删除的问题。详情请阅读以下内容。
新功能:
问题修复:
修改 Word 文档中的字体可以显着影响其视觉外观和整体可读性。无论您是想增强文档的风格还是使其符合特定的格式要求,更改字体都是一个简单直接的过程,可以让您自定义文本。在本文中,您将学习如何使用 Spire.Doc for Python 在 Python 中更改 Word 文档中的段落或文本的字体。
本教程需要 Spire.Doc for Python 和 plum-dispatch v1.7.4。您可以通过以下 pip 命令将它们轻松安装到 Windows 中。
pip install Spire.Doc如果您不确定如何安装,请参考此教程: 如何在 Windows 中安装 Spire.Doc for Python
使用 Spire.Doc for Python,您可以创建一个 ParagraphStyle 对象,该对象定义了可以应用于特定段落的字体信息。以下是更改段落字体的步骤:
from spire.doc import *
from spire.doc.common import *
# 创建一个 Document 对象
document = Document()
# 从文件加载示例文档
document.LoadFromFile('示例文档.docx')
# 获取文档的第一节
section = document.Sections.get_Item(0)
# 获取第二个段落
paragraph = section.Paragraphs.get_Item(1)
# 创建一个自定义样式对象
style = ParagraphStyle(document)
# 设置样式名称为 'NewStyle'
style.Name = 'NewStyle'
# 设置样式的字符格式,加粗、斜体、红色字体、微软雅黑
style.CharacterFormat.Bold = True
style.CharacterFormat.Italic = True
style.CharacterFormat.TextColor = Color.get_Red()
style.CharacterFormat.FontName = '微软雅黑'
# 将自定义样式添加到文档的样式集合中
document.Styles.Add(style)
# 应用样式到指定段落
paragraph.ApplyStyle(style.Name)
# 将修改后的文档保存为新文件,使用 Docx 格式
document.SaveToFile('修改段落字体.docx', FileFormat.Docx)
document.Dispose()
document.Close()
要更改 Word 文档中特定文本(字母、短语或句子)的字体,您首先需要从文档中找到该文本,然后为其设置不同的颜色或字体样式。以下是详细的步骤:
from spire.doc import *
from spire.doc.common import *
# 创建一个 Document 对象
document = Document()
# 从文件加载示例文档
document.LoadFromFile('示例文档.docx')
# 查找文档中所有包含 'Python Word' 的文本,并返回所有匹配结果
textSelections = document.FindAllString('Python Word', False, True)
# 遍历每个匹配结果
for selection in textSelections:
# 获取匹配结果作为一个文本范围,并修改其字体名称和字体样式
selection.GetAsOneRange().CharacterFormat.FontName = 'Times New Roman'
selection.GetAsOneRange().CharacterFormat.TextColor = Color.get_Red()
selection.GetAsOneRange().CharacterFormat.Bold = True
# 将修改后的文档保存为新文件,使用 Docx 格式
document.SaveToFile('修改文本字体.docx', FileFormat.Docx)
document.Dispose()
document.Close()
如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。