Spire.Office for Java 9.12.0 已发布。在该版本中,Spire.PDF for Java 新增支持从流中加载带密码的 PDF 文档;Spire.OCR for Java 支持 macOS 10.15 及更高版本使用,同时提高了内存回收效率和文字识别速度。此外,许多已知问题也在该版本中成功修复。详情请阅读以下内容。
获取 Spire.Office for Java 9.12.0,请点击:https://www.e-iceblue.cn/Downloads/Spire-Office-JAVA.html
新功能:
问题修复:
问题修复:
问题修复:
问题修复:
新功能:
问题修复:
Spire.Doc for Java 12.12.21 现已正式发布。最新版本修复了转换 Word 文档到 PDF 文档时字符不正确的问题。详情请查阅下面的内容。
问题修复:
Spire.PDF for Java 10.12.10 已发布。该版本新增支持从流中加载带密码的 PDF 文档,同时增强了 PDF 到 Excel、文本和 OFD 的转换功能。此外,一些已知问题也在该版本中成功修复,如数字签名验证失败的问题。详情请阅读以下内容。
新功能:
问题修复:
Spire.Office for Python 9.12.1 已正式发布。在该版本中,Spire.Doc for Python 支持将 Word 文档标记为 "final",并支持设置 Word 装订线的位置。Spire.PDF for Python 支持数字签名功能,以及将 imageInfo[i].Image 返回为 byte[] 类型。Spire.XLS for Python 新增了 workbook.Chartsheets 属性和 excelPicture.HyperLink 属性。Spire.Presentation for Python 支持获取 section 中的幻灯片。此外,一些在转换、处理和保存 Word/Excel/PDF/PowerPoint 文件时出现的问题也已成功被修复。更多新功能及问题修复详情如下。
获取 Spire.Office for Python 9.12.1,请点击:https://www.e-iceblue.cn/Downloads/Spire-Office-Python.html
新功能:
from spire.doc import *
from spire.doc.common import *
document = Document()
document.LoadFromFile("in.docx")
customProperties = document.CustomDocumentProperties
customProperties.Add("_MarkAsFinal", Boolean(True))
document.SaveToFile("out.docx", FileFormat.Docx2013)from spire.doc import *
from spire.doc.common import *
document = Document()
sec = None
for i in range(0, 10):
sec = document.AddSection()
sec.PageSetup.IsTopGutter = False
para = sec.AddParagraph()
txtRange = para.AppendText("Test")
sec.PageSetup.Gutter = 50 + i*10
document.SaveToFile(outputFile, FileFormat.Docx)
document.Close()from spire.doc import *
from spire.doc.common import *
document = Document()
document.LoadFromFile(inputFile)
document.SetCustomFontsFolders(document,"Angsana New")
document.SaveToFile(outputFile, FileFormat.PDF)
document.Close()from spire.doc import *
from spire.doc.common import *
document = Document()
#Load the file from disk.
document.LoadFromFile(inputFile)
for i in range(document.Sections.Count):
sec = document.Sections.get_Item(i)
#Iterate through the element under body in the section
for j in range(sec.Body.ChildObjects.Count):
docItem = sec.Body.ChildObjects.get_Item(j)
if isinstance(docItem, Paragraph):
para = docItem
if para.IsInsertRevision:
para.InsertRevision.Author="Spire.Doc Insert"
elif para.IsDeleteRevision:
para.DeleteRevision.Author="Spire.Doc Insert"
for k in range(para.ChildObjects.Count):
textRange = para.ChildObjects.get_Item(k)
if isinstance(textRange, TextRange):
if textRange.IsInsertRevision:
textRange.InsertRevision.Author="Spire.Doc Insert"
elif textRange.IsDeleteRevision:
textRange.DeleteRevision.Author="Spire.Doc Insert"
#Save to file.
document.SaveToFile(outputFile, FileFormat.Docx2013)
document.Close()问题修复:
新功能:
book = Workbook()
book.LoadFromFile(inputFile)
# Retain the page size set
book.ConverterSetting.SheetFitToPageRetainPaperSize = True
book.SaveToFile(outputFile, FileFormat.PDF)问题修复:
新功能:
byteResult = imageInfo[i].Image.ToArray()
fileName = outputFile_1 + "Bug_6888_{0:d}.png".format(i)
with open(fileName,'wb') as f:
f.write(byteResult)pdf=PdfDocument()
pdf.LoadFromFile(inputFile)
page = pdf.Pages[0]
textreplacer = PdfTextReplacer(page)
options = PdfTextReplaceOptions()
options.ReplaceType = ReplaceActionType.WholeWord
textreplacer.Options = options
textreplacer.ReplaceAllText("荷塘", "池塘")
pdf.SaveToFile(outputFile)pdf = PdfDocument()
pdf.LoadFromFile(inputFile)
inder = PdfTextFinder(pdf.Pages[0])
fragments = finder.Find("PDF")
sb = []
for fragment in fragments:
sb.append(fragment.TextStates[0].FontName)
sb.append(fragment.TextStates[0].FontFamily)
sb.append(str(round(fragment.TextStates[0].FontSize,2)))
File.AppendAllText(outputFile,sb)
pdf.Close()# Load a Pdf document from disk
doc = PdfDocument()
doc.LoadFromFile(inputFile)
# Create a signature maker with the PDF document and PFX file
signatureMaker = PdfOrdinarySignatureMaker(doc, inputFile_pfx, "e-iceblue")
# Configure the signature properties
signature = signatureMaker.Signature
signature.Name = "Gary"
signature.ContactInfo = "028-81705109"
signature.Location = "Chengdu"
signature.Reason = "The certificate of this document"
# Create a signature appearance
appearance = PdfSignatureAppearance(signature)
appearance.NameLabel = "Signer: "
appearance.ContactInfoLabel = "ContactInfo: "
appearance.LocationLabel = "Location: "
appearance.ReasonLabel = "Reaseon: "
appearance.SignatureImage = PdfImage.FromFile(inputImage)
appearance.GraphicMode = GraphicMode.SignImageAndSignDetail
appearance.SignImageLayout = SignImageLayout.none
# Apply the signature to the PDF document
signatureMaker.MakeSignature("Signer:", doc.Pages.get_Item(0), 90.0, 550.0, 270.0, 90.0, appearance)
# Save the document
doc.SaveToFile(outputFile)问题修复:
新功能:
ppt = Presentation()
ppt.LoadFromFile(inputFile)
section=ppt.SectionList[0]
slides=section.GetSlides()
sb = [] i=0 for slide in slides:
sb.append("SlideID:"+str(slides[i].SlideID))
i=i+1
File.AppendAllText(outputFile, sb)
ppt.Dispose# Create a Presentation oject
presentation = Presentation()
# Load a PowerPoint document
presentation.LoadFromFile(inputFile)
sb = []
# Get custom document properties
for shape in presentation.Slides[0].Shapes:
if isinstance(shape, ISmartArt):
sa = shape if isinstance(shape, ISmartArt) else None
sb.append("left: " + str(sa.Left))
sb.append("top: " + str(sa.Top))
File.AppendAllText(outputFile, sb)
presentation.Dispose()# Create a Presentation oject
presentation = Presentation()
presentation.LoadFromFile(inputFile)
shape = presentation.Slides[0].Shapes[0]
textrange = shape.TextFrame.Paragraphs[0].TextRanges[0]
displayformat = textrange.DisplayFormat
sb = []
sb.append("text :" + str(textrange.Text))
sb.append("is bold :" + str(displayformat.IsBold))
sb.append("is italic :" + str(displayformat.IsItalic))
sb.append("latin_font FontName = :" + str(displayformat.LatinFont.FontName))
File.AppendAllText(outputFile, sb)
presentation.Dispose()问题修复:
Spire.Office 9.12.0 已发布,在该版本中,Spire.Doc 支持在段落中查找文本;Spire.XLS 支持 SEC、WRAPCOLS、REPTARRAY、PERCENTOF、SUBSTITUTES 等函数;Spire.PDF 支持进行多页打印时设置自动旋转方向;Spire.Presentation 增强了 PPT 到 PDF 的转换功能;Spire.Barcode 修复了扫描出的二维码的结果不正确的问题;Spire.OCR 优化了内存回收效率和识别速度。
此外,该版本还成功修复了大量已知问题。详情请阅读以下内容。
版本信息如下:
https://www.e-iceblue.cn/Downloads/Spire-Office-NET.html
新功能:
paragraph.FindAllString();
paragraph.FindAllPattern();问题修复:
新功能:
问题修复:
新功能:
PdfMultiPageLayout printParameters = pdf.PrintSettings.SelectMultiPageLayout(1, 2);
printParameters.AutoRotate = true;
pdf.PrintSettings.Duplex = Duplex.Horizontal;PdfDocument doc = new PdfDocument();
doc.LoadFromFile(inputFile);
PdfFormWidget formWidget = (PdfFormWidget)doc.Form;
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine("btnAction:");
for (int i = 0; i < formWidget.FieldsWidget.Count; ++i)
{
var field = formWidget.FieldsWidget[i] as PdfButtonWidgetFieldWidget;
if (field.Actions.MouseUp != null && field.Actions.MouseUp is PdfNamedAction)
{
var mouseUp = (PdfNamedAction)field.Actions.MouseUp;
stringBuilder.AppendLine(formWidget.FieldsWidget[i].Name + "-MouseUp-" + mouseUp.Destination.ToString());
}
else if (field.Actions.MouseDown != null && field.Actions.MouseDown is PdfNamedAction)
{
var mouseDown = (PdfNamedAction)field.Actions.MouseDown;
stringBuilder.AppendLine(formWidget.FieldsWidget[i].Name + "-MouseDown--" + mouseDown.Destination.ToString());
}
else if (field.Actions.MouseDown != null && field.Actions.MouseDown is PdfUriAction)
{
var mouseDown = (PdfUriAction)field.Actions.MouseDown;
stringBuilder.AppendLine(formWidget.FieldsWidget[i].Name + "-MouseDown--" + mouseDown.Uri.ToString());
}
else if (field.Actions.MouseUp != null && field.Actions.MouseUp is PdfUriAction)
{
var mouseUp = (PdfUriAction)field.Actions.MouseUp;
stringBuilder.AppendLine(formWidget.FieldsWidget[i].Name + "-MouseUp-" + mouseUp.Uri.ToString());
}
}
File.WriteAllText(outputFile, stringBuilder.ToString());
doc.Dispose();问题修复:
问题修复:
问题修复:
问题修复:
Spire.XLS for Python 14.12.0 已发布。本次更新修复了转换 Excel 文档到 PDF 文档时文本位置不正确的问题。详情请阅读以下内容。
问题修复:
通过 C# 中的流进行操作,开发者可以动态地创建、加载、修改和保存 Excel 文件,从而实现灵活高效的数据处理。这种方法可以在很大程度上减少直接的磁盘 I/O 操作,不仅提升了应用程序性能,还增强了响应能力。尤其适用于实时数据操作或存储受限的场景,可以简化数据交换和系统集成。本文通过 Spire.XLS for .NET 演示如何使用 C# 通过流创建、加载、修改和保存 Excel 文件,为数据管理提供灵活且可扩展的解决方案。
首先,您需要将 Spire.XLS for .NET 包含的 DLL 文件作为引用添加到您的 .NET 项目中。DLL 文件可以从此链接下载,也可以通过 NuGet 安装。
PM> Install-Package Spire.XLS
利用 Spire.XLS for .NET,开发者可以通过初始化 Workbook 对象动态创建 Excel 文件,然后填充数据并设置格式,最后使用 Workbook.SaveToStream() 方法将其保存到流。这种方法可以省去直接对磁盘进行文件存储的需求,同时提升了应用的性能和响应速度。
以下是通过 C# 创建 Excel 文件并保存到流的步骤:
using Spire.Xls;
using System.Data;
using System.Drawing;
namespace CreateExcelStream
{
class Program
{
static void Main(string[] args)
{
// 创建一个新的工作簿实例
Workbook workbook = new Workbook();
// 获取工作簿中的第一个工作表
Worksheet sheet = workbook.Worksheets[0];
// 创建并填充一个包含示例数据的 DataTable
DataTable dataTable = new DataTable("Data");
dataTable.Columns.Add("编号", typeof(int));
dataTable.Columns.Add("姓名", typeof(string));
dataTable.Columns.Add("年龄", typeof(int));
dataTable.Columns.Add("国家", typeof(string));
dataTable.Columns.Add("工资 (¥)", typeof(decimal));
dataTable.Rows.Add(1, "张伟", 29, "中国", 8000m);
dataTable.Rows.Add(2, "李娜", 35, "中国", 12000m);
dataTable.Rows.Add(3, "王强", 42, "中国", 15000m);
dataTable.Rows.Add(4, "杰克", 26, "美国", 9500m);
dataTable.Rows.Add(5, "陈思", 31, "中国", 11000m);
dataTable.Rows.Add(6, "石原安子", 28, "日本", 8800m);
// 将 DataTable 中的数据插入到工作表中
sheet.InsertDataTable(dataTable, true, 1, 1);
// 格式化工作表
// 设置表头行的样式
sheet.Rows[0].Style.Color = Color.LightSkyBlue;
sheet.Rows[0].Style.Font.FontName = "微软雅黑";
sheet.Rows[0].Style.Font.Size = 12f;
sheet.Rows[0].BorderAround(); // 给表头行添加外边框
sheet.Rows[0].Borders.Color = Color.LightSteelBlue; // 设置边框颜色
// 设置数据行的样式
for (int i = 1; i < sheet.AllocatedRange.Rows.Count(); i++)
{
sheet.Rows[i].Style.Color = Color.LightGray;
sheet.Rows[i].Style.Font.FontName = "微软雅黑";
sheet.Rows[i].Style.Font.Size = 11f;
}
sheet.Range[2, 1, sheet.Rows.Count(), sheet.Columns.Count()].BorderInside(); // 添加数据行单元格内边框
sheet.Range[2, 1, sheet.Rows.Count(), sheet.Columns.Count()].Borders.Color = Color.LightSteelBlue; // 设置边框颜色
// 调整列宽以适应内容
for (int j = 1; j <= sheet.AllocatedRange.Columns.Count(); j++)
{
sheet.AutoFitColumn(j);
}
// 将工作簿保存到内存流
MemoryStream stream = new MemoryStream();
workbook.SaveToStream(stream, FileFormat.Version2016);
// 将流内容写入到文件
File.WriteAllBytes("output/通过流创建Excel文件.xlsx", stream.ToArray());
// 释放资源
workbook.Dispose();
}
}
}

通过 Spire.XLS for .NET,开发者可以利用 Workbook.LoadFromStream() 方法直接从流加载 Excel 文件。加载完成后,可以轻松读取到流中 Excel 文件的单元格数据,实现快速灵活的数据处理,而无需文件 I/O 操作。
以下是通过 C# 从流加载并读取 Excel 文件的步骤:
using Spire.Xls;
namespace LoadExcelStream
{
class Program
{
static void Main(string[] args)
{
// 创建一个 Workbook 类的实例
Workbook workbook = new Workbook();
// 创建一个内存流
MemoryStream stream = new MemoryStream();
File.OpenRead("Sample.xlsx").CopyTo(stream);
// 从内存流加载 Excel 文件
workbook.LoadFromStream(stream);
// 获取工作簿中的第一个工作表
Worksheet sheet = workbook.Worksheets[0];
// 初始化一个列表,用于存储从工作表中提取的数据
List<List<string>> data = new List<List<string>>();
for (int i = 0; i < sheet.AllocatedRange.Rows.Count(); i++)
{
// 创建一个列表来存储每行数据
List<string> lines = new List<string>();
for (int j = 0; j < sheet.AllocatedRange.Columns.Count(); j++)
{
// 获取单元格的值并添加到当前行的列表中
lines.Add(sheet.AllocatedRange[i + 1, j + 1].Value);
}
// 将当前行的数据添加到数据列表中
data.Add(lines);
}
// 打印提取的数据,或将其用于后续操作
foreach (List<string> lines in data)
{
Console.WriteLine(string.Join(" | ", lines));
}
}
}
}

借助 Spire.XLS for .NET,开发者可以在内存中修改 Excel 文件。首先通过 LoadFromStream() 方法将流中的 Excel 文件加载到 Workbook 对象中。完成修改(例如更改单元格值或格式)后,可以使用 Workbook.SaveToStream() 方法将文件保存回流。无需依赖直接的文件存储操作即可实现实时的 Excel 文件数据更改。
以下是通过 C# 修改流中 Excel 文件的步骤:
using Spire.Xls;
using System.Drawing;
namespace ModifyExcelStream
{
class Program
{
static void Main(string[] args)
{
// 创建 Workbook 类的一个新实例
Workbook workbook = new Workbook();
// 创建一个内存流
MemoryStream stream = new MemoryStream();
File.OpenRead("Sample.xlsx").CopyTo(stream);
// 从内存流加载 Excel 文件
workbook.LoadFromStream(stream);
// 获取工作簿中的第一个工作表
Worksheet sheet = workbook.Worksheets[0];
// 修改表头行的样式
CellRange headerRow = sheet.AllocatedRange.Rows[0];
headerRow.Style.Font.FontName = "宋体";
headerRow.Style.Font.Size = 12f;
headerRow.Style.Color = Color.LightBlue;
// 修改数据行的样式
for (int i = 1; i < sheet.AllocatedRange.Rows.Count(); i++)
{
CellRange dataRow = sheet.AllocatedRange.Rows[i];
dataRow.Style.Font.FontName = "宋体";
dataRow.Style.Font.Size = 10f;
dataRow.Style.Color = Color.LightGray;
// 交替着色(偶数行)
if (i % 2 == 0)
{
dataRow.Style.Color = Color.LightSlateGray;
}
}
// 自动调整列宽以适应内容
for (int k = 1; k <= sheet.AllocatedRange.Columns.Count(); k++)
{
sheet.AutoFitColumn(k);
}
// 修改边框颜色
sheet.AllocatedRange.Style.Borders.Color = Color.White;
// 将修改后的工作簿保存回内存流
workbook.SaveToStream(stream);
// 将流内容写入到一个新文件
File.WriteAllBytes("output/通过流修改Excel文件.xlsx", stream.ToArray());
// 释放资源
workbook.Dispose();
}
}
}

如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。
Word 文档中的批注通常用于协作审阅和反馈。这些批注可能包含文本和图片,它们为文档改进提供了重要的参考信息。提取批注中的文本和图片可以帮助你分析和评估审阅者的反馈,从而全面了解文档的优点、缺点以及改进建议。本文将演示如何使用 Spire.Doc for Java 在 Java 中提取 Word 文档中的批注文本和图片。
首先,您需要在 Java 程序中添加 Spire.Doc.jar 文件作为依赖项。JAR 文件可以从此链接下载。 如果您使用 Maven,则可以将以下代码添加到项目的 pom.xml 文件中,从而轻松地在应用程序中导入 JAR 文件。
<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>https://repo.e-iceblue.cn/repository/maven-public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.doc</artifactId>
<version>14.9.5</version>
</dependency>
</dependencies>
使用 Java 获取 Word 文档批注中的文本并不难。首先遍历 Word 文档中的所有批注,然后使用 Spire.Doc for Java 提供的 Document.getComments().get() 方法获取当前的批注,再然后遍历批注正文的每一个段落并获取当前段落,最后使用 Paragraph.getText() 方法获取该段落的文本。下面是具体的操作步骤:
import com.spire.doc.*;
import com.spire.doc.documents.*;
import com.spire.doc.fields.*;
import java.io.*;
public class ExtractComments {
public static void main(String[] args) throws IOException {
// 创建一个 Document 类的对象
Document doc = new Document();
// 加载一个 Word 文档
doc.loadFromFile("/AI绘画的利弊及法律应对.docx");
// 遍历文档中的每个批注
for (int i = 0; i < doc.getComments().getCount(); i++) {
// 获取当前索引处的批注
Comment comment = doc.getComments().get(i);
// 遍历批注正文中的每个段落
for (int j = 0; j < comment.getBody().getParagraphs().getCount(); j++) {
// 获取当前的段落
Paragraph para = comment.getBody().getParagraphs().get(j);
// 获取该段落的文本
String result = para.getText() + "\r\n";
// 将提取到的批注保存为文本文件
writeStringToTxt(result, "/批注信息.txt");
}
}
// 释放资源
doc.dispose();
}
// 自定义将数据写入到文本文件的方法
public static void writeStringToTxt(String content, String txtFileName) throws IOException {
FileWriter fWriter = new FileWriter(txtFileName);
try {
// 写入文本文件
fWriter.write(content);
} catch (IOException ex) {
ex.printStackTrace();
} finally {
try {
// 关闭文件写入器
fWriter.flush();
fWriter.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}

要从 Word 文档的批注中提取图片,需要遍历批注段落中的子对象,找到 DocPicture 对象。然后通过 DocPicture.getImageBytes() 方法获取图片数据,并将其保存为图像文件。
import com.spire.doc.*;
import com.spire.doc.documents.*;
import com.spire.doc.fields.*;
import java.io.*;
import java.nio.file.*;
import java.util.ArrayList;
import java.util.List;
public class ExtractCommentImages {
public static void main(String[] args) {
// 创建一个 Document 对象
Document document = new Document();
// 加载包含批注的 Word 文档
document.loadFromFile("/AI绘画的利弊及法律应对.docx");
// 创建一个列表来存储提取的图片数据
List images = new ArrayList<>();
// 遍历文档中的批注
for (int i = 0; i < document.getComments().getCount(); i++) {
Comment comment = document.getComments().get(i);
// 遍历批注正文中的所有段落
for (int j = 0; j < comment.getBody().getParagraphs().getCount(); j++) {
Paragraph paragraph = comment.getBody().getParagraphs().get(j);
// 遍历段落中的所有子对象
for (int k = 0; k < paragraph.getChildObjects().getCount(); k++) {
DocumentObject obj = paragraph.getChildObjects().get(k);
// 检查是否为图片
if (obj instanceof DocPicture) {
DocPicture picture = (DocPicture) obj;
// 获取图片数据并添加到列表
images.add(picture.getImageBytes());
}
}
}
}
// 指定输出路径
String outputDir = "/批注图片/";
new File(outputDir).mkdirs();
// 保存图片数据为文件
for (int i = 0; i < images.size(); i++) {
String fileName = String.format("批注图片-.png", i);
Path filePath = Paths.get(outputDir, fileName);
try (FileOutputStream fos = new FileOutputStream(filePath.toFile())) {
fos.write(images.get(i));
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。
Spire.Doc 12.12.12 现已发布。 该版本支持在段落中查找文本,并且还修复了一些在转换 Word 到 PDF、HTML 到 Word,以及加载 ODT 文档时出现的问题。详情请查看以下内容。
新功能:
paragraph.FindAllString();
paragraph.FindAllPattern();问题修复:
Spire.OCR for Java 1.9.22 现已正式发布。最新版本支持在 macOS 10.15 及更高版本中使用。此外,本次更新还修复了提取文本的坐标不正确的问题。更多详情请查阅以下内容。
新功能:
问题修复: