本文将介绍如何使用spire.xls for java来修改和删除excel中的超链接。添加超链接的方法可参考此篇教程。
修改超链接
import com.spire.xls.*;
import com.spire.xls.collections.hyperlinkscollection;
public class modifyhyperlink {
public static void main(string[] args) {
//加载示例excel文档
workbook workbook = new workbook();
workbook.loadfromfile("c:\\users\\test1\\desktop\\sample.xlsx");
//读取第一个工作表
worksheet sheet = workbook.getworksheets().get(0);
//获取超链接,修改文本信息及链接地址
hyperlinkscollection links = sheet.gethyperlinks();
links.get(0).settexttodisplay("紫月公司收入统计");
links.get(0).setaddress("https://www.11467.com/qiye/80122421.htm");
//保存文档
workbook.savetofile("output/modifyhyperlink.xlsx", excelversion.version2013);
}
}
删除超链接
import com.spire.xls.*;
import com.spire.xls.collections.hyperlinkscollection;
public class removehyperlink {
public static void main(string[] args) {
//加载示例excel文档
workbook workbook = new workbook();
workbook.loadfromfile("c:\\users\\test1\\desktop\\sample.xlsx");
//获取第一个工作表
worksheet sheet = workbook.getworksheets().get(0);
//获取工作表中的超链接
hyperlinkscollection links = sheet.gethyperlinks();
//移除超链接,并保留文本信息
sheet.gethyperlinks().removeat(0);
//保存文档
string output = "output/removehyperlink.xlsx";
workbook.savetofile(output, excelversion.version2013);
}
}