在 Word 文档中进行带条件的邮件合并是创建大量个性化文档的高效方法。与只能根据固定模板生成文档的一般邮件合并不同,条件邮件合并可以根据特定的标准或条件来定制内容,使邮件合并能够得到更广泛的应用。利用 Python,用户可以轻松创建和执行条件邮件合并,实现更高效的定制文档生成。
本文将演示如何使用 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
条件邮件合并是一个包含邮件合并域的 IF 域,可以根据数据和判断条件显示特定的合并结果。要在 Word 文档中创建条件邮件合并,需要先插入一个 IF 域,然后在 IF 域的代码中添加一个邮件合并域,最后添加域结束标记以结束 IF 域。条件由 IF 域中的代码控制。
在 Word 文档中创建条件邮件合并的详细步骤如下:
from spire.doc import *
# 创建 Document 实例
doc = Document()
# 向文档添加一个节
section = doc.AddSection()
# 设置页面大小和边距
section.PageSetup.PageSize = PageSize.A4()
section.PageSetup.Margins.All = 50
# 创建段落样式
style = ParagraphStyle(doc)
style.Name = "Style1"
style.CharacterFormat.FontName = "HarmonyOS Sans SC"
style.CharacterFormat.FontSize = 14
doc.Styles.Add(style)
# 添加段落并设置样式
paragraph = section.AddParagraph()
paragraph.AppendText("尊敬的")
paragraph.AppendField("Name", FieldType.FieldMergeField)
paragraph.AppendText(":")
paragraph.ApplyStyle(style.Name)
paragraph = section.AddParagraph()
paragraph.AppendText("\r\n感谢您成为我们的宝贵客户。我们非常感谢您的业务和支持。")
paragraph.ApplyStyle(style.Name)
# 在段落中添加 IF 域
paragraph = section.AddParagraph()
ifField = IfField(doc)
ifField.Type = FieldType.FieldIf
ifField.Code = "IF "
paragraph.Items.Add(ifField)
# 在 IF 域的代码中添加邮件合并域
paragraph.AppendField("CustomerType", FieldType.FieldMergeField)
paragraph.AppendText(" = ")
paragraph.AppendText("\"VIP\"")
paragraph.AppendText(" \"作为 VIP 客户,我们为您准备了一个特别优惠!享受下一次购买的 20% 折扣。\"")
paragraph.AppendText("\"我们将不定期提供额外的优惠,请关注我们的公告或邮件。\"")
# 在末尾添加域结束标记以结束 IF 域
endIf = paragraph.AppendFieldMark(FieldMarkType.FieldEnd)
ifField.End = endIf
paragraph.ApplyStyle(style.Name)
# 添加段落并设置样式
paragraph = section.AddParagraph()
paragraph.AppendText("您的总消费金额(¥):")
paragraph.AppendField("TotalSpent", FieldType.FieldMergeField)
paragraph.ApplyStyle(style.Name)
paragraph = section.AddParagraph()
paragraph.AppendText("\r\n此致,\r\n科技有限公司")
paragraph.ApplyStyle(style.Name)
# 保存文档
doc.SaveToFile("output/条件邮件合并.docx", FileFormat.Docx)
doc.Close()

Spire.Doc for Python 提供的 Document.MailMerge.Execute(fieldNames: list[str], fieldValues: list[str]) 方法可用于在 Word 文档中进行邮件合并操作。合并完成后,通过将 Document.IsUpdateFields 属性设置为 True 来更新条件邮件合并的结果。具体步骤如下:
from spire.doc import *
import csv
# 从 CSV 文件中读取数据
data = []
with open("示例.csv", "r", encoding="utf-8") as csvfile:
read = csv.reader(csvfile)
for row in read:
data.append(row)
# 遍历数据行,跳过标题行
for i in range(1, len(data)):
# 创建 Document 实例并加载 Word 文档
doc = Document("output/条件邮件合并.docx")
# 从文档中获取域名
fieldNames = doc.MailMerge.GetMergeFieldNames()
# 执行邮件合并
doc.MailMerge.Execute(fieldNames, data[i])
# 更新 If 域
doc.IsUpdateFields = True
# 保存文档
doc.SaveToFile(f"output/顾客/{data[i][0]}.docx", FileFormat.Docx2019)
doc.Close()

如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。
Spire.Doc 12.8.2 已经正式发布,本次更新增强了将 Word 转换为 OFD 和 PDF 的功能。此外,一些已知的问题也在最新版本中被成功修复,例如转换 Word 到 OFD 时, 多出了空白页的问题。详情请查阅以下内容。
问题修复:
不管是想要将重要的信息放到表格的开头,以便读者第一时间查阅,还是想修正表格中错误的排序,你都需要在 Excel 中重新排列行或列。使用 Python 进行这一操作可以使你轻松改变电子表格中数据的排序,并减少人工操作的错漏。
本文将介绍怎样使用 Spire.XLS for Python 在 Python 中重新排列 Excel 表格中的行或列。
本教程需要 Spire.XLS for Python 和 plum-dispatch v1.7.4。您可以通过以下 pip 命令将它们轻松安装到 Windows 中。
pip install Spire.XLS
如果您不确定如何安装,请参考此教程: 如何在 Windows 中安装 Spire.XLS for Python。
Spire.XLS 并未提供直接重新排列 Excel 工作表中列或行顺序的方法。解决方案需要创建一个目标工作表的副本。然后,你可以将副本工作表中的行或列以调整后的顺序复制到原始表格中。
下面是使用 Python 重新排列 Excel 表格中的列的步骤:
from spire.xls import *
from spire.xls.common import *
# 创建一个 Workbook 对象
workbook = Workbook()
# 加载 Excel 文档
workbook.LoadFromFile("sample2.xlsx")
# 获取指定工作表
targetSheet = workbook.Worksheets[0]
# 在列表中指定新的列的顺序(列的索引从0开始)
newColumnOrder = [0, 1, 2, 3, 7, 8, 9, 4, 5, 6, 10]
# 添加一个临时工作表
tempSheet = workbook.Worksheets.Add("temp")
# 将目标工作表的数据复制到临时工作表中
tempSheet.CopyFrom(targetSheet)
# 遍历新顺序列表
for i in range(len(newColumnOrder)):
# 将临时工作表的列按新顺序复制到目标工作表中
tempSheet.Columns[newColumnOrder[i]].Copy(targetSheet.Columns[i], True, True)
# 重置目标工作表的列宽
targetSheet.Columns[i].ColumnWidth = tempSheet.Columns[newColumnOrder[i]].ColumnWidth
# 删除临时工作表
workbook.Worksheets.Remove(tempSheet)
# 保存工作簿为新的 Excel 文档
workbook.SaveToFile("output/重排-列.xlsx", FileFormat.Version2016)
# 释放资源
workbook.Dispose()

在 Excel 电子表格中重新排列行的方法与调整列的顺序方法相类似。以下是重新排列 Excel 工作表中行的步骤。
from spire.xls import *
from spire.xls.common import *
# 创建一个 Workbook 对象
workbook = Workbook()
# 加载 Excel 文档
workbook.LoadFromFile("sample2.xlsx")
# 获取指定工作表
targetSheet = workbook.Worksheets[0]
# 在列表中指定新的行的顺序(行的索引从0开始)
newRowOrder = [0, 1, 4, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
# 添加一个临时工作表
tempSheet = workbook.Worksheets.Add("temp")
# 将目标工作表的数据复制到临时工作表中
tempSheet.CopyFrom(targetSheet)
# 遍历新顺序列表
for i in range(len(newRowOrder)):
# 将临时工作表的行按新顺序复制到目标工作表中
tempSheet.Rows[newRowOrder[i]].Copy(targetSheet.Rows[i], True, True)
# 重置目标工作表的行高
targetSheet.Rows[i].RowHeight = tempSheet.Rows[newRowOrder[i]].RowHeight
# 删除临时工作表
workbook.Worksheets.Remove(tempSheet)
# 保存工作簿为新的 Excel 文档
workbook.SaveToFile("output/重排-行.xlsx", FileFormat.Version2016)
# 释放资源
workbook.Dispose()

如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。
在 Excel 中,激活工作表或单元格是指将某个工作表或单元格设置为当前焦点,使其成为可以直接操作的对象。激活工作表和单元格是进行数据输入、编辑、格式化等操作的前提。这篇文章将介绍如何使用 Spire.XLS for Python 和 Python 在 Excel 中激活工作表和单元格。
此教程需要 Spire.XLS for Python 和 plum-dispatch v1.7.4。您可以通过以下 pip 命令将它们轻松安装到 Windows 中。
pip install Spire.XLS
如果您不确定如何安装,请参考: 如何在 Windows 中安装 Spire.XLS for Python
激活工作表意味着将指定的工作表设为活动工作表。激活后的工作表将出现在 Excel 的主窗口中,用户可以在该工作表中进行各类操作,如输入数据、创建图表、添加公式等。
Spire.XLS for Python 提供了 Worksheet.Activate() 方法,用于激活 Excel 工作簿中的特定工作表。具体步骤如下:
from spire.xls import *
from spire.xls.common import *
# 创建 Workbook 对象
workbook = Workbook()
# 加载 Excel 文件
workbook.LoadFromFile("示例.xlsx")
# 获取第二个工作表
sheet = workbook.Worksheets[1]
# 将该工作表设为活动工作表
sheet.Activate()
# 保存结果文件
workbook.SaveToFile("激活工作表.xlsx", FileFormat.Version2013)
workbook.Dispose()
打开结果文档,Excel 主窗口将显示第二个工作表:

激活单元格意味着将工作表中的某个特定单元格设置为活动单元格。激活后的单元格可以进行数据输入、编辑和格式设置等操作。
要激活工作表中的特定单元格,你可以使用 CellRange.Activate() 方法。具体步骤如下:
from spire.xls import *
from spire.xls.common import *
# 创建 Workbook 对象
workbook = Workbook()
# 加载 Excel 文件
workbook.LoadFromFile("示例.xlsx")
# 获取第二个工作表
sheet = workbook.Worksheets[1]
# 将该工作表设为活动工作表
sheet.Activate()
# 获取需要激活的单元格
cell = sheet.Range["B3"]
# 将该单元格设为活动单元格
cell.Activate()
# 保存结果文件
workbook.SaveToFile("激活单元格.xlsx", FileFormat.Version2013)
workbook.Dispose()
打开结果文档,第二个工作表的B3单元格将被鼠标选中:

如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。
Excel 页面设置是指 Microsoft Excel 中的一组设置选项,用于定义工作表或工作簿的打印或打印预览效果。这些设置包括页边距、方向、纸张大小、打印区域、页眉、页脚和打印缩放等参数。通过调整这些设置,你可以优化 Excel 文档在打印时的布局和外观。本文将讲解如何使用 Spire.XLS for Python 和 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 提供了 PageSetup 类,用于配置或修改 Excel 工作表的页面设置。你可以通过 Worksheet.PageSetup 属性获取特定工作表的 PageSetup 对象,然后使用 PageSetup 类的 TopMargin、BottomMargin、LeftMargin、RightMargin、HeaderMarginInch 和 FooterMarginInch 等属性设置相应的页边距。具体步骤如下:
from spire.xls import *
from spire.xls.common import *
# 创建 Workbook 对象
workbook = Workbook()
# 加载 Excel 文件
workbook.LoadFromFile("示例.xlsx")
# 获取第一个工作表
sheet = workbook.Worksheets[0]
# 获取工作表的 PageSetup 对象
pageSetup = sheet.PageSetup
# 设置工作表的上、下、左、右、页眉、页脚页边距(单位为英寸,1英寸 = 2.54厘米)
pageSetup.TopMargin = 1
pageSetup.BottomMargin = 1
pageSetup.LeftMargin = 1
pageSetup.RightMargin = 1
pageSetup.HeaderMarginInch = 1
pageSetup.FooterMarginInch = 1
# 将修改后的工作簿保存到新文件
workbook.SaveToFile("设置页边距.xlsx", ExcelVersion.Version2016)
workbook.Dispose()

要调整 Excel 工作表的页面方向,你可以使用 PageSetup 类的 Orientation 属性。具体步骤如下:
from spire.xls import *
from spire.xls.common import *
# 创建 Workbook 对象
workbook = Workbook()
# 加载 Excel 文件
workbook.LoadFromFile("示例.xlsx")
# 获取第一个工作表
sheet = workbook.Worksheets[0]
# 获取工作表的 PageSetup 对象
pageSetup = sheet.PageSetup
# 将工作表的打印页面方向设置为横向模式
pageSetup.Orientation = PageOrientationType.Landscape
# 将修改后的工作簿保存到新文件
workbook.SaveToFile("设置页面方向.xlsx", ExcelVersion.Version2016)
workbook.Dispose()

你还可以使用 PageSetup 类的 PaperSize 属性为 Excel 工作表设置多种纸张大小,如 A3、A4、A5、B4、B5、Letter、Legal 和 Tabloid 等。具体步骤如下:
from spire.xls import *
from spire.xls.common import *
# 创建 Workbook 对象
workbook = Workbook()
# 加载 Excel 文件
workbook.LoadFromFile("示例.xlsx")
# 获取第一个工作表
sheet = workbook.Worksheets[0]
# 获取工作表的 PageSetup 对象
pageSetup = sheet.PageSetup
# 将纸张大小设置为 A4
pageSetup.PaperSize = PaperSizeType.PaperA4
# 将修改后的工作簿保存到新文件
workbook.SaveToFile("设置纸张大小.xlsx", ExcelVersion.Version2016)
workbook.Dispose()

Excel 工作表的打印区域可以通过 PageSetup 类的 PrintArea 属性自定义。具体步骤如下:
from spire.xls import *
from spire.xls.common import *
# 创建 Workbook 对象
workbook = Workbook()
# 加载 Excel 文件
workbook.LoadFromFile("示例.xlsx")
# 获取第一个工作表
sheet = workbook.Worksheets[0]
# 获取工作表的 PageSetup 对象
pageSetup = sheet.PageSetup
# 将工作表的打印区域设置为 "A1:E5"
pageSetup.PrintArea = "A1:E5"
# 将修改后的工作簿保存到新文件
workbook.SaveToFile("设置打印区域.xlsx", ExcelVersion.Version2016)
workbook.Dispose()

通过使用 PageSetup 类的 Zoom 属性,你可以将工作表的内容缩放到原始大小的特定百分比。具体步骤如下:
from spire.xls import *
from spire.xls.common import *
# 创建 Workbook 对象
workbook = Workbook()
# 加载 Excel 文件
workbook.LoadFromFile("示例.xlsx")
# 获取第一个工作表
sheet = workbook.Worksheets[0]
# 获取工作表的 PageSetup 对象
pageSetup = sheet.PageSetup
# 将工作表的缩放比例设置为 90%
pageSetup.Zoom = 90
# 将修改后的工作簿保存到新文件
workbook.SaveToFile("设置缩放比例.xlsx", ExcelVersion.Version2016)
workbook.Dispose()

除了将工作表的内容缩放到原始大小的特定百分比外,你还可以使用 PageSetup 类的 FitToPagesTall 和 FitToPagesWide 属性将其适应到特定页数,例如1页。具体步骤如下:
from spire.xls import *
from spire.xls.common import *
# 创建 Workbook 对象
workbook = Workbook()
# 加载 Excel 文件
workbook.LoadFromFile("示例.xlsx")
# 获取第一个工作表
sheet = workbook.Worksheets[0]
# 获取工作表的 PageSetup 对象
pageSetup = sheet.PageSetup
# 将工作表内容在垂直方向上调整到一页(即所有行都适应到一页)
pageSetup.FitToPagesTall = 1
# 将工作表内容在水平方向上调整到一页(即所有列都适应到一页)
pageSetup.FitToPagesWide = 1
# 将修改后的工作簿保存到新文件
workbook.SaveToFile("调整为一页.xlsx", ExcelVersion.Version2016)
workbook.Dispose()

有关给 Excel 设置页眉和页脚的详细信息,请查看这篇文章:Python 添加页眉和页脚到 Excel。
如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。
Spire.Office for Java 9.7.0 已正式发布。该版本新增了一些功能,如 Spire.Doc for Java 支持转换 Word 文档到 HTML Fixed 格式的 HTML 文档时内嵌 CSS 和图片;Spire.Presentation for Java 支持给指定文本添加批注;Spire.Barcode for Java 支持获取条码信息,包括类型、数据值和顶点位置信息。此外,一些已知问题也在该版本中被成功修复。更多新功能及问题修复详情如下。
获取 Spire.Office for Java 9.7.0,请点击:https://www.e-iceblue.cn/Downloads/Spire-Office-JAVA.html
新功能:
String inputFile = "1.docx";
String outputFile ="1.html";
Document doc = new Document();
doc.loadFromFile(inputFile);
doc.getHtmlExportOptions().setCssStyleSheetType(CssStyleSheetType.Internal);
doc.getHtmlExportOptions().setImageEmbedded(true);
doc.saveToFile(outputFile, FileFormat.HtmlFixed);
doc.dispose();问题修复:
问题修复:
新功能:
Presentation ppt = new Presentation();
ISlide slide = ppt.getSlides().get(0);
IAutoShape shape = ppt.getSlides().get(0).getShapes().appendShape(ShapeType.RECTANGLE, new Rectangle2D.Double(100, 250, 350, 200));
ppt.getSlides().get(0).getShapes().get(0).getLine().getFillFormat().getSolidFillColor().setColor(Color.white);
shape.getFill().setFillType(FillFormatType.SOLID);
shape.getFill().getSolidColor().setColor(Color.GRAY);
ParagraphEx paragraphEx = shape.getTextFrame().getTextRange().getParagraph();
PortionEx ex = new PortionEx("文本文本文本md文本文本文本文本\ttmd文本文本文本文本md文本文本文本文\tt本md文本文本文本文本md文本文\tt本文本文本md文");
paragraphEx.getTextRanges().append(ex);
ICommentAuthor commentAuthor = ppt.getCommentAuthors().addAuthor("测试","12");
paragraphEx.addComment(commentAuthor,slide,shape,ex,"123");
String result = "result.pptx";
ppt.saveToFile(result, FileFormat.PPTX_2013);
Presentation ppt = new Presentation();
ppt.loadFromFile(inputFile);
ISlide slide = ppt.getSlides().get(0);
IAutoShape shape = (IAutoShape) slide.getShapes().get(0);
ParagraphEx paragraphEx = shape.getTextFrame().getTextRange().getParagraph();
PortionEx portionEx = paragraphEx.getTextRanges().get(0);
ICommentAuthor commentAuthor = ppt.getCommentAuthors().addAuthor("测试","18");
paragraphEx.addComment(commentAuthor,slide,shape,portionEx,"123456789");
String result = "result.pptx";
ppt.saveToFile(result, FileFormat.PPTX_2013);问题修复:
新功能:
BarcodeInfo[] infos = BarcodeScanner.scanInfo("barcode.png");
Point[] loaction = infos[0].getVertexes();
BarCodeReadType barCodeReadType = infos[0].getReadType();
String dataString = infos[0].getDataString();String[] s = BarcodeScanner.scan("AZTEC.png",BarCodeType.Aztec);Public static String[] scan(BufferedImage bitmap, java.awt.Rectangle rect, BarCodeType barcodeType, boolean IncludeCheckSum)
Public static String[] scan(String fileName, BarCodeType barcodeType, boolean IncludeCheckSum)
Public static String scanOne(String fileName, BarCodeType barcodeType, boolean IncludeCheckSum)
Public static String scanOne(InputStream stream, BarCodeType barcodeType, boolean IncludeCheckSum)com.spire.barcode.publics.drawing.FontStyle
com.spire.barcode.publics.drawing.GraphicsUnit
com.spire.barcode.publics.drawing.StringAlignmentpublic java.awt.Font getTopTextFont()
public java.awt.Font getBottomTextFont()
public java.awt.Font getTextFont()public void setBottomTextFont(java.awt.Font value)->public void setBottomTextFont(String familyName, float fontSize)
public void setTopTextFont(java.awt.Font value)->public void setTopTextFont(String familyName, float fontSize)
public boolean showBottomText->public boolean isShowBottomText()
public void setShowBottomText(boolean value) -> public void isShowBottomText(boolean value)
public com.spire.barcode.GraphicsUnit getUnit() -> public com.spire.barcode.publics.drawing.GraphicsUnit getUnit()
public void setUnit(com.spire.barcode.GraphicsUnit value) -> public void setUnit(com.spire.barcode.publics.drawing.GraphicsUnit value)
public void setTextFont(java.awt.Font value) -> public void setTextFont(String familyName, float fontSize)
public float getLeftMargin() ->The default value adjusted from 5 to 4. public float getTopTextMargin()
public void setTopTextMargin(float value)
public int getAztecErrorCorrection()
public void setAztecErrorCorrection(int value)
public int getAztecLayers()
public void setAztecLayers(int value)
public DataMatrixSymbolShape getDataMatrixSymbolShape()
public void setDataMatrixSymbolShape(DataMatrixSymbolShape value)
public ITF14BorderType getITF14BearerBars()
public void setITF14BearerBars(ITF14BorderType value)
public void setTextFont(String familyName, float fontSize, com.spire.barcode.publics.drawing.FontStyle style)
public boolean isShowStartCharAndStopChar()
public void isShowStartCharAndStopChar(boolean value)public java.awt.Font getTextFont()
public java.awt.Font getTopTextFont()
public java.awt.Font getBottomTextFont()public void setTextFont(java.awt.Font value) -> public void setTextFont(String familyName, float sizePoints)
public com.spire.barcode.GraphicsUnit getUnit() -> public com.spire.barcode.publics.drawing.GraphicsUnit getUnit()
public void setUnit(com.spire.barcode.GraphicsUnit value) -> public void setUnit(com.spire.barcode.publics.drawing.GraphicsUnit value)
public com.spire.barcode.StringAlignment getTextAlignment() -> public com.spire.barcode.publics.drawing.StringAlignment getTextAlignment()
public void setTextAlignment(com.spire.barcode.StringAlignment value) -> public void setTextAlignment(com.spire.barcode.publics.drawing.StringAlignment value)
public com.spire.barcode.StringAlignment getTopTextAligment() -> public com.spire.barcode.publics.drawing.StringAlignment getTopTextAligment()
public void setTopTextAligment(com.spire.barcode.StringAlignment value) -> public void setTopTextAligment(com.spire.barcode.publics.drawing.StringAlignment value)
public void setBottomTextFont(java.awt.Font value) -> public void setBottomTextFont(String familyName, float fontSize)
public void setTopTextFont(java.awt.Font value) -> public void setTopTextFont(String familyName, float fontSize)
public boolean showBottomText->public boolean isShowBottomText()
public void setShowBottomText(boolean value) -> public void isShowBottomText(boolean value)
public com.spire.barcode.StringAlignment getBottomTextAlignment() -> public com.spire.barcode.publics.drawing.StringAlignment getBottomTextAlignment()
public void setBottomTextAlignment(com.spire.barcode.StringAlignment value) -> public void setBottomTextAlignment(com.spire.barcode.publics.drawing.StringAlignment value)
public float getLeftMargin() ->The default value adjusted from 5 to 4. public float getTopTextMargin()
public void setTopTextMargin(float value)
public void setTextFont(String familyName, float sizePoints, com.spire.barcode.publics.drawing.FontStyle style)
public void setTopTextFont(String familyName, float fontSize, com.spire.barcode.publics.drawing.FontStyle style)
public void setITF14BearerBars(ITF14BorderType value)
public boolean isShowStartCharAndStopChar()
public void isShowStartCharAndStopChar(boolean value)
public int getAztecLayers()
public void setAztecLayers(int value)
public int getAztecErrorCorrection()
public void setAztecErrorCorrection(int value)
public DataMatrixSymbolShape getDataMatrixSymbolShape()
public void setDataMatrixSymbolShape(DataMatrixSymbolShape value)
public void setBottomTextFont(String familyName, float fontSize, com.spire.barcode.publics.drawing.FontStyle style)新功能:
import com.spire.ocr.*;
import java.awt.geom.Rectangle2D;
public class OCRTest {
public static void main(String[] args) throws Exception{
OcrScanner scanner = new OcrScanner();
ConfigureOptions configureOptions = new ConfigureOptions("D:\\LanguageModel", "English");
String dependencies = "dependencies/";
configureOptions.setLibPath(dependencies);
scanner.ConfigureDependencies(configureOptions);
String imageFile = "Sample.png";
scanner. scan(imageFile);
String scannedText=scanner.getText().toString();
StringBuilder stringBuilder=new StringBuilder();
for(IOCRTextBlock blockItem :scanner.getText().getBlocks()){
Rectangle2D rectangle2D=blockItem.getBox();
stringBuilder.append(blockItem.getText() +","+ "X"+ rectangle2D.getX()+"; Y:"+rectangle2D.getY()+ "; Width:"+ rectangle2D.getWidth()+ "; Height:"+ rectangle2D.getHeight());
}
}
}Spire.Doc for Java 12.7.17 已发布。本次更新新增支持转换 Word 文档到 HTML Fixed 格式的 HTML 文档时内嵌 CSS 和图片的功能。该版本还增强了 DOCX 到 OFD、PDF 和 HTML 的转换功能。此外,许多已知问题也在该版本中成功修复,如添加的图片方向不正确的问题。详情请阅读以下内容。
新功能:
String inputFile = "1.docx";
String outputFile ="1.html";
Document doc = new Document();
doc.loadFromFile(inputFile);
doc.getHtmlExportOptions().setCssStyleSheetType(CssStyleSheetType.Internal);
doc.getHtmlExportOptions().setImageEmbedded(true);
doc.saveToFile(outputFile, FileFormat.HtmlFixed);
doc.dispose();问题修复:
XLS 和 XLSX 是 Microsoft Excel 电子表格的两种不同文件格式。XLS 是 Microsoft Excel 2003 及以前版本的默认文件格式,而 XLSX 是 Microsoft Excel 2007 及以后版本的默认文件格式。在某些情况下,开发人员可能需要在Excel的这两种文件格式之间进行转换。本文将介绍如何使用 Spire.XLS for .NET 在 C# 中将 XLS 转换为 XLSX 或将 XLSX 转换为 XLS。
首先,您需要将 Spire.XLS for .NET 包含的 DLL 文件作为引用添加到您的 .NET 项目中。DLL 文件可以从此链接下载,也可以通过 NuGet 安装。
PM> Install-Package Spire.XLS
Spire.XLS for .NET 支持的 Excel 版本涵盖旧版的 Excel 97-2003 以及新版的 Excel 2007、Excel 2010、Excel 2013、Excel 2016、Excel 2019。以下是将一个 XLS 文件转换为 XLSX 文件的步骤:
using Spire.Xls;
namespace ConvertXlsToXlsx
{
class Program
{
static void Main(string[] args)
{
//创建Workbook对象
Workbook workbook = new Workbook();
//加载一个XLS文件
workbook.LoadFromFile("示例.xls");
//将XLS文件另存为XLSX格式
workbook.SaveToFile("转Xlsx.xlsx", ExcelVersion.Version2016);
}
}
}

要实现该转换,可以先加载一个 .xlsx 文件,然后通过 Workbook.SaveToFile(string fileName, ExcelVersion.Version97to2003) 方法将其另存为 Excel 97-2003 (.xls) 格式文档 。具体步骤如下:
using Spire.Xls;
namespace ConvertXlsxToXls
{
class Program
{
static void Main(string[] args)
{
//创建Workbook对象
Workbook workbook = new Workbook();
//加载一个XLSX文件
workbook.LoadFromFile("报价.xlsx");
//将XLSX文件转为XLS格式
workbook.SaveToFile("转Xls.xls", ExcelVersion.Version97to2003);
}
}
}

如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。
Spire.Presentation for Java 9.7.6 已发布。该版本支持给指定文本添加批注,并修复了一些已知问题,如添加内容到形状后,形状高度不正确的问题。详情请查看以下内容。
新功能:
Presentation ppt = new Presentation();
ISlide slide = ppt.getSlides().get(0);
IAutoShape shape = ppt.getSlides().get(0).getShapes().appendShape(ShapeType.RECTANGLE, new Rectangle2D.Double(100, 250, 350, 200));
ppt.getSlides().get(0).getShapes().get(0).getLine().getFillFormat().getSolidFillColor().setColor(Color.white);
shape.getFill().setFillType(FillFormatType.SOLID);
shape.getFill().getSolidColor().setColor(Color.GRAY);
ParagraphEx paragraphEx = shape.getTextFrame().getTextRange().getParagraph();
PortionEx ex = new PortionEx("文本文本文本md文本文本文本文本\ttmd文本文本文本文本md文本文本文本文\tt本md文本文本文本文本md文本文\tt本文本文本md文");
paragraphEx.getTextRanges().append(ex);
ICommentAuthor commentAuthor = ppt.getCommentAuthors().addAuthor("测试","12");
paragraphEx.addComment(commentAuthor,slide,shape,ex,"123");
String result = "result.pptx";
ppt.saveToFile(result, FileFormat.PPTX_2013);
Presentation ppt = new Presentation();
ppt.loadFromFile(inputFile);
ISlide slide = ppt.getSlides().get(0);
IAutoShape shape = (IAutoShape) slide.getShapes().get(0);
ParagraphEx paragraphEx = shape.getTextFrame().getTextRange().getParagraph();
PortionEx portionEx = paragraphEx.getTextRanges().get(0);
ICommentAuthor commentAuthor = ppt.getCommentAuthors().addAuthor("测试","18");
paragraphEx.addComment(commentAuthor,slide,shape,portionEx,"123456789");
String result = "result.pptx";
ppt.saveToFile(result, FileFormat.PPTX_2013);问题修复:
https://www.e-iceblue.cn/Downloads/Spire-Presentation-JAVA.html
Spire.Office for Python 9.7.0 已发布。在该版本中,Spire.PDF for Python 支持转换 PDF 文档到 PPTX 文档,同时新增文档的加密和解密接口以及删除图片的方法。此外,许多已知问题也在该版本中成功修复。详情请阅读以下内容。
获取 Spire.Office for Python 9.7.0 请点击:https://www.e-iceblue.cn/Downloads/Spire-Office-Python.html
新功能:
# 加密
pdfDocument = PdfDocument()
securityPolicy = PdfPasswordSecurityPolicy("123456789", "M123456789")
securityPolicy.EncryptionAlgorithm = PdfEncryptionAlgorithm.AES_128
securityPolicy.DocumentPrivilege = PdfDocumentPrivilege.ForbidAll()
securityPolicy.DocumentPrivilege.AllowPrint = True
pdfDocument.Encrypt(securityPolicy)
pdfMargin = PdfMargins()
unitCvtr = PdfUnitConvertor()
pdfMargin.Left = unitCvtr.ConvertUnits(0, PdfGraphicsUnit.Pixel, PdfGraphicsUnit.Point)
pdfMargin.Right = unitCvtr.ConvertUnits(0,PdfGraphicsUnit.Pixel, PdfGraphicsUnit.Point)
pdfMargin.Top = unitCvtr.ConvertUnits(0, PdfGraphicsUnit.Pixel, PdfGraphicsUnit.Point)
pdfMargin.Bottom = unitCvtr.ConvertUnits(0, PdfGraphicsUnit.Pixel, PdfGraphicsUnit.Point)
pageSize = PdfPageSize.A4()
spirePage = pdfDocument.Pages.Add(pageSize, pdfMargin)
pdfDocument.SaveToFile("1.pdf", FileFormat.PDF)
pdfDocument.Dispose()
# 解密
pdfDocument = PdfDocument()
pdfDocument.LoadFromFile("input.pdf","123456789")
pdfDocument.Decrypt("M123456789")
pdfDocument.SaveToFile("output.pdf", FileFormat.PDF)
pdfDocument.Dispose()pdf = PdfDocument()
pdf.LoadFromFile(inputfile)
page = pdf.Pages[0]
imageHelper = PdfImageHelper()
imageInfos = imageHelper.GetImagesInfo(page)
imageHelper.DeleteImage(imageInfos[0])
pdf.SaveToFile(outputFile, FileFormat.PDF)
pdf.Close()pdfDocument = PdfDocument()
pdfDocument.LoadFromFile("Sample.pdf")
pdfDocument.SaveToFile("ConvertPDFtoPowerPoint.pptx", FileFormat.PPTX)问题修复:
问题修复:
问题修复:
问题修复: