Spire.Doc for Python 13.4.6 现已正式发布。最新版本支持在段落中匹配查找所有关键字。此外,本次更新还成功修复了一些已知问题,例如 Word 转 TXT 时,文本乱码的问题。更多详情请查阅下面的内容。
新功能:
- 在段落中匹配查找所有关键字。
- 支持在 Word 中创建图表。
- 支持获取查找到的内容所在行的索引位置。
- 支持启用和关闭修订跟踪模式。
- 转换 Word 到 PDF 时,支持设置 Document.LayoutOptions.UseHarfBuzzTextShaper。
- 支持判断文档是否有加密。
- 支持将 OfficeMath 转换为 MathMLCode。
#Create word document
document = Document()
#Load the document from disk.
document.LoadFromFile(inputFile)
#Insert the paragraphs of document
for i in range(document.Sections.Count):
section = document.Sections.get_Item(i)
for j in range(section.Paragraphs.Count):
paragraph = section.Paragraphs.get_Item(j)
textSelections = paragraph.FindAllString("The", False, True)
for selection in textSelections:
#highlight
selection.GetAsOneRange().CharacterFormat.HighlightColor = Color.get_Yellow()
#Save doc file.
document.SaveToFile(outputFile, FileFormat.Docx)
def AppendCharts(section, chartType, width, heigh):
section.AddParagraph().AppendText("{0:s} chart.".format(chartType))
newPara = section.AddParagraph()
# Support adding the BarChart/LineChart/ColumnChart/Surface3DChart/BubbleChart/PieChart/ScatterChart type
shape = newPara.AppendChart(chartType, float(width), float(heigh))
chart = shape.Chart
chart.Series.Clear()
chart.Series.Add("E-iceblue Test Series 1", ["Word", "PDF", "Excel", "GoogleDocs", "Office"], [
float(1900000), float(850000), float(2100000), float(600000), float(1500000)])
chart.Series.Add("E-iceblue Test Series 2", ["Word", "PDF", "Excel", "GoogleDocs", "Office"], [
float(900000), float(50000), float(1100000), float(400000), float(2500000)])
chart.Series.Add("E-iceblue Test Series 3", ["Word", "PDF", "Excel", "GoogleDocs", "Office"], [
float(500000), float(820000), float(1500000), float(400000), float(100000)])
#Create word document
document = Document()
#Add section
section = document.AddSection()
AppendCharts(section, ChartType.Bar, 500, 300)
#Save
document.SaveToFile("AppendCharts.docx", FileFormat.Docx)
document = Document()
document.LoadFromFile(inputFile)
textSelections = document.FindAllString("Ceshi", True, True)
sb = []
ranges = []
for selection in textSelections:
tr = selection.GetAsOneRange()
ranges.append(tr)
layoutDoc = FixedLayoutDocument(document)
for tr in ranges:
spans = layoutDoc.GetLayoutEntitiesOfNode(tr)
for i in range(spans.Count):
tempSpan = spans[i]
fs = FixedLayoutSpan(tempSpan)
tempfl = fs.Parent
line = FixedLayoutLine(tempfl)
if line.Parent.Type == LayoutElementType.Column:
lines = line.Parent.Lines
index = lines.IndexOf(line)
# print(index)
sb.append("position:" + str(index))
File.AppendAllText(outputFile, sb)
document = Document()
#Load the file from disk.
document.LoadFromFile(inputFile)
document.TrackChanges = True
document.StartTrackRevisions("user")
range = document.LastParagraph.AppendText("Revise4")
range.InsertRevision.Author = "test01"
document.LastParagraph.Text = "remove"
range.DeleteRevision.Author = "test01"
document.StopTrackRevisions()
document.SaveToFile(outputFile)
Document doc = new Document();
doc.LoadFromFile("input.docx");
doc.LayoutOptions.UseHarfBuzzTextShaper = true;
doc.SaveToFile("result.pdf", Spire.Doc.FileFormat.PDF);
value1 = Document.IsEncrypted(inputFile_1)
doc = Document()
section=doc.AddSection()
officeMath = OfficeMath(doc)
officeMath.FromLatexMathCode("x^{2}+\\sqrt{{x^{2}+1}}+1")
officeMath.ToMathMLCode()
问题修复:
- 修复了添加和提取公式时,程序抛 “Arg_InvalidCastException” 异常的问题。
- 修复了 Word 转 TXT 时,文本乱码的问题。
- 修复了使用 FixedLayoutRow.Table 时,程序抛 “Arg_NullReferenceException” 的问题。
- 修复了 Document.IsContainMacro 返回值不正确的问题。
- 修复了 HTML 转 Word 时,程序抛异常 “Cannot remove because there is no parent.” 的问题。
- 修复了 Word 转 HTML 时,程序抛 “System.ArgumentNullException” 的问题。
- 修复了使用 PreserveFormFields=True 不生效的问题。
- 修复了 Word 转 PDF 时,list 编号效果不正确的问题。
- 修复了使用 Span.ParentNode 程序报 "'Document' is not defined" 的问题。
- 修复了 Word 转 HTML 时,公式模糊的问题。
获取 Spire.Doc for Python 13.4.6 请点击: