package org.apache.poi.xssf.usermodel;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
-
-import java.io.IOException;
-
import org.apache.poi.common.usermodel.HyperlinkType;
import org.apache.poi.hssf.usermodel.HSSFHyperlink;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.openxml4j.opc.PackageRelationship;
import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
-import org.apache.poi.ss.usermodel.BaseTestHyperlink;
-import org.apache.poi.ss.usermodel.Cell;
-import org.apache.poi.ss.usermodel.CreationHelper;
-import org.apache.poi.ss.usermodel.Hyperlink;
-import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellAddress;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.xssf.XSSFITestDataProvider;
import org.apache.poi.xssf.XSSFTestDataSamples;
import org.junit.Test;
+import java.io.IOException;
+
+import static org.junit.Assert.*;
+
public final class TestXSSFHyperlink extends BaseTestHyperlink {
public TestXSSFHyperlink() {
super(XSSFITestDataProvider.instance);
for(int i = 0; i < rels.size(); i++){
PackageRelationship rel = rels.getRelationship(i);
// there should be a relationship for each URL
+ assertNotNull(rel);
assertEquals(urls[i], rel.getTargetURI().toString());
}
for(int i = 0; i < rels.size(); i++){
PackageRelationship rel = rels.getRelationship(i);
// there should be a relationship for each URL
+ assertNotNull(rel);
assertEquals(urls[i], rel.getTargetURI().toString());
}
}
createHelper.createHyperlink(HyperlinkType.URL).setAddress(s);
fail("expected IllegalArgumentException: " + s);
} catch (IllegalArgumentException e){
-
+ // expected here
}
}
workbook.close();
wb.close();
}
+
+ @Test
+ public void test() throws IOException {
+ XSSFWorkbook wb = new XSSFWorkbook();
+
+ CreationHelper createHelper = wb.getCreationHelper();
+ XSSFCellStyle hlinkStyle = (XSSFCellStyle) wb.createCellStyle();
+ Font hlinkFont = wb.createFont();
+
+ Sheet sheet = wb.createSheet("test");
+
+ Row rowDet = sheet.createRow(0);
+
+ Cell cellDet = rowDet.createCell(7);
+ cellDet.setCellValue("http://www.google.at");
+ //set up style to be able to create hyperlinks
+ hlinkFont.setColor(IndexedColors.BLUE.getIndex());
+ hlinkStyle.setFont(hlinkFont);
+ Hyperlink link = createHelper.createHyperlink(HyperlinkType.URL);
+ link.setAddress("http://www.example.com");
+ cellDet.setHyperlink(link);
+ cellDet.setCellStyle(hlinkStyle);
+
+ //set up style to be able to create hyperlinks
+ hlinkFont.setColor(IndexedColors.BLUE.getIndex());
+ hlinkStyle.setFont(hlinkFont);
+ link = createHelper.createHyperlink(HyperlinkType.URL);
+
+ //string for hyperlink
+ cellDet = rowDet.createCell(13);
+ cellDet.setCellValue("http://www.other.com");
+ link.setAddress("http://www.gmx.at");
+ cellDet.setHyperlink(link);
+ cellDet.setCellStyle(hlinkStyle);
+
+ XSSFWorkbook wbBack = XSSFTestDataSamples.writeOutAndReadBack(wb);
+
+ assertNotNull(wbBack.getSheetAt(0).getRow(0).getCell(7).getHyperlink());
+ assertNotNull(wbBack.getSheetAt(0).getRow(0).getCell(13).getHyperlink());
+
+ wb.close();
+ wbBack.close();
+ }
}