使用改变超链接位置的方式实现取消效果,效果如下。
取消后:
代码如下:
public void deleteExcel2007AllHyperLink(String filePath) throws Exception { XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(filePath)); Font hylinkFont = wb.createFont(); hylinkFont.setColor(Font.COLOR_NORMAL); hylinkFont.setUnderline(Font.U_NONE); int totalSheet = wb.getNumberOfSheets(); for (int i = 0; i < totalSheet; i++) { XSSFSheet sheet = wb.getSheetAt(i); int rowCount = sheet.getLastRowNum(); for (int r = 0; r <= rowCount; r++) { XSSFRow row = sheet.getRow(r); if (row != null) { int lastCellNum = row.getLastCellNum(); XSSFCell cell = null; for (int c = 0; c <= lastCellNum; c++) { cell = row.getCell(c); if (cell == null) { continue; } XSSFHyperlink hylink = cell.getHyperlink(); if (hylink != null) { //设置超链接位置为excel最后一个单元格位置,达到删除的功能 hylink.setFirstRow(1048573); hylink.setLastRow(1048573); hylink.setFirstColumn(16383); hylink.setLastColumn(16383); hylink.setLabel(null); hylink.setAddress(""); RichTextString richStr = new XSSFRichTextString(cell.getRichStringCellValue().getString()); richStr.applyFont(hylinkFont); cell.setCellValue(richStr); } } } } } saveWorkBook(wb); } public void printExcelHyperLinkInfo(String filePath) throws Exception { Workbook wb = new XSSFWorkbook(new FileInputStream(filePath)); int totalSheet = wb.getNumberOfSheets(); for (int i = 0; i < totalSheet; i++) { Sheet sheet = wb.getSheetAt(0); int rowCount = sheet.getLastRowNum(); for (int r = 0; r <= rowCount; r++) { Row row = sheet.getRow(r); if (row != null) { int lastCellNum = row.getLastCellNum(); Cell cell = null; for (int c = 0; c <= lastCellNum; c++) { cell = row.getCell(c); if(cell==null){ continue; } Hyperlink hylink = cell.getHyperlink(); if (hylink != null) { StringBuffer sb = new StringBuffer(); sb.append(" 工作簿名称:").append(sheet.getSheetName()); sb.append(" 第").append((r + 1)).append("行"); sb.append(" 第").append((c + 1)).append("列"); sb.append(" 位置:").append(convertNumToLetter(c + 1)).append((r + 1)); sb.append(" 单元格内容:").append(cell.getRichStringCellValue().getString()); sb.append(" 超链接地址:").append(hylink.getAddress()); sb.append(" 超链接内容:").append(hylink.getLabel()); switch (hylink.getType()) { case 1: sb.append(" 超链接类型:").append("网页URL"); break; case 2: sb.append(" 超链接类型:").append("文档"); break; case 3: sb.append(" 超链接类型:").append("邮箱"); break; case 4: sb.append(" 超链接类型:").append("文件"); break; default: sb.append(" 超链接类型:").append("未知"); break; } sb.append(" 开始行:").append(hylink.getFirstRow()).append(" 开始列").append(hylink.getFirstColumn()); sb.append(" 结束行:").append(hylink.getLastRow()).append(" 结束列").append(hylink.getLastColumn()); System.out.println(sb.toString()); } } } } } wb.close(); } public String convertNumToLetter(int colNum) { String colLetter = ""; do { colNum--; colLetter = ((char) (colNum % 26 + (int) 'A')) + colLetter; colNum = (int) ((colNum - colNum % 26) / 26); } while (colNum > 0); return colLetter; } public void saveWorkBook(Workbook wb) throws Exception { FileOutputStream fileOut = new FileOutputStream( "f:/saveFile/temp/sys_xlsx_" + System.currentTimeMillis() + ".xlsx"); wb.write(fileOut); fileOut.close(); }
全文完。
相关推荐
java使用poi在excel单元格添加超链接,设置字体颜色(csdn)————程序
poi做excel读取超链接
JAVA开发中需要将表格中数据导出成EXCEL文件,其中的某一项又要设置为HTML格式,并支持点击链接,使用POI的开源方式导出时可以参考到此文件的内容!
使用POI版本:3.10-FINAL*/ /* 建立新HSSFWorkbook对象*/ HSSFWorkbook wb = new HSSFWorkbook(); /* 建立新的sheet对象*/ HSSFSheet sheet = wb.createSheet("汇总页面"); HSSFRow row = sheet....
NULL 博文链接:https://topbox163.iteye.com/blog/1114166
最新版poi解析excel2007源码,简单实用,需要的可下.
POI处理 excel2007
poi excel poi excel poi excel poi excel poi excel poi excel poi excel poi excel
利用poi导出excel2007的时候出现内存溢出,当数据量过大,这种情况就更不容易控制了,这个文档就是解决这类问题,我就是用的这个,数据二十万都没溢出过,希望对大家有帮助。
poi操作excel2007
POI解析Excel2007
poi操作Excel,向Excel单元格中添加超链接
POI_EXCEL2007
poi 操作 excel 2007 demo 及poi类库
POI生成Excel POI读取Excel java操作Excel Servlet生成Excel web项目,包含含读取Excel与生成Excel方法
poi读取excel2007和2003兼容工具例子.利用简单工厂方法
利用POI读取excel写入到word 利用POI读取excel写入到word 利用POI读取excel写入到word,压缩包里包含了jar包
POI向excel中插入图片
poi读写excel,poi总结; poi读写excel,poi总结 poi读写excel,poi总结
可以运行的POI导出Excel文件实例,里面有两种方法,一个是Servlet,一个是main