Spire.XLS 15.3 现已发布。该版本支持使用表格数据创建 Slicer 切片器、修改 Slicer 切片器、获取 Slicer 切片器信息以及删除Slicer切片器。此外,它还修复了将 Excel 转换为 PDF 时切片器丢失的那个问题。新功能及问题修复详情如下。
新功能:
Workbook wb = new Workbook();
Worksheet worksheet = wb.Worksheets[0];
worksheet.Range["A1"].Value = "fruit";
worksheet.Range["A2"].Value = "grape";
worksheet.Range["A3"].Value = "blueberry";
worksheet.Range["A4"].Value = "kiwi";
worksheet.Range["A5"].Value = "cherry";
worksheet.Range["A6"].Value = "grape";
worksheet.Range["A7"].Value = "blueberry";
worksheet.Range["A8"].Value = "kiwi";
worksheet.Range["A9"].Value = "cherry";
worksheet.Range["B1"].Value = "year";
worksheet.Range["B2"].Value2 = 2020;
worksheet.Range["B3"].Value2 = 2020;
worksheet.Range["B4"].Value2 = 2020;
worksheet.Range["B5"].Value2 = 2020;
worksheet.Range["B6"].Value2 = 2021;
worksheet.Range["B7"].Value2 = 2021;
worksheet.Range["B8"].Value2 = 2021;
worksheet.Range["B9"].Value2 = 2021;
worksheet.Range["C1"].Value = "amount";
worksheet.Range["C2"].Value2 = 50;
worksheet.Range["C3"].Value2 = 60;
worksheet.Range["C4"].Value2 = 70;
worksheet.Range["C5"].Value2 = 80;
worksheet.Range["C6"].Value2 = 90;
worksheet.Range["C7"].Value2 = 100;
worksheet.Range["C8"].Value2 = 110;
worksheet.Range["C9"].Value2 = 120;
// Get slicer collection
XlsSlicerCollection slicers = worksheet.Slicers;
//Create a super table with the data from the specific cell range.
IListObject table = worksheet.ListObjects.Create("Super Table", worksheet.Range["A1:C9"]);
int count = 3;
int index = 0;
foreach (SlicerStyleType type in Enum.GetValues(typeof(SlicerStyleType)))
{
count += 5;
//Add a Slicer through table data : here invoke Add(IListObject, string, int) api.
String range = "E" + count;
index = slicers.Add(table, range.ToString(), 0);
//Style setting
XlsSlicer xlsSlicer = slicers[index];
xlsSlicer.Name = "slicers_" + count;
xlsSlicer.StyleType = type;
}
//Save to file
wb.SaveToFile("output.xlsx", ExcelVersion.Version2013);Workbook wb = new Workbook();
Worksheet worksheet = wb.Worksheets[0];
worksheet.Range["A1"].Value = "fruit";
worksheet.Range["A2"].Value = "grape";
worksheet.Range["A3"].Value = "blueberry";
worksheet.Range["A4"].Value = "kiwi";
worksheet.Range["A5"].Value = "cherry";
worksheet.Range["A6"].Value = "grape";
worksheet.Range["A7"].Value = "blueberry";
worksheet.Range["A8"].Value = "kiwi";
worksheet.Range["A9"].Value = "cherry";
worksheet.Range["B1"].Value = "year";
worksheet.Range["B2"].Value2 = 2020;
worksheet.Range["B3"].Value2 = 2020;
worksheet.Range["B4"].Value2 = 2020;
worksheet.Range["B5"].Value2 = 2020;
worksheet.Range["B6"].Value2 = 2021;
worksheet.Range["B7"].Value2 = 2021;
worksheet.Range["B8"].Value2 = 2021;
worksheet.Range["B9"].Value2 = 2021;
worksheet.Range["C1"].Value = "amount";
worksheet.Range["C2"].Value2 = 50;
worksheet.Range["C3"].Value2 = 60;
worksheet.Range["C4"].Value2 = 70;
worksheet.Range["C5"].Value2 = 80;
worksheet.Range["C6"].Value2 = 90;
worksheet.Range["C7"].Value2 = 100;
worksheet.Range["C8"].Value2 = 110;
worksheet.Range["C9"].Value2 = 120;
// Get pivot table collection
Spire.Xls.Collections.PivotTablesCollection pivotTables = worksheet.PivotTables;
//Add a PivotTable to the worksheet
CellRange dataRange = worksheet.Range["A1:C9"];
PivotCache cache = wb.PivotCaches.Add(dataRange);
//Cell to put the pivot table
Spire.Xls.PivotTable pt = worksheet.PivotTables.Add("TestPivotTable", worksheet.Range["A12"], cache);
//Drag the fields to the row area.
PivotField pf = pt.PivotFields["fruit"] as PivotField;
pf.Axis = AxisTypes.Row;
PivotField pf2 = pt.PivotFields["year"] as PivotField;
pf2.Axis = AxisTypes.Column;
//Drag the field to the data area.
pt.DataFields.Add(pt.PivotFields["amount"], "SUM of Count", SubtotalTypes.Sum);
//Set PivotTable style
pt.BuiltInStyle = PivotBuiltInStyles.PivotStyleMedium10;
pt.CalculateData();
//Get slicer collection
XlsSlicerCollection slicers = worksheet.Slicers;
//Add a Slicer through pivot table data: here invoke Add(IPivotTable, string, int) api.
int index = slicers.Add(pt, "E12", 0);
XlsSlicer xlsSlicer = slicers[index];
xlsSlicer.Name = "test_xlsSlicer";
xlsSlicer.Width = 100;
xlsSlicer.Height = 120;
xlsSlicer.StyleType = SlicerStyleType.SlicerStyleLight2;
xlsSlicer.PositionLocked = true;
//Get SlicerCache object of current slicer
XlsSlicerCache slicerCache = xlsSlicer.SlicerCache;
slicerCache.CrossFilterType = SlicerCacheCrossFilterType.ShowItemsWithNoData;
//Style setting
XlsSlicerCacheItemCollection slicerCacheItems = xlsSlicer.SlicerCache.SlicerCacheItems;
XlsSlicerCacheItem xlsSlicerCacheItem = slicerCacheItems[0];
xlsSlicerCacheItem.Selected = false;
XlsSlicerCollection slicers_2 = worksheet.Slicers;
IPivotField r1 = pt.PivotFields["year"];
int index_2 = slicers_2.Add(pt, "I12", r1);
XlsSlicer xlsSlicer_2 = slicers[index_2];
xlsSlicer_2.RowHeight = 40;
xlsSlicer_2.StyleType = SlicerStyleType.SlicerStyleLight3;
xlsSlicer_2.PositionLocked = false;
//Get SlicerCache object of current slicer
XlsSlicerCache slicerCache_2 = xlsSlicer_2.SlicerCache;
slicerCache_2.CrossFilterType = SlicerCacheCrossFilterType.ShowItemsWithDataAtTop;
//Style setting
XlsSlicerCacheItemCollection slicerCacheItems_2 = xlsSlicer_2.SlicerCache.SlicerCacheItems;
XlsSlicerCacheItem xlsSlicerCacheItem_2 = slicerCacheItems_2[1];
xlsSlicerCacheItem_2.Selected = false;
pt.CalculateData();
//Save to file
wb.SaveToFile("out.xlsx", ExcelVersion.Version2013);Workbook wb = new Workbook();
wb.LoadFromFile(inputFile);
//Get slicer collection of first worksheet
Worksheet worksheet = wb.Worksheets[0];
XlsSlicerCollection slicers = worksheet.Slicers;
//Remove the first slicer by index
slicers.RemoveAt(0);
Worksheet worksheet_2 = wb.Worksheets[1];
//Remove all slicers
worksheet_2.Slicers.Clear();
wb.SaveToFile(outputFile, ExcelVersion.Version2013);Workbook wb = new Workbook();
wb.LoadFromFile("in.xlsx");
//Get the first worksheet of workbook
Worksheet worksheet = wb.Worksheets[0];
//Get slicer collection
XlsSlicerCollection slicers = worksheet.Slicers;
//Style setting
XlsSlicer xlsSlicer = slicers[0];
xlsSlicer.StyleType = SlicerStyleType.SlicerStyleDark4;
xlsSlicer.Caption = "Slicer";
xlsSlicer.PositionLocked = true;
XlsSlicerCacheItemCollection slicerCacheItems = xlsSlicer.SlicerCache.SlicerCacheItems;
XlsSlicerCacheItem xlsSlicerCacheItem = slicerCacheItems[0];
xlsSlicerCacheItem.Selected = false;
string displayValue = xlsSlicerCacheItem.DisplayValue;
//Get SlicerCache object of current slicer
XlsSlicerCache slicerCache = xlsSlicer.SlicerCache;
slicerCache.CrossFilterType = SlicerCacheCrossFilterType.ShowItemsWithNoData;
//Save to file
wb.SaveToFile("out.xlsx", ExcelVersion.Version2013);Workbook wb = new Workbook();
wb.LoadFromFile("in.xlsx");
//Get slicer collection of first worksheet
Worksheet worksheet = wb.Worksheets[0];
XlsSlicerCollection slicers = worksheet.Slicers;
StringBuilder builder = new StringBuilder();
builder.AppendLine("slicers.Count:" + slicers.Count);
XlsSlicer xlsSlicer = slicers[1];
builder.AppendLine("xlsSlicer.Name:" + xlsSlicer.Name);
builder.AppendLine("xlsSlicer.Caption:" + xlsSlicer.Caption);
builder.AppendLine("xlsSlicer.NumberOfColumns:" + xlsSlicer.NumberOfColumns);
builder.AppendLine("xlsSlicer.ColumnWidth:" + xlsSlicer.ColumnWidth);
builder.AppendLine("xlsSlicer.RowHeight:" + xlsSlicer.RowHeight);
builder.AppendLine("xlsSlicer.ShowCaption:" + xlsSlicer.ShowCaption);
builder.AppendLine("xlsSlicer.PositionLocked:" + xlsSlicer.PositionLocked);
builder.AppendLine("xlsSlicer.Width:" + xlsSlicer.Width);
builder.AppendLine("xlsSlicer.Height:" + xlsSlicer.Height);
//Get SlicerCache object of current slicer
XlsSlicerCache slicerCache = xlsSlicer.SlicerCache;
builder.AppendLine("slicerCache.SourceName:" + slicerCache.SourceName);
builder.AppendLine("slicerCache.IsTabular:" + slicerCache.IsTabular);
builder.AppendLine("slicerCache.Name:" + slicerCache.Name);
XlsSlicerCacheItemCollection slicerCacheItems = slicerCache.SlicerCacheItems;
XlsSlicerCacheItem xlsSlicerCacheItem = slicerCacheItems[1];
builder.AppendLine("xlsSlicerCacheItem.Selected:" + xlsSlicerCacheItem.Selected);
File.WriteAllText("out.txt", builder.ToString());
wb.Dispose();Workbook wb = new Workbook();
wb.LoadFromFile(inputFile);
Worksheet worksheet = wb.Worksheets[0];
XlsSlicerCollection slicers = worksheet.Slicers;
XlsSlicer xlsSlicer = slicers[0];
xlsSlicer.Caption = "Name1";
wb.SaveToFile(outputFile, ExcelVersion.Version2013);问题修复:
合并 Excel 文件是数据处理中的常见任务。随着项目的不断发展,团队成员常常会生成多个电子表格,以记录不同的数据和信息。这时,如何将这些分散的文件整合成一个统一的文档,便于分析和共享,成为了一个亟需解决的问题。无论是处理财务报表、销售数据,还是项目进度表,掌握高效合并 Excel 文件的技巧,不仅可以提高工作效率,也能让数据分析变得更加直观和便捷。这篇文章将介绍如何在 React 项目中使用 JavaScript 和 Spire.XLS for JavaScript 库实现合并 Excel 文件。
要在 React 应用程序中实现合并Excel文件,首先需要下载 Spire.XLS for JavaScript,或者通过 npm 进行安装:
npm i spire.office
下载的产品包整合了Spire.Doc for JavaScript,Spire.XLS for JavaScript,Spire.PDF for JavaScript,Spire.Presentation for JavaScript,使用Spire.XLS for JavaScript的功能需将相应( spire.xls.js,Spire.Xls.Wasm.zip,spire.common.js,Spire.Common.Wasm.zip,_framework 文件复制到项目的 public 文件夹中。同时为了确保文本渲染,相关使用字体文件可自定义路径添加。以下示例中,字体添加路径为:public\static\font。
详细的安装和配置步骤,请参考此教程:如何在 React 项目中集成 Spire.XLS for JavaScript
通过合并多个 Excel 工作簿,你可以将各个文件整合为一个文档,这样不仅提高了数据的可读性,还使得信息的分析和共享变得更加高效,便于团队协作和决策。
使用 Spire.XLS for JavaScript,开发人员可以通过 XlsWorksheetsCollection.AddCopy() 方法,将源工作簿中的工作表复制到新的工作簿,从而实现多个工作簿的合并。主要步骤如下:
import React, { useState, useEffect } from 'react';
function App() {
const [wasmModule, setWasmModule] = useState(null);
// 加载 Spire.XLS
useEffect(() => {
(async () => {
try {
const publicUrl = process.env.PUBLIC_URL || '';
const spireModule = await import(/* webpackIgnore: true */ `${publicUrl}/spire.xls.js`);
const rawModule = spireModule.default || spireModule;
window.wasmModule = typeof rawModule === 'function'
? await rawModule({ locateFile: p => p.endsWith('.wasm') ? `${publicUrl}/${p}` : p })
: rawModule;
setWasmModule(window.wasmModule);
} catch (error) {
console.error('Failed to load spire.xls.js WASM module:', error);
}
})();
}, []);
// 合并 Excel 工作簿的函数
const MergeExcelWorkbooks = async () => {
const wasmModule = window.wasmModule.spirexls;
if (wasmModule) {
// 将字体加载到虚拟文件系统(VFS)中
await window.spire.FetchFileToVFS('Arial.ttf', '/Library/Fonts/', `${process.env.PUBLIC_URL}/static/font/`);
// 将 Excel 文件加载到虚拟文件系统 (VFS)
const files = [
"文档1.xlsx",
"文档2.xlsx",
"文档3.xlsx",
];
for (const file of files) {
window.spire.FetchFileToVFS(file, '', `${process.env.PUBLIC_URL}/static/data/`);
}
// 创建一个新的工作簿
const newbook = new wasmModule.Workbook();
newbook.Version = wasmModule.ExcelVersion.Version2013;
// 清除默认工作表
newbook.Worksheets.Clear();
// 创建一个临时工作簿
let tempbook = new wasmModule.Workbook();
for (const file of files) {
// 加载当前文件
tempbook.LoadFromFile(file.split("/").pop());
for (let i = 0; i < tempbook.Worksheets.Count; i++) {
let sheet = tempbook.Worksheets.get(i);
// 将当前文件中的每个工作表复制到新工作簿
wasmModule.XlsWorksheetsCollection.Convert(
newbook.Worksheets
).AddCopy({
sheet: sheet,
flags: wasmModule.WorksheetCopyType.CopyAll,
});
}
}
let outputFileName = "合并工作簿.xlsx";
newbook.SaveToFile({ fileName: outputFileName, version: wasmModule.ExcelVersion.Version2013 });
// 读取保存的文件并转换为Blob对象
const modifiedFileArray = window.dotnetRuntime.Module.FS.readFile(outputFileName);
const modifiedFile = new Blob([modifiedFileArray], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
// 为Blob创建一个URL并启动下载
const url = URL.createObjectURL(modifiedFile);
const a = document.createElement('a');
a.href = url;
a.download = outputFileName;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
// 清理工作簿使用的资源
newbook.Dispose();
}
};
return (
<div style={{ textAlign: 'center', height: '300px' }}>
<h1>使用 JavaScript 在 React 中合并多个 Excel 工作簿为一个</h1>
<button onClick={MergeExcelWorkbooks} disabled={!wasmModule}>
合并
</button>
</div>
);
}
export default App;
React 应用程序编译成功后,将在默认网页浏览器中打开,通常是 http://localhost:3000。

点击“合并”,就能下载合并后的Excel工作簿。下图展示了本示例中的输入工作簿和合并后的工作簿:

将多个工作表合并为一个工作表不仅能提升信息的清晰度,还能提供更全面的相关数据视图。使用 Spire.XLS for JavaScript,开发人员可以利用 CellRange.Copy() 方法,将数据区域从不同的工作表复制到同一个工作表中,从而实现数据合并。主要步骤如下:
import React, { useState, useEffect } from 'react';
function App() {
const [wasmModule, setWasmModule] = useState(null);
// 加载 Spire.XLS
useEffect(() => {
(async () => {
try {
const publicUrl = process.env.PUBLIC_URL || '';
const spireModule = await import(/* webpackIgnore: true */ `${publicUrl}/spire.xls.js`);
const rawModule = spireModule.default || spireModule;
window.wasmModule = typeof rawModule === 'function'
? await rawModule({ locateFile: p => p.endsWith('.wasm') ? `${publicUrl}/${p}` : p })
: rawModule;
setWasmModule(window.wasmModule);
} catch (error) {
console.error('Failed to load spire.xls.js WASM module:', error);
}
})();
}, []);
// 合并 多个Excel 工作表的函数
const MergeWorksheets = async () => {
const wasmModule = window.wasmModule.spirexls;
if (wasmModule) {
// 将字体加载到虚拟文件系统(VFS)中
await window.spire.FetchFileToVFS('Arial.ttf', '/Library/Fonts/', `${process.env.PUBLIC_URL}/static/font/`);
// 将 Excel 文件加载到虚拟文件系统 (VFS)
let inputFileName = '示例.xlsx';
await window.spire.FetchFileToVFS(inputFileName, '', `${process.env.PUBLIC_URL}/static/data/`);
// 创建一个新的工作簿
const workbook = new wasmModule.Workbook();
// 从虚拟文件系统加载 Excel 文件
workbook.LoadFromFile(inputFileName);
// 获取第一个工作表
let sheet1 = workbook.Worksheets.get(0);
// 获取第二个工作表
let sheet2 = workbook.Worksheets.get(1);
// 获取第二个工作表中所使用的数据区域
let fromRange = sheet2.AllocatedRange;
// 指定第一个工作表中的目标区域
let toRange = sheet1.Range.get({ row: sheet1.LastRow + 1, column: 1 });
// 将第二个工作表的数据区域复制到第一个工作表的目标区域
fromRange.Copy({ destRange: toRange });
// 删除第二个工作表
sheet2.Remove();
// 定义输出文件名
const outputFileName = "合并工作表.xlsx";
workbook.SaveToFile({ fileName: outputFileName, version: wasmModule.ExcelVersion.Version2010 });
// 读取保存的文件并转换为Blob对象
const modifiedFileArray = window.dotnetRuntime.Module.FS.readFile(outputFileName);
const modifiedFile = new Blob([modifiedFileArray], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
// 为Blob创建一个URL并启动下载
const url = URL.createObjectURL(modifiedFile);
const a = document.createElement('a');
a.href = url;
a.download = outputFileName;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
// 清理工作簿使用的资源
workbook.Dispose();
}
};
return (
<div style={{ textAlign: 'center', height: '300px' }}>
<h1>使用 JavaScript 在 React 中合并多个 Excel 工作表为一个</h1>
<button onClick={MergeWorksheets} disabled={!wasmModule}>
合并
</button>
</div>
);
}
export default App;

如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。
Spire.Office for Java 10.2.0 已发布。在该版本中,Spire.Doc for Java 优化了对比功能的效果;Spire.XLS for Java 增强了 Excel 到图片和 PDF 的转换;Spire.Presentation for Java 增强了 PPT 到图片的转换功能;Spire.PDF for Java 支持获取 PDF 文档中的视频和音频。此外,大量已知问题也在该版本中成功修复。详情请阅读以下内容。
获取 Spire.Office for Java 10.2.0,请点击:https://www.e-iceblue.cn/Downloads/Spire-Office-JAVA.html
问题修复:
问题修复:
问题修复:
新功能:
PdfDocument pdf = new PdfDocument();
pdf.loadFromFile(inputFile);
FileOutputStream outputFileStream =null;
for (int i = 0; i < pdf.getPages().getCount(); i++)
{
PdfPageBase page = pdf.getPages().get(i);
PdfAnnotationCollection ancoll = page.getAnnotations();
for (int j = 0; j < ancoll.getCount(); j++)
{
PdfRichMediaAnnotationWidget MediaWidget = (PdfRichMediaAnnotationWidget)ancoll.get(j);
byte[] data = MediaWidget.getRichMediaData();
String embedFileName = MediaWidget.getRichMediaName();
outputFileStream = new FileOutputStream(String.format(outputFile + embedFileName));
outputFileStream.write(data);
}
}问题修复:
Spire.PDF for Java 11.2.3 已发布。本次更新新增支持获取 PDF 文档中的视频和音频,同时增强了 PDF 到 OFD 的转换功能。此外,该版本还成功修复了一些已知问题,如绘制 grid 表格文本时,内容重叠的问题。详情请阅读以下内容。
新功能:
PdfDocument pdf = new PdfDocument();
pdf.loadFromFile(inputFile);
FileOutputStream outputFileStream =null;
for (int i = 0; i < pdf.getPages().getCount(); i++)
{
PdfPageBase page = pdf.getPages().get(i);
PdfAnnotationCollection ancoll = page.getAnnotations();
for (int j = 0; j < ancoll.getCount(); j++)
{
PdfRichMediaAnnotationWidget MediaWidget = (PdfRichMediaAnnotationWidget)ancoll.get(j);
byte[] data = MediaWidget.getRichMediaData();
String embedFileName = MediaWidget.getRichMediaName();
outputFileStream = new FileOutputStream(String.format(outputFile + embedFileName));
outputFileStream.write(data);
}
}问题修复:
Spire.Doc for Java 13.2.1 现已正式发布。该版本优化了对比功能的效果,还修复了一些在 转换 Word 到 PDF、统计字数和加载 Word 文档时出现的问题。 更多详情如下。
问题修复:
在 PDF 文档中,超链接用于跳转到特定页面、外部网站或电子邮件地址,但随着内容的变更,超链接可能需要更新或删除。通过修改 PDF 中的超链接,用户可以确保链接指向最新的页面或移除已失效的链接,从而提升文档的可读性和专业性。本文介绍如何使用 Spire.PDF for Java 在 Java 中更新或删除 PDF 中的超链接。
首先,您需要在 Java 程序中添加 Spire.Pdf.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.pdf</artifactId>
<version>12.9.0</version>
</dependency>
</dependencies>
Spire.PDF for Java 提供了 PdfTextWebLinkAnnotationWidget.setUrl() 方法,可用于修改 PDF 中的超链接。以下是具体步骤:
import com.spire.pdf.PdfDocument;
import com.spire.pdf.PdfPageBase;
import com.spire.pdf.annotations.PdfAnnotationCollection;
import com.spire.pdf.annotations.PdfTextWebLinkAnnotationWidget;
public class UpdateHyperlinks {
public static void main(String[] args) {
// 创建 PdfDocument 对象
PdfDocument document = new PdfDocument();
// 加载 PDF 文件
document.loadFromFile("示例.pdf");
// 获取第一页
PdfPageBase page = document.getPages().get(0);
// 获取页面的注释集合
PdfAnnotationCollection widgetCollection = page.getAnnotationsWidget();
// 获取集合内第一个超链接注释
PdfTextWebLinkAnnotationWidget uriWidget = (PdfTextWebLinkAnnotationWidget) widgetCollection.get(0);
// 修改超链接 URL地址
uriWidget.setUrl("https://www.ccchina.org.cn/");
// 保存修改后的 PDF 文件
document.saveToFile("更改超链接.pdf");
// 关闭 PDF 文档以释放资源
document.close();
document.dispose();
}
}

Spire.PDF for Java 还提供了 PdfAnnotationCollection.remove() 方法,可用于删除 PDF 中的超链接。需要注意的是,删除超链接后,其外观仍会保留,但链接功能将被移除。以下是具体步骤:
import com.spire.pdf.PdfDocument;
import com.spire.pdf.PdfPageBase;
import com.spire.pdf.annotations.PdfAnnotation;
import com.spire.pdf.annotations.PdfAnnotationCollection;
import com.spire.pdf.annotations.PdfTextWebLinkAnnotationWidget;
public class RemoveHyperlinks {
public static void main(String[] args) {
// 创建 PdfDocument 对象
PdfDocument document = new PdfDocument();
// 加载 PDF 文件
document.loadFromFile("示例.pdf");
// 获取第一页
PdfPageBase page = document.getPages().get(0);
// 获取页面的注释集合
PdfAnnotationCollection widgetCollection = page.getAnnotationsWidget();
// 检查页面是否有注释
if (widgetCollection.getCount() > 0) {
// 反向遍历注释集合
for (int i = widgetCollection.getCount() - 1; i >= 0; i--) {
// 获取当前注释
PdfAnnotation annotation = widgetCollection.get(i);
// 检查注释是否为文本网页链接
if (annotation instanceof PdfTextWebLinkAnnotationWidget) {
// 将注释强制转换为文本网页链接注释
PdfTextWebLinkAnnotationWidget link = (PdfTextWebLinkAnnotationWidget) annotation;
// 从集合中删除文本网页链接注释
widgetCollection.remove(link);
}
}
}
// 保存修改后的文档到输出文件
document.saveToFile("删除超链接.pdf");
// 关闭 PDF 文档以释放资源
document.close();
document.dispose();
}
}

如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。
Spire.XLS 15.2.3 现已正式发布。最新版本支持在使用 ExportDataTable() 时保留原有格式。此外,一些已知问题也在本次更新中被成功修复,例如更新透视表后,日语字符变成了英文字符的问题。新功能及问题修复详情如下。
新功能:
ExportTableOptions op = new ExportTableOptions();
op.ExportColumnNames = true;
op.KeepDataType = true;
var r = sheet.Range["A1:M7"];Workbook workbook = new Workbook();
workbook.Worksheets[0].Range["C2"].Formula = "=MUNIT(5)";
workbook.Worksheets[0].Range["C8"].Formula = "=MUNIT(0)";
workbook.Worksheets[0].Range["A1"].Formula = "=FLOOR.PRECISE(3.2)";
workbook.Worksheets[0].Range["D1"].Formula = "CSC(-2)";
workbook.Worksheets[0].Range["A3"].Formula = "=IMCSCH(\"4 + 3i\")";
workbook.CalculateAllValue();问题修复:
Spire.Presentation for Java 10.2.2 已发布。本次更新增强了 PPT 到图片的转换功能。此外,一些已知问题也在该版本中成功修复,如保存 PPT 文档时抛 "Value cannot be null" 的问题。详情请阅读以下内容。
问题修复:
https://www.e-iceblue.cn/Downloads/Spire-Presentation-JAVA.html
Spire.Doc 13.2.3 现已发布。该版本优化了 Word 转 PDF 时的时间和资源占用,还新增了接口用于读写图表标题、数据标签、坐标轴、图例、数据表以及其他图表属性。详情请查看以下内容。
新功能:
Spire.Doc.Formatting.RowFormat.TablePositioning->Spire.Doc.Formatting.TablePositioning
Spire.Doc.Printing.PagesPreSheet->Spire.Doc.Printing.PagesPerSheetSpire.XLS for Java 15.2.1 现已正式发布。最新版本增强了 Excel 到图片和 PDF 的转换。同时,本次更新还修复了加载 XLSX 文档时,程序抛 "NullPointerException" 的问题。详情请查阅以下内容。
问题修复: