Browse Source

add R1C1 test

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1897657 13f79535-47bb-0310-9956-ffa450edef68
tags/REL_5_2_1
PJ Fanning 2 years ago
parent
commit
607eb0fabe

+ 16
- 0
poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java View File

@@ -1357,6 +1357,22 @@ public final class TestXSSFWorkbook extends BaseTestXWorkbook {
}
}

@Test
void checkNewFileForR1C1Refs() throws IOException {
try (
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
XSSFWorkbook wb = new XSSFWorkbook()
) {
assertNull(wb.usesR1C1CellReferences());
wb.setUseR1C1CellReferences(true);
assertTrue(wb.usesR1C1CellReferences());
wb.write(bos);
try (XSSFWorkbook wb2 = new XSSFWorkbook(bos.toInputStream())) {
assertTrue(wb2.usesR1C1CellReferences());
}
}
}

private static void expectFormattedContent(Cell cell, String value) {
assertEquals(value, new DataFormatter().formatCellValue(cell),
"Cell " + ref(cell) + " has wrong formatted content.");

+ 10
- 0
poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java View File

@@ -1769,6 +1769,16 @@ public final class HSSFWorkbook extends POIDocument implements Workbook {
return null;
}

/**
* Configure workbook to use R1C1 cell references (as opposed to A1 cell references).
* <p>
* Note that HSSF format stores this information at sheet level - so if the workbook has no sheets,
* this call will have no effect. It is recommended that you call this (possibly again) just before
* writing HSSFWorkbook.
* </p>
* @param useR1C1CellReferences set to true if you want to configure workbook to use R1C1 cell references (as opposed to A1 cell references).
* @since POI 5.2.1
*/
@Override
public void setUseR1C1CellReferences(boolean useR1C1CellReferences) {
for (HSSFSheet hssfSheet : _sheets) {

+ 18
- 0
poi/src/test/java/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java View File

@@ -1194,6 +1194,24 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
}
}

@Test
void checkNewFileForR1C1Refs() throws IOException {
try (
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
HSSFWorkbook wb = new HSSFWorkbook()
) {
assertNull(wb.usesR1C1CellReferences());
HSSFSheet sheet = wb.createSheet();
assertFalse(wb.usesR1C1CellReferences());
wb.setUseR1C1CellReferences(true);
assertTrue(wb.usesR1C1CellReferences());
wb.write(bos);
try (HSSFWorkbook wb2 = new HSSFWorkbook(bos.toInputStream())) {
assertTrue(wb2.usesR1C1CellReferences());
}
}
}

@Disabled
void createDrawing() {
// the dimensions for this image are different than for XSSF and SXSSF

Loading…
Cancel
Save