mirror of https://github.com/apache/poi.git
bug 59783: replace deprecated Hyperlink.LINK_* and Hyperlink.getType usage
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1753040 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2cddaa1319
commit
ed944416da
|
@ -1109,15 +1109,15 @@ public class HSSFCell implements Cell {
|
||||||
link.setFirstColumn(_record.getColumn());
|
link.setFirstColumn(_record.getColumn());
|
||||||
link.setLastColumn(_record.getColumn());
|
link.setLastColumn(_record.getColumn());
|
||||||
|
|
||||||
switch(link.getType()){
|
switch(link.getTypeEnum()){
|
||||||
case HSSFHyperlink.LINK_EMAIL:
|
case EMAIL:
|
||||||
case HSSFHyperlink.LINK_URL:
|
case URL:
|
||||||
link.setLabel("url");
|
link.setLabel("url");
|
||||||
break;
|
break;
|
||||||
case HSSFHyperlink.LINK_FILE:
|
case FILE:
|
||||||
link.setLabel("file");
|
link.setLabel("file");
|
||||||
break;
|
break;
|
||||||
case HSSFHyperlink.LINK_DOCUMENT:
|
case DOCUMENT:
|
||||||
link.setLabel("place");
|
link.setLabel("place");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -71,7 +71,7 @@ public final class TestXSSFHyperlink extends BaseTestHyperlink {
|
||||||
"http://apache.org/default.php?s=isTramsformed&submit=Search&la=*&li=*"};
|
"http://apache.org/default.php?s=isTramsformed&submit=Search&la=*&li=*"};
|
||||||
for(int i = 0; i < urls.length; i++){
|
for(int i = 0; i < urls.length; i++){
|
||||||
String s = urls[i];
|
String s = urls[i];
|
||||||
XSSFHyperlink link = createHelper.createHyperlink(Hyperlink.LINK_URL);
|
XSSFHyperlink link = createHelper.createHyperlink(HyperlinkType.URL);
|
||||||
link.setAddress(s);
|
link.setAddress(s);
|
||||||
|
|
||||||
XSSFCell cell = row.createCell(i);
|
XSSFCell cell = row.createCell(i);
|
||||||
|
@ -111,7 +111,7 @@ public final class TestXSSFHyperlink extends BaseTestHyperlink {
|
||||||
"\\poi"};
|
"\\poi"};
|
||||||
for(String s : invalidURLs){
|
for(String s : invalidURLs){
|
||||||
try {
|
try {
|
||||||
createHelper.createHyperlink(Hyperlink.LINK_URL).setAddress(s);
|
createHelper.createHyperlink(HyperlinkType.URL).setAddress(s);
|
||||||
fail("expected IllegalArgumentException: " + s);
|
fail("expected IllegalArgumentException: " + s);
|
||||||
} catch (IllegalArgumentException e){
|
} catch (IllegalArgumentException e){
|
||||||
|
|
||||||
|
@ -153,7 +153,7 @@ public final class TestXSSFHyperlink extends BaseTestHyperlink {
|
||||||
Row r17 = sheet.createRow(17);
|
Row r17 = sheet.createRow(17);
|
||||||
Cell r17c = r17.createCell(2);
|
Cell r17c = r17.createCell(2);
|
||||||
|
|
||||||
Hyperlink hyperlink = createHelper.createHyperlink(Hyperlink.LINK_URL);
|
Hyperlink hyperlink = createHelper.createHyperlink(HyperlinkType.URL);
|
||||||
hyperlink.setAddress("http://poi.apache.org/spreadsheet/");
|
hyperlink.setAddress("http://poi.apache.org/spreadsheet/");
|
||||||
hyperlink.setLabel("POI SS Link");
|
hyperlink.setLabel("POI SS Link");
|
||||||
r17c.setHyperlink(hyperlink);
|
r17c.setHyperlink(hyperlink);
|
||||||
|
@ -161,8 +161,8 @@ public final class TestXSSFHyperlink extends BaseTestHyperlink {
|
||||||
assertEquals(5, sheet.getNumHyperlinks());
|
assertEquals(5, sheet.getNumHyperlinks());
|
||||||
doTestHyperlinkContents(sheet);
|
doTestHyperlinkContents(sheet);
|
||||||
|
|
||||||
assertEquals(Hyperlink.LINK_URL,
|
assertEquals(HyperlinkType.URL,
|
||||||
sheet.getRow(17).getCell(2).getHyperlink().getType());
|
sheet.getRow(17).getCell(2).getHyperlink().getTypeEnum());
|
||||||
assertEquals("POI SS Link",
|
assertEquals("POI SS Link",
|
||||||
sheet.getRow(17).getCell(2).getHyperlink().getLabel());
|
sheet.getRow(17).getCell(2).getHyperlink().getLabel());
|
||||||
assertEquals("http://poi.apache.org/spreadsheet/",
|
assertEquals("http://poi.apache.org/spreadsheet/",
|
||||||
|
@ -182,8 +182,8 @@ public final class TestXSSFHyperlink extends BaseTestHyperlink {
|
||||||
assertEquals(5, sheet.getNumHyperlinks());
|
assertEquals(5, sheet.getNumHyperlinks());
|
||||||
doTestHyperlinkContents(sheet);
|
doTestHyperlinkContents(sheet);
|
||||||
|
|
||||||
assertEquals(Hyperlink.LINK_URL,
|
assertEquals(HyperlinkType.URL,
|
||||||
sheet.getRow(17).getCell(2).getHyperlink().getType());
|
sheet.getRow(17).getCell(2).getHyperlink().getTypeEnum());
|
||||||
assertEquals("POI SS Link",
|
assertEquals("POI SS Link",
|
||||||
sheet.getRow(17).getCell(2).getHyperlink().getLabel());
|
sheet.getRow(17).getCell(2).getHyperlink().getLabel());
|
||||||
assertEquals("http://poi.apache.org/spreadsheet/",
|
assertEquals("http://poi.apache.org/spreadsheet/",
|
||||||
|
@ -200,32 +200,32 @@ public final class TestXSSFHyperlink extends BaseTestHyperlink {
|
||||||
assertNotNull(sheet.getRow(16).getCell(2).getHyperlink());
|
assertNotNull(sheet.getRow(16).getCell(2).getHyperlink());
|
||||||
|
|
||||||
// First is a link to poi
|
// First is a link to poi
|
||||||
assertEquals(Hyperlink.LINK_URL,
|
assertEquals(HyperlinkType.URL,
|
||||||
sheet.getRow(3).getCell(2).getHyperlink().getType());
|
sheet.getRow(3).getCell(2).getHyperlink().getTypeEnum());
|
||||||
assertEquals(null,
|
assertEquals(null,
|
||||||
sheet.getRow(3).getCell(2).getHyperlink().getLabel());
|
sheet.getRow(3).getCell(2).getHyperlink().getLabel());
|
||||||
assertEquals("http://poi.apache.org/",
|
assertEquals("http://poi.apache.org/",
|
||||||
sheet.getRow(3).getCell(2).getHyperlink().getAddress());
|
sheet.getRow(3).getCell(2).getHyperlink().getAddress());
|
||||||
|
|
||||||
// Next is an internal doc link
|
// Next is an internal doc link
|
||||||
assertEquals(Hyperlink.LINK_DOCUMENT,
|
assertEquals(HyperlinkType.DOCUMENT,
|
||||||
sheet.getRow(14).getCell(2).getHyperlink().getType());
|
sheet.getRow(14).getCell(2).getHyperlink().getTypeEnum());
|
||||||
assertEquals("Internal hyperlink to A2",
|
assertEquals("Internal hyperlink to A2",
|
||||||
sheet.getRow(14).getCell(2).getHyperlink().getLabel());
|
sheet.getRow(14).getCell(2).getHyperlink().getLabel());
|
||||||
assertEquals("Sheet1!A2",
|
assertEquals("Sheet1!A2",
|
||||||
sheet.getRow(14).getCell(2).getHyperlink().getAddress());
|
sheet.getRow(14).getCell(2).getHyperlink().getAddress());
|
||||||
|
|
||||||
// Next is a file
|
// Next is a file
|
||||||
assertEquals(Hyperlink.LINK_FILE,
|
assertEquals(HyperlinkType.FILE,
|
||||||
sheet.getRow(15).getCell(2).getHyperlink().getType());
|
sheet.getRow(15).getCell(2).getHyperlink().getTypeEnum());
|
||||||
assertEquals(null,
|
assertEquals(null,
|
||||||
sheet.getRow(15).getCell(2).getHyperlink().getLabel());
|
sheet.getRow(15).getCell(2).getHyperlink().getLabel());
|
||||||
assertEquals("WithVariousData.xlsx",
|
assertEquals("WithVariousData.xlsx",
|
||||||
sheet.getRow(15).getCell(2).getHyperlink().getAddress());
|
sheet.getRow(15).getCell(2).getHyperlink().getAddress());
|
||||||
|
|
||||||
// Last is a mailto
|
// Last is a mailto
|
||||||
assertEquals(Hyperlink.LINK_EMAIL,
|
assertEquals(HyperlinkType.EMAIL,
|
||||||
sheet.getRow(16).getCell(2).getHyperlink().getType());
|
sheet.getRow(16).getCell(2).getHyperlink().getTypeEnum());
|
||||||
assertEquals(null,
|
assertEquals(null,
|
||||||
sheet.getRow(16).getCell(2).getHyperlink().getLabel());
|
sheet.getRow(16).getCell(2).getHyperlink().getLabel());
|
||||||
assertEquals("mailto:dev@poi.apache.org?subject=XSSF%20Hyperlinks",
|
assertEquals("mailto:dev@poi.apache.org?subject=XSSF%20Hyperlinks",
|
||||||
|
@ -242,13 +242,13 @@ public final class TestXSSFHyperlink extends BaseTestHyperlink {
|
||||||
|
|
||||||
assertEquals(sh1.getNumberOfComments(), sh2.getNumberOfComments());
|
assertEquals(sh1.getNumberOfComments(), sh2.getNumberOfComments());
|
||||||
XSSFHyperlink l1 = sh1.getHyperlink(0, 1);
|
XSSFHyperlink l1 = sh1.getHyperlink(0, 1);
|
||||||
assertEquals(XSSFHyperlink.LINK_DOCUMENT, l1.getType());
|
assertEquals(HyperlinkType.DOCUMENT, l1.getTypeEnum());
|
||||||
assertEquals("B1", l1.getCellRef());
|
assertEquals("B1", l1.getCellRef());
|
||||||
assertEquals("Sort on Titel", l1.getTooltip());
|
assertEquals("Sort on Titel", l1.getTooltip());
|
||||||
|
|
||||||
XSSFHyperlink l2 = sh2.getHyperlink(0, 1);
|
XSSFHyperlink l2 = sh2.getHyperlink(0, 1);
|
||||||
assertEquals(l1.getTooltip(), l2.getTooltip());
|
assertEquals(l1.getTooltip(), l2.getTooltip());
|
||||||
assertEquals(XSSFHyperlink.LINK_DOCUMENT, l2.getType());
|
assertEquals(HyperlinkType.DOCUMENT, l2.getTypeEnum());
|
||||||
assertEquals("B1", l2.getCellRef());
|
assertEquals("B1", l2.getCellRef());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -313,22 +313,22 @@ public final class TestXSSFHyperlink extends BaseTestHyperlink {
|
||||||
|
|
||||||
XSSFHyperlink link = sh.getHyperlink(A2);
|
XSSFHyperlink link = sh.getHyperlink(A2);
|
||||||
assertEquals("address", "A2", link.getCellRef());
|
assertEquals("address", "A2", link.getCellRef());
|
||||||
assertEquals("link type", Hyperlink.LINK_URL, link.getType());
|
assertEquals("link type", HyperlinkType.URL, link.getTypeEnum());
|
||||||
assertEquals("link target", "http://twitter.com/#!/apacheorg", link.getAddress());
|
assertEquals("link target", "http://twitter.com/#!/apacheorg", link.getAddress());
|
||||||
|
|
||||||
link = sh.getHyperlink(A3);
|
link = sh.getHyperlink(A3);
|
||||||
assertEquals("address", "A3", link.getCellRef());
|
assertEquals("address", "A3", link.getCellRef());
|
||||||
assertEquals("link type", Hyperlink.LINK_URL, link.getType());
|
assertEquals("link type", HyperlinkType.URL, link.getTypeEnum());
|
||||||
assertEquals("link target", "http://www.bailii.org/databases.html#ie", link.getAddress());
|
assertEquals("link target", "http://www.bailii.org/databases.html#ie", link.getAddress());
|
||||||
|
|
||||||
link = sh.getHyperlink(A4);
|
link = sh.getHyperlink(A4);
|
||||||
assertEquals("address", "A4", link.getCellRef());
|
assertEquals("address", "A4", link.getCellRef());
|
||||||
assertEquals("link type", Hyperlink.LINK_URL, link.getType());
|
assertEquals("link type", HyperlinkType.URL, link.getTypeEnum());
|
||||||
assertEquals("link target", "https://en.wikipedia.org/wiki/Apache_POI#See_also", link.getAddress());
|
assertEquals("link target", "https://en.wikipedia.org/wiki/Apache_POI#See_also", link.getAddress());
|
||||||
|
|
||||||
link = sh.getHyperlink(A7);
|
link = sh.getHyperlink(A7);
|
||||||
assertEquals("address", "A7", link.getCellRef());
|
assertEquals("address", "A7", link.getCellRef());
|
||||||
assertEquals("link type", Hyperlink.LINK_DOCUMENT, link.getType());
|
assertEquals("link type", HyperlinkType.DOCUMENT, link.getTypeEnum());
|
||||||
assertEquals("link target", "Sheet1", link.getAddress());
|
assertEquals("link target", "Sheet1", link.getAddress());
|
||||||
|
|
||||||
wb.close();
|
wb.close();
|
||||||
|
|
|
@ -20,10 +20,10 @@ package org.apache.poi.hssf.usermodel;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.apache.poi.common.usermodel.HyperlinkType;
|
||||||
import org.apache.poi.hssf.HSSFITestDataProvider;
|
import org.apache.poi.hssf.HSSFITestDataProvider;
|
||||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||||
import org.apache.poi.ss.usermodel.BaseTestHyperlink;
|
import org.apache.poi.ss.usermodel.BaseTestHyperlink;
|
||||||
|
@ -34,6 +34,7 @@ import org.apache.poi.xssf.usermodel.XSSFCreationHelper;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFHyperlink;
|
import org.apache.poi.xssf.usermodel.XSSFHyperlink;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
*/
|
*/
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests HSSFHyperlink.
|
* Tests HSSFHyperlink.
|
||||||
|
@ -64,7 +65,7 @@ public final class TestHSSFHyperlink extends BaseTestHyperlink {
|
||||||
assertEquals("POI", link.getLabel());
|
assertEquals("POI", link.getLabel());
|
||||||
assertEquals("POI", cell.getRichStringCellValue().getString());
|
assertEquals("POI", cell.getRichStringCellValue().getString());
|
||||||
assertEquals("http://poi.apache.org/", link.getAddress());
|
assertEquals("http://poi.apache.org/", link.getAddress());
|
||||||
assertEquals(HSSFHyperlink.LINK_URL, link.getType());
|
assertEquals(HyperlinkType.URL, link.getTypeEnum());
|
||||||
|
|
||||||
cell = sheet.getRow(8).getCell(0);
|
cell = sheet.getRow(8).getCell(0);
|
||||||
link = cell.getHyperlink();
|
link = cell.getHyperlink();
|
||||||
|
@ -72,7 +73,7 @@ public final class TestHSSFHyperlink extends BaseTestHyperlink {
|
||||||
assertEquals("HSSF", link.getLabel());
|
assertEquals("HSSF", link.getLabel());
|
||||||
assertEquals("HSSF", cell.getRichStringCellValue().getString());
|
assertEquals("HSSF", cell.getRichStringCellValue().getString());
|
||||||
assertEquals("http://poi.apache.org/hssf/", link.getAddress());
|
assertEquals("http://poi.apache.org/hssf/", link.getAddress());
|
||||||
assertEquals(HSSFHyperlink.LINK_URL, link.getType());
|
assertEquals(HyperlinkType.URL, link.getTypeEnum());
|
||||||
|
|
||||||
sheet = wb.getSheet("Emails");
|
sheet = wb.getSheet("Emails");
|
||||||
cell = sheet.getRow(4).getCell(0);
|
cell = sheet.getRow(4).getCell(0);
|
||||||
|
@ -81,7 +82,7 @@ public final class TestHSSFHyperlink extends BaseTestHyperlink {
|
||||||
assertEquals("dev", link.getLabel());
|
assertEquals("dev", link.getLabel());
|
||||||
assertEquals("dev", cell.getRichStringCellValue().getString());
|
assertEquals("dev", cell.getRichStringCellValue().getString());
|
||||||
assertEquals("mailto:dev@poi.apache.org", link.getAddress());
|
assertEquals("mailto:dev@poi.apache.org", link.getAddress());
|
||||||
assertEquals(HSSFHyperlink.LINK_EMAIL, link.getType());
|
assertEquals(HyperlinkType.EMAIL, link.getTypeEnum());
|
||||||
|
|
||||||
sheet = wb.getSheet("Internal");
|
sheet = wb.getSheet("Internal");
|
||||||
cell = sheet.getRow(4).getCell(0);
|
cell = sheet.getRow(4).getCell(0);
|
||||||
|
@ -91,7 +92,7 @@ public final class TestHSSFHyperlink extends BaseTestHyperlink {
|
||||||
assertEquals("Link To First Sheet", cell.getRichStringCellValue().getString());
|
assertEquals("Link To First Sheet", cell.getRichStringCellValue().getString());
|
||||||
assertEquals("WebLinks!A1", link.getTextMark());
|
assertEquals("WebLinks!A1", link.getTextMark());
|
||||||
assertEquals("WebLinks!A1", link.getAddress());
|
assertEquals("WebLinks!A1", link.getAddress());
|
||||||
assertEquals(HSSFHyperlink.LINK_DOCUMENT, link.getType());
|
assertEquals(HyperlinkType.DOCUMENT, link.getTypeEnum());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -141,14 +142,14 @@ public final class TestHSSFHyperlink extends BaseTestHyperlink {
|
||||||
//cell A1 has a link to 'Target Sheet-1'!A1
|
//cell A1 has a link to 'Target Sheet-1'!A1
|
||||||
cell = sheet.createRow(0).createCell(0);
|
cell = sheet.createRow(0).createCell(0);
|
||||||
cell.setCellValue("Worksheet Link");
|
cell.setCellValue("Worksheet Link");
|
||||||
link = new HSSFHyperlink(HSSFHyperlink.LINK_DOCUMENT);
|
link = new HSSFHyperlink(HyperlinkType.DOCUMENT);
|
||||||
link.setTextMark("'Target Sheet'!A1");
|
link.setTextMark("'Target Sheet'!A1");
|
||||||
cell.setHyperlink(link);
|
cell.setHyperlink(link);
|
||||||
|
|
||||||
//cell B1 has a link to cell A1 on the same sheet
|
//cell B1 has a link to cell A1 on the same sheet
|
||||||
cell = sheet.createRow(1).createCell(0);
|
cell = sheet.createRow(1).createCell(0);
|
||||||
cell.setCellValue("Worksheet Link");
|
cell.setCellValue("Worksheet Link");
|
||||||
link = new HSSFHyperlink(HSSFHyperlink.LINK_DOCUMENT);
|
link = new HSSFHyperlink(HyperlinkType.DOCUMENT);
|
||||||
link.setAddress("'Hyperlinks'!A1");
|
link.setAddress("'Hyperlinks'!A1");
|
||||||
cell.setHyperlink(link);
|
cell.setHyperlink(link);
|
||||||
|
|
||||||
|
@ -202,7 +203,7 @@ public final class TestHSSFHyperlink extends BaseTestHyperlink {
|
||||||
|
|
||||||
cell = sheet.createRow(1).createCell(0);
|
cell = sheet.createRow(1).createCell(0);
|
||||||
cell.setCellValue("File Link");
|
cell.setCellValue("File Link");
|
||||||
link = new HSSFHyperlink(HSSFHyperlink.LINK_FILE);
|
link = new HSSFHyperlink(HyperlinkType.FILE);
|
||||||
link.setAddress("testfolder\\test.PDF");
|
link.setAddress("testfolder\\test.PDF");
|
||||||
cell.setHyperlink(link);
|
cell.setHyperlink(link);
|
||||||
|
|
||||||
|
@ -239,7 +240,7 @@ public final class TestHSSFHyperlink extends BaseTestHyperlink {
|
||||||
assertEquals(2, link1.getLastRow());
|
assertEquals(2, link1.getLastRow());
|
||||||
|
|
||||||
//assign a hyperlink to A4
|
//assign a hyperlink to A4
|
||||||
HSSFHyperlink link2 = new HSSFHyperlink(HSSFHyperlink.LINK_DOCUMENT);
|
HSSFHyperlink link2 = new HSSFHyperlink(HyperlinkType.DOCUMENT);
|
||||||
link2.setAddress("Sheet2!A2");
|
link2.setAddress("Sheet2!A2");
|
||||||
HSSFCell cell2 = sheet.getRow(3).getCell(0);
|
HSSFCell cell2 = sheet.getRow(3).getCell(0);
|
||||||
cell2.setHyperlink(link2);
|
cell2.setHyperlink(link2);
|
||||||
|
|
|
@ -28,6 +28,7 @@ import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.poi.common.usermodel.HyperlinkType;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||||
import org.apache.poi.ss.ITestDataProvider;
|
import org.apache.poi.ss.ITestDataProvider;
|
||||||
import org.apache.poi.ss.util.CellAddress;
|
import org.apache.poi.ss.util.CellAddress;
|
||||||
|
@ -514,32 +515,32 @@ public abstract class BaseTestSheetShiftRows {
|
||||||
// CellAddress=A1, shifted to A4
|
// CellAddress=A1, shifted to A4
|
||||||
Cell cell = row.createCell(0);
|
Cell cell = row.createCell(0);
|
||||||
cell.setCellStyle(hlinkStyle);
|
cell.setCellStyle(hlinkStyle);
|
||||||
createHyperlink(helper, cell, Hyperlink.LINK_DOCUMENT, "test!E1");
|
createHyperlink(helper, cell, HyperlinkType.DOCUMENT, "test!E1");
|
||||||
|
|
||||||
// URL
|
// URL
|
||||||
cell = row.createCell(1);
|
cell = row.createCell(1);
|
||||||
// CellAddress=B1, shifted to B4
|
// CellAddress=B1, shifted to B4
|
||||||
cell.setCellStyle(hlinkStyle);
|
cell.setCellStyle(hlinkStyle);
|
||||||
createHyperlink(helper, cell, Hyperlink.LINK_URL, "http://poi.apache.org/");
|
createHyperlink(helper, cell, HyperlinkType.URL, "http://poi.apache.org/");
|
||||||
|
|
||||||
// row0 will be shifted on top of row1, so this URL should be removed from the workbook
|
// row0 will be shifted on top of row1, so this URL should be removed from the workbook
|
||||||
Row overwrittenRow = sheet.createRow(3);
|
Row overwrittenRow = sheet.createRow(3);
|
||||||
cell = overwrittenRow.createCell(2);
|
cell = overwrittenRow.createCell(2);
|
||||||
// CellAddress=C4, will be overwritten (deleted)
|
// CellAddress=C4, will be overwritten (deleted)
|
||||||
cell.setCellStyle(hlinkStyle);
|
cell.setCellStyle(hlinkStyle);
|
||||||
createHyperlink(helper, cell, Hyperlink.LINK_EMAIL, "mailto:poi@apache.org");
|
createHyperlink(helper, cell, HyperlinkType.EMAIL, "mailto:poi@apache.org");
|
||||||
|
|
||||||
// hyperlinks on this row are unaffected by the row shifting, so the hyperlinks should not move
|
// hyperlinks on this row are unaffected by the row shifting, so the hyperlinks should not move
|
||||||
Row unaffectedRow = sheet.createRow(20);
|
Row unaffectedRow = sheet.createRow(20);
|
||||||
cell = unaffectedRow.createCell(3);
|
cell = unaffectedRow.createCell(3);
|
||||||
// CellAddress=D21, will be unaffected
|
// CellAddress=D21, will be unaffected
|
||||||
cell.setCellStyle(hlinkStyle);
|
cell.setCellStyle(hlinkStyle);
|
||||||
createHyperlink(helper, cell, Hyperlink.LINK_FILE, "54524.xlsx");
|
createHyperlink(helper, cell, HyperlinkType.FILE, "54524.xlsx");
|
||||||
|
|
||||||
cell = wb.createSheet("other").createRow(0).createCell(0);
|
cell = wb.createSheet("other").createRow(0).createCell(0);
|
||||||
// CellAddress=Other!A1, will be unaffected
|
// CellAddress=Other!A1, will be unaffected
|
||||||
cell.setCellStyle(hlinkStyle);
|
cell.setCellStyle(hlinkStyle);
|
||||||
createHyperlink(helper, cell, Hyperlink.LINK_URL, "http://apache.org/");
|
createHyperlink(helper, cell, HyperlinkType.URL, "http://apache.org/");
|
||||||
|
|
||||||
int startRow = 0;
|
int startRow = 0;
|
||||||
int endRow = 0;
|
int endRow = 0;
|
||||||
|
@ -555,10 +556,10 @@ public abstract class BaseTestSheetShiftRows {
|
||||||
|
|
||||||
// document link anchored on a shifted cell should be moved
|
// document link anchored on a shifted cell should be moved
|
||||||
// Note that hyperlinks do not track what they point to, so this hyperlink should still refer to test!E1
|
// Note that hyperlinks do not track what they point to, so this hyperlink should still refer to test!E1
|
||||||
verifyHyperlink(shiftedRow.getCell(0), Hyperlink.LINK_DOCUMENT, "test!E1");
|
verifyHyperlink(shiftedRow.getCell(0), HyperlinkType.DOCUMENT, "test!E1");
|
||||||
|
|
||||||
// URL, EMAIL, and FILE links anchored on a shifted cell should be moved
|
// URL, EMAIL, and FILE links anchored on a shifted cell should be moved
|
||||||
verifyHyperlink(shiftedRow.getCell(1), Hyperlink.LINK_URL, "http://poi.apache.org/");
|
verifyHyperlink(shiftedRow.getCell(1), HyperlinkType.URL, "http://poi.apache.org/");
|
||||||
|
|
||||||
// Make sure hyperlinks were moved and not copied
|
// Make sure hyperlinks were moved and not copied
|
||||||
assertNull("Document hyperlink should be moved, not copied", sh.getHyperlink(0, 0));
|
assertNull("Document hyperlink should be moved, not copied", sh.getHyperlink(0, 0));
|
||||||
|
@ -578,12 +579,12 @@ public abstract class BaseTestSheetShiftRows {
|
||||||
// Make sure unaffected rows are not shifted
|
// Make sure unaffected rows are not shifted
|
||||||
Cell unaffectedCell = sh.getRow(20).getCell(3);
|
Cell unaffectedCell = sh.getRow(20).getCell(3);
|
||||||
assertTrue(cellHasHyperlink(unaffectedCell));
|
assertTrue(cellHasHyperlink(unaffectedCell));
|
||||||
verifyHyperlink(unaffectedCell, Hyperlink.LINK_FILE, "54524.xlsx");
|
verifyHyperlink(unaffectedCell, HyperlinkType.FILE, "54524.xlsx");
|
||||||
|
|
||||||
// Make sure cells on other sheets are not affected
|
// Make sure cells on other sheets are not affected
|
||||||
unaffectedCell = read.getSheet("other").getRow(0).getCell(0);
|
unaffectedCell = read.getSheet("other").getRow(0).getCell(0);
|
||||||
assertTrue(cellHasHyperlink(unaffectedCell));
|
assertTrue(cellHasHyperlink(unaffectedCell));
|
||||||
verifyHyperlink(unaffectedCell, Hyperlink.LINK_URL, "http://apache.org/");
|
verifyHyperlink(unaffectedCell, HyperlinkType.URL, "http://apache.org/");
|
||||||
|
|
||||||
read.close();
|
read.close();
|
||||||
}
|
}
|
||||||
|
@ -678,17 +679,17 @@ public abstract class BaseTestSheetShiftRows {
|
||||||
wb.close();
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createHyperlink(CreationHelper helper, Cell cell, int linkType, String ref) {
|
private void createHyperlink(CreationHelper helper, Cell cell, HyperlinkType linkType, String ref) {
|
||||||
cell.setCellValue(ref);
|
cell.setCellValue(ref);
|
||||||
Hyperlink link = helper.createHyperlink(linkType);
|
Hyperlink link = helper.createHyperlink(linkType);
|
||||||
link.setAddress(ref);
|
link.setAddress(ref);
|
||||||
cell.setHyperlink(link);
|
cell.setHyperlink(link);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void verifyHyperlink(Cell cell, int linkType, String ref) {
|
private void verifyHyperlink(Cell cell, HyperlinkType linkType, String ref) {
|
||||||
assertTrue(cellHasHyperlink(cell));
|
assertTrue(cellHasHyperlink(cell));
|
||||||
Hyperlink link = cell.getHyperlink();
|
Hyperlink link = cell.getHyperlink();
|
||||||
assertEquals(linkType, link.getType());
|
assertEquals(linkType, link.getTypeEnum());
|
||||||
assertEquals(ref, link.getAddress());
|
assertEquals(ref, link.getAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue