//collect unit tests
System.out.println("Collecting unit tests from " + _testDir);
collectTests(_testDir, _testDir, lst, ".+.class$",
- ".+(TestUnfixedBugs|MemoryUsage|TestDataProvider|TestDataSamples|All.+Tests|ZipFileAssert|PkiTestUtils|TestCellFormatPart\\$\\d|TestSignatureInfo\\$\\d).class");
+ ".+(BaseTestXCell|TestUnfixedBugs|MemoryUsage|TestDataProvider|TestDataSamples|All.+Tests|ZipFileAssert|PkiTestUtils|TestCellFormatPart\\$\\d|TestSignatureInfo\\$\\d).class");
System.out.println("Found " + lst.size() + " classes");
//run tests
--- /dev/null
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.ss.usermodel;
+
+import org.apache.poi.hssf.usermodel.HSSFCell;
+import org.apache.poi.ss.ITestDataProvider;
+import org.apache.poi.xssf.SXSSFITestDataProvider;
+import org.apache.poi.xssf.XSSFITestDataProvider;
+import org.apache.poi.xssf.streaming.SXSSFCell;
+import org.apache.poi.xssf.usermodel.XSSFCell;
+
+/**
+ * Class for combined testing of XML-specific functionality of
+ * {@link XSSFCell} and {@link SXSSFCell}.
+ *
+ * Any test that is applicable for {@link HSSFCell} as well should go into
+ * the common base class {@link BaseTestCell}.
+ */
+public abstract class BaseTestXCell extends BaseTestCell {
+ protected BaseTestXCell(ITestDataProvider testDataProvider) {
+ super(testDataProvider);
+ }
+
+ public void testXmlEncoding(){
+ Workbook wb = _testDataProvider.createWorkbook();
+ Sheet sh = wb.createSheet();
+ Row row = sh.createRow(0);
+ Cell cell = row.createCell(0);
+ String sval = "\u0000\u0002\u0012<>\t\n\u00a0 &\"POI\'\u2122";
+ cell.setCellValue(sval);
+
+ wb = _testDataProvider.writeOutAndReadBack(wb);
+
+ // invalid characters are replaced with question marks
+ assertEquals("???<>\t\n\u00a0 &\"POI\'\u2122", wb.getSheetAt(0).getRow(0).getCell(0).getStringCellValue());
+
+ }
+
+ public void testEncodingbeloAscii(){
+ Workbook xwb = XSSFITestDataProvider.instance.createWorkbook();
+ Cell xCell = xwb.createSheet().createRow(0).createCell(0);
+
+ Workbook swb = SXSSFITestDataProvider.instance.createWorkbook();
+ Cell sCell = swb.createSheet().createRow(0).createCell(0);
+
+ StringBuffer sb = new StringBuffer();
+ // test all possible characters
+ for(int i = 0; i < Character.MAX_VALUE; i++) sb.append((char)i) ;
+
+ String str = sb.toString();
+
+ xCell.setCellValue(str);
+ assertEquals(str, xCell.getStringCellValue());
+ sCell.setCellValue(str);
+ assertEquals(str, sCell.getStringCellValue());
+
+ xwb = XSSFITestDataProvider.instance.writeOutAndReadBack(xwb);
+ swb = SXSSFITestDataProvider.instance.writeOutAndReadBack(swb);
+ xCell = xwb.getSheetAt(0).createRow(0).createCell(0);
+ sCell = swb.getSheetAt(0).createRow(0).createCell(0);
+
+ assertEquals(xCell.getStringCellValue(), sCell.getStringCellValue());
+ }
+}
import javax.xml.namespace.QName;
-import org.apache.poi.ss.usermodel.BaseTestCell;
+import org.apache.poi.ss.usermodel.BaseTestXCell;
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.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.SXSSFITestDataProvider;
-import org.apache.poi.xssf.XSSFITestDataProvider;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.xmlbeans.XmlCursor;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;
/**
- *
+ * Tests various functionality having to do with {@link SXSSFCell}. For instance support for
+ * particular datatypes, etc.
*/
-public class TestSXSSFCell extends BaseTestCell {
+public class TestSXSSFCell extends BaseTestXCell {
public TestSXSSFCell() {
super(SXSSFITestDataProvider.instance);
}
-
@Override
public void tearDown(){
SXSSFITestDataProvider.instance.cleanup();
"Only XSSFCells can be evaluated.", e.getMessage());
}
}
-
- public void testXmlEncoding(){
- Workbook wb = _testDataProvider.createWorkbook();
- Sheet sh = wb.createSheet();
- Row row = sh.createRow(0);
- Cell cell = row.createCell(0);
- String sval = "\u0000\u0002\u0012<>\t\n\u00a0 &\"POI\'\u2122";
- cell.setCellValue(sval);
-
- wb = _testDataProvider.writeOutAndReadBack(wb);
-
- // invalid characters are replaced with question marks
- assertEquals("???<>\t\n\u00a0 &\"POI\'\u2122", wb.getSheetAt(0).getRow(0).getCell(0).getStringCellValue());
-
- }
-
- public void testEncodingbeloAscii(){
- Workbook xwb = new XSSFWorkbook();
- Cell xCell = xwb.createSheet().createRow(0).createCell(0);
-
- Workbook swb = SXSSFITestDataProvider.instance.createWorkbook();
- Cell sCell = swb.createSheet().createRow(0).createCell(0);
-
- StringBuffer sb = new StringBuffer();
- // test all possible characters
- for(int i = 0; i < Character.MAX_VALUE; i++) sb.append((char)i) ;
-
- String str = sb.toString();
-
- xCell.setCellValue(str);
- assertEquals(str, xCell.getStringCellValue());
- sCell.setCellValue(str);
- assertEquals(str, sCell.getStringCellValue());
-
- xwb = XSSFITestDataProvider.instance.writeOutAndReadBack(xwb);
- swb = SXSSFITestDataProvider.instance.writeOutAndReadBack(swb);
- xCell = xwb.getSheetAt(0).createRow(0).createCell(0);
- sCell = swb.getSheetAt(0).createRow(0).createCell(0);
-
- assertEquals(xCell.getStringCellValue(), sCell.getStringCellValue());
-
+
+ /**
+ * this test involves evaluation of formulas which isn't supported for SXSSF
+ */
+ @Override
+ public void testGetErrorCellValueFromFormulaCell() {
+ try {
+ super.testConvertStringFormulaCell();
+ fail("expected exception");
+ } catch (IllegalArgumentException e){
+ assertEquals(
+ "Unexpected type of cell: class org.apache.poi.xssf.streaming.SXSSFCell. " +
+ "Only XSSFCells can be evaluated.", e.getMessage());
+ }
}
public void testPreserveSpaces() throws IOException {
"\n\nPOI \n",
};
for(String str : samplesWithSpaces){
- Workbook swb = new SXSSFWorkbook();
+ Workbook swb = _testDataProvider.createWorkbook();
Cell sCell = swb.createSheet().createRow(0).createCell(0);
sCell.setCellValue(str);
assertEquals(sCell.getStringCellValue(), str);
// read back as XSSF and check that xml:spaces="preserve" is set
- XSSFWorkbook xwb = (XSSFWorkbook)SXSSFITestDataProvider.instance.writeOutAndReadBack(swb);
+ XSSFWorkbook xwb = (XSSFWorkbook)_testDataProvider.writeOutAndReadBack(swb);
XSSFCell xCell = xwb.getSheetAt(0).getRow(0).getCell(0);
CTRst is = xCell.getCTCell().getIs();
assertEquals("expected xml:spaces=\"preserve\" \"" + str + "\"", "preserve", t);
}
}
-
- public void testBug55658SetNumericValue(){
- Workbook wb = new SXSSFWorkbook();
- Sheet sh = wb.createSheet();
- Row row = sh.createRow(0);
- Cell cell = row.createCell(0);
- cell.setCellValue(Integer.valueOf(23));
-
- cell.setCellValue("some");
-
- cell = row.createCell(1);
- cell.setCellValue(Integer.valueOf(23));
-
- cell.setCellValue("24");
-
- wb = _testDataProvider.writeOutAndReadBack(wb);
-
- assertEquals("some", wb.getSheetAt(0).getRow(0).getCell(0).getStringCellValue());
- assertEquals("24", wb.getSheetAt(0).getRow(0).getCell(1).getStringCellValue());
- }
-
- public void testRemoveHyperlink(){
- Workbook wb = _testDataProvider.createWorkbook();
- Sheet sh = wb.createSheet("test");
- Row row = sh.createRow(0);
- CreationHelper helper = wb.getCreationHelper();
-
- Cell cell1 = row.createCell(1);
- Hyperlink link1 = helper.createHyperlink(Hyperlink.LINK_URL);
- cell1.setHyperlink(link1);
- assertNotNull(cell1.getHyperlink());
- cell1.removeHyperlink();
- assertNull(cell1.getHyperlink());
-
- Cell cell2 = row.createCell(0);
- Hyperlink link2 = helper.createHyperlink(Hyperlink.LINK_URL);
- cell2.setHyperlink(link2);
- assertNotNull(cell2.getHyperlink());
- cell2.setHyperlink(null);
- assertNull(cell2.getHyperlink());
-
- _testDataProvider.writeOutAndReadBack(wb);
- }
}
import java.io.IOException;
-import org.apache.poi.ss.usermodel.BaseTestCell;
+import org.apache.poi.ss.usermodel.BaseTestXCell;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.DataFormatter;
-import org.apache.poi.ss.usermodel.Hyperlink;
+import org.apache.poi.ss.usermodel.RichTextString;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
/**
* @author Yegor Kozlov
*/
-public final class TestXSSFCell extends BaseTestCell {
+public final class TestXSSFCell extends BaseTestXCell {
public TestXSSFCell() {
super(XSSFITestDataProvider.instance);
*/
public void test47278() {
XSSFWorkbook wb = (XSSFWorkbook)_testDataProvider.createWorkbook();
- XSSFSheet sheet = wb.createSheet();
- XSSFRow row = sheet.createRow(0);
+ Sheet sheet = wb.createSheet();
+ Row row = sheet.createRow(0);
SharedStringsTable sst = wb.getSharedStringSource();
assertEquals(0, sst.getCount());
//case 1. cell.setCellValue(new XSSFRichTextString((String)null));
- XSSFCell cell_0 = row.createCell(0);
- XSSFRichTextString str = new XSSFRichTextString((String)null);
+ Cell cell_0 = row.createCell(0);
+ RichTextString str = new XSSFRichTextString((String)null);
assertNull(str.getString());
cell_0.setCellValue(str);
assertEquals(0, sst.getCount());
- assertEquals(XSSFCell.CELL_TYPE_BLANK, cell_0.getCellType());
+ assertEquals(Cell.CELL_TYPE_BLANK, cell_0.getCellType());
//case 2. cell.setCellValue((String)null);
- XSSFCell cell_1 = row.createCell(1);
+ Cell cell_1 = row.createCell(1);
cell_1.setCellValue((String)null);
assertEquals(0, sst.getCount());
- assertEquals(XSSFCell.CELL_TYPE_BLANK, cell_1.getCellType());
+ assertEquals(Cell.CELL_TYPE_BLANK, cell_1.getCellType());
}
public void testFormulaString() throws IOException {
- XSSFWorkbook wb = new XSSFWorkbook();
+ XSSFWorkbook wb = (XSSFWorkbook)_testDataProvider.createWorkbook();
try {
XSSFCell cell = wb.createSheet().createRow(0).createCell(0);
CTCell ctCell = cell.getCTCell(); //low-level bean holding cell's xml
assertEquals(null, cell.getCellStyle());
}
- /**
- * Cell with the formula that returns error must return error code(There was
- * an problem that cell could not return error value form formula cell).
- * @throws IOException
- */
- public void testGetErrorCellValueFromFormulaCell() throws IOException {
- XSSFWorkbook wb = new XSSFWorkbook();
- try {
- XSSFSheet sheet = wb.createSheet();
- XSSFRow row = sheet.createRow(0);
- XSSFCell cell = row.createCell(0);
- cell.setCellFormula("SQRT(-1)");
- wb.getCreationHelper().createFormulaEvaluator().evaluateFormulaCell(cell);
- assertEquals(36, cell.getErrorCellValue());
- } finally {
- wb.close();
- }
- }
-
public void testMissingRAttribute() {
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = wb.createSheet();
}
}
- public void testRemoveHyperlink() {
- final Workbook wb = new XSSFWorkbook();
- final Sheet sheet = wb.createSheet();
- Row row = sheet.createRow(0);
-
- Cell cell1 = row.createCell(1);
- Hyperlink link1 = new XSSFHyperlink(Hyperlink.LINK_URL);
- cell1.setHyperlink(link1);
- assertNotNull(cell1.getHyperlink());
- cell1.removeHyperlink();
- assertNull(cell1.getHyperlink());
-
- Cell cell2 = row.createCell(0);
- Hyperlink link2 = new XSSFHyperlink(Hyperlink.LINK_URL);
- cell2.setHyperlink(link2);
- assertNotNull(cell2.getHyperlink());
- cell2.setHyperlink(null);
- assertNull(cell2.getHyperlink());
-
- XSSFTestDataSamples.writeOutAndReadBack(wb);
- }
-
public void testBug56644ReturnNull() throws IOException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("56644.xlsx");
try {
import org.apache.poi.ss.usermodel.BaseTestCell;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.ErrorConstants;
-import org.apache.poi.ss.usermodel.Hyperlink;
+import org.apache.poi.ss.usermodel.FormulaError;
import org.apache.poi.ss.usermodel.RichTextString;
+import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
public TestHSSFCell() {
super(HSSFITestDataProvider.instance);
}
+
/**
* Checks that the recognition of files using 1904 date windowing
* is working properly. Conversion of the date is also an issue,
//
// fos.close();
- wb = _testDataProvider.writeOutAndReadBack(wb);
-
- assertEquals(1, ((HSSFSheet)wb.getSheetAt(0)).getSheet().getActiveCellRow());
- assertEquals(3, ((HSSFSheet)wb.getSheetAt(0)).getSheet().getActiveCellCol());
+ Workbook wbBack = _testDataProvider.writeOutAndReadBack(wb);
+ wb.close();
+
+ assertEquals(1, ((HSSFSheet)wbBack.getSheetAt(0)).getSheet().getActiveCellRow());
+ assertEquals(3, ((HSSFSheet)wbBack.getSheetAt(0)).getSheet().getActiveCellCol());
- wb.getSheetAt(0).getRow(3).getCell(3).setAsActiveCell();
+ wbBack.getSheetAt(0).getRow(3).getCell(3).setAsActiveCell();
- assertEquals(3, ((HSSFSheet)wb.getSheetAt(0)).getSheet().getActiveCellRow());
- assertEquals(3, ((HSSFSheet)wb.getSheetAt(0)).getSheet().getActiveCellCol());
+ assertEquals(3, ((HSSFSheet)wbBack.getSheetAt(0)).getSheet().getActiveCellRow());
+ assertEquals(3, ((HSSFSheet)wbBack.getSheetAt(0)).getSheet().getActiveCellCol());
// fos = new FileOutputStream("/tmp/56114a.xls");
//
-// wb.write(fos);
+// wbBack.write(fos);
//
// fos.close();
- wb = _testDataProvider.writeOutAndReadBack(wb);
+ Workbook wbBack2 = _testDataProvider.writeOutAndReadBack(wbBack);
+ wbBack.close();
- assertEquals(3, ((HSSFSheet)wb.getSheetAt(0)).getSheet().getActiveCellRow());
- assertEquals(3, ((HSSFSheet)wb.getSheetAt(0)).getSheet().getActiveCellCol());
+ assertEquals(3, ((HSSFSheet)wbBack2.getSheetAt(0)).getSheet().getActiveCellRow());
+ assertEquals(3, ((HSSFSheet)wbBack2.getSheetAt(0)).getSheet().getActiveCellCol());
+ wbBack2.close();
}
+
/**
* Test reading hyperlinks
*/
assertEquals(1, link2.getFirstColumn());
}
- public void testRemoveHyperlink() {
- HSSFWorkbook wb = new HSSFWorkbook();
- HSSFSheet sheet = wb.createSheet();
- HSSFRow row = sheet.createRow(0);
-
- HSSFCell cell1 = row.createCell(1);
- HSSFHyperlink link1 = new HSSFHyperlink(Hyperlink.LINK_URL);
- assertNotNull(link1);
- cell1.removeHyperlink();
- assertNull(cell1.getHyperlink());
-
- HSSFCell cell2 = row.createCell(0);
- HSSFHyperlink link2 = new HSSFHyperlink(Hyperlink.LINK_URL);
- assertNotNull(link2);
- cell2.setHyperlink(null);
- assertNull(cell2.getHyperlink());
-
- HSSFTestDataSamples.writeOutAndReadBack(wb);
- }
-
/**
* Test to ensure we can only assign cell styles that belong
* to our workbook, and not those from other workbooks.
* the {@link StringRecord} following the {@link FormulaRecord} after the result type had been
* changed to number/boolean/error. Excel silently ignores the extra record, but some POI
* versions (prior to bug 46213 / r717883) crash instead.
+ * @throws IOException
*/
- public void testCachedTypeChange() {
- HSSFSheet sheet = new HSSFWorkbook().createSheet("Sheet1");
- HSSFCell cell = sheet.createRow(0).createCell(0);
+ public void testCachedTypeChange() throws IOException {
+ HSSFWorkbook wb = new HSSFWorkbook();
+ HSSFSheet sheet = wb.createSheet("Sheet1");
+ Cell cell = sheet.createRow(0).createCell(0);
cell.setCellFormula("A1");
cell.setCellValue("abc");
confirmStringRecord(sheet, true);
cell.setCellValue(123);
Record[] recs = RecordInspector.getRecords(sheet, 0);
if (recs.length == 28 && recs[23] instanceof StringRecord) {
+ wb.close();
throw new AssertionFailedError("Identified bug - leftover StringRecord");
}
confirmStringRecord(sheet, false);
confirmStringRecord(sheet, true);
cell.setCellValue(false);
confirmStringRecord(sheet, false);
+ wb.close();
}
private static void confirmStringRecord(HSSFSheet sheet, boolean isPresent) {
/**
* The maximum length of cell contents (text) is 32,767 characters.
+ * @throws IOException
*/
- public void testMaxTextLength(){
- HSSFSheet sheet = new HSSFWorkbook().createSheet();
+ public void testMaxTextLength() throws IOException{
+ HSSFWorkbook wb = new HSSFWorkbook();
+ HSSFSheet sheet = wb.createSheet();
HSSFCell cell = sheet.createRow(0).createCell(0);
int maxlen = SpreadsheetVersion.EXCEL97.getMaxTextLength();
} catch (IllegalArgumentException e){
assertEquals("The maximum length of cell contents (text) is 32,767 characters", e.getMessage());
}
+ wb.close();
}
/**
cell.removeCellComment();
}
- public void testCellType() {
- HSSFWorkbook wb = new HSSFWorkbook();
- HSSFSheet sheet = wb.createSheet();
- HSSFRow row = sheet.createRow(0);
- HSSFCell cell = row.createCell(0);
+ public void testCellType() throws IOException {
+ Workbook wb = _testDataProvider.createWorkbook();
+ Sheet sheet = wb.createSheet();
+ Row row = sheet.createRow(0);
+ Cell cell = row.createCell(0);
cell.setCellType(Cell.CELL_TYPE_BLANK);
assertNull(null, cell.getDateCellValue());
cell.setCellType(Cell.CELL_TYPE_BOOLEAN);
assertEquals("TRUE", cell.toString());
cell.setCellType(Cell.CELL_TYPE_BOOLEAN);
+ cell.setCellValue("" + FormulaError.VALUE.name());
cell.setCellType(Cell.CELL_TYPE_ERROR);
assertEquals("#VALUE!", cell.toString());
cell.setCellType(Cell.CELL_TYPE_ERROR);
cell.setCellValue((String)null);
cell.setCellValue((RichTextString)null);
- }
-
- public void testSetRemoveStyle() throws Exception {
- HSSFWorkbook wb = new HSSFWorkbook();
- HSSFSheet sheet = wb.createSheet();
- HSSFRow row = sheet.createRow(0);
- HSSFCell cell = row.createCell(0);
-
- HSSFCellStyle defaultStyle = wb.getCellStyleAt((short)15);
-
- // Starts out with the default style
- assertEquals(defaultStyle, cell.getCellStyle());
-
- // Create some styles, no change
- HSSFCellStyle style1 = wb.createCellStyle();
- HSSFCellStyle style2 = wb.createCellStyle();
- style1.setDataFormat((short)2);
- style2.setDataFormat((short)3);
-
- assertEquals(defaultStyle, cell.getCellStyle());
-
- // Apply one, changes
- cell.setCellStyle(style1);
- assertEquals(style1, cell.getCellStyle());
-
- // Apply the other, changes
- cell.setCellStyle(style2);
- assertEquals(style2, cell.getCellStyle());
-
- // Remove, goes back to default
- cell.setCellStyle(null);
- assertEquals(defaultStyle, cell.getCellStyle());
-
- // Add back, returns
- cell.setCellStyle(style2);
- assertEquals(style2, cell.getCellStyle());
+ wb.close();
}
}
package org.apache.poi.ss.usermodel;
+import java.io.IOException;
import java.util.Calendar;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.ITestDataProvider;
/**
- * Common superclass for testing implementatiosn of
+ * Common superclass for testing implementations of
* {@link org.apache.poi.ss.usermodel.Cell}
*/
public abstract class BaseTestCell extends TestCase {
assertFalse(style2.getHidden());
}
+ public void testBug55658SetNumericValue(){
+ Workbook wb = _testDataProvider.createWorkbook();
+ Sheet sh = wb.createSheet();
+ Row row = sh.createRow(0);
+ Cell cell = row.createCell(0);
+ cell.setCellValue(Integer.valueOf(23));
+
+ cell.setCellValue("some");
+
+ cell = row.createCell(1);
+ cell.setCellValue(Integer.valueOf(23));
+
+ cell.setCellValue("24");
+
+ wb = _testDataProvider.writeOutAndReadBack(wb);
+
+ assertEquals("some", wb.getSheetAt(0).getRow(0).getCell(0).getStringCellValue());
+ assertEquals("24", wb.getSheetAt(0).getRow(0).getCell(1).getStringCellValue());
+ }
+
+ public void testRemoveHyperlink(){
+ Workbook wb = _testDataProvider.createWorkbook();
+ Sheet sh = wb.createSheet("test");
+ Row row = sh.createRow(0);
+ CreationHelper helper = wb.getCreationHelper();
+
+ Cell cell1 = row.createCell(1);
+ Hyperlink link1 = helper.createHyperlink(Hyperlink.LINK_URL);
+ cell1.setHyperlink(link1);
+ assertNotNull(cell1.getHyperlink());
+ cell1.removeHyperlink();
+ assertNull(cell1.getHyperlink());
+
+ Cell cell2 = row.createCell(0);
+ Hyperlink link2 = helper.createHyperlink(Hyperlink.LINK_URL);
+ cell2.setHyperlink(link2);
+ assertNotNull(cell2.getHyperlink());
+ cell2.setHyperlink(null);
+ assertNull(cell2.getHyperlink());
+
+ Cell cell3 = row.createCell(2);
+ Hyperlink link3 = helper.createHyperlink(Hyperlink.LINK_URL);
+ link3.setAddress("http://poi.apache.org/");
+ cell3.setHyperlink(link3);
+ assertNotNull(cell3.getHyperlink());
+
+ Workbook wbBack = _testDataProvider.writeOutAndReadBack(wb);
+ assertNotNull(wbBack);
+
+ cell1 = wbBack.getSheet("test").getRow(0).getCell(1);
+ assertNull(cell1.getHyperlink());
+ cell2 = wbBack.getSheet("test").getRow(0).getCell(0);
+ assertNull(cell2.getHyperlink());
+ cell3 = wbBack.getSheet("test").getRow(0).getCell(2);
+ assertNotNull(cell3.getHyperlink());
+ }
+
+ /**
+ * Cell with the formula that returns error must return error code(There was
+ * an problem that cell could not return error value form formula cell).
+ * @throws IOException
+ */
+ public void testGetErrorCellValueFromFormulaCell() throws IOException {
+ Workbook wb = _testDataProvider.createWorkbook();
+ try {
+ Sheet sheet = wb.createSheet();
+ Row row = sheet.createRow(0);
+ Cell cell = row.createCell(0);
+ cell.setCellFormula("SQRT(-1)");
+ wb.getCreationHelper().createFormulaEvaluator().evaluateFormulaCell(cell);
+ assertEquals(36, cell.getErrorCellValue());
+ } finally {
+ wb.close();
+ }
+ }
+
+ public void testSetRemoveStyle() throws Exception {
+ Workbook wb = _testDataProvider.createWorkbook();
+ Sheet sheet = wb.createSheet();
+ Row row = sheet.createRow(0);
+ Cell cell = row.createCell(0);
+
+ // different default style indexes for HSSF and XSSF/SXSSF
+ CellStyle defaultStyle = wb.getCellStyleAt(wb instanceof HSSFWorkbook ? (short)15 : (short)0);
+
+ // Starts out with the default style
+ assertEquals(defaultStyle, cell.getCellStyle());
+
+ // Create some styles, no change
+ CellStyle style1 = wb.createCellStyle();
+ CellStyle style2 = wb.createCellStyle();
+ style1.setDataFormat((short)2);
+ style2.setDataFormat((short)3);
+
+ assertEquals(defaultStyle, cell.getCellStyle());
+
+ // Apply one, changes
+ cell.setCellStyle(style1);
+ assertEquals(style1, cell.getCellStyle());
+
+ // Apply the other, changes
+ cell.setCellStyle(style2);
+ assertEquals(style2, cell.getCellStyle());
+
+ // Remove, goes back to default
+ cell.setCellStyle(null);
+ assertEquals(defaultStyle, cell.getCellStyle());
+
+ // Add back, returns
+ cell.setCellStyle(style2);
+ assertEquals(style2, cell.getCellStyle());
+
+ wb.close();
+ }
}