diff --git a/src/java/org/apache/poi/ss/usermodel/CellStyle.java b/src/java/org/apache/poi/ss/usermodel/CellStyle.java index 7b62c1ee8..3eed0604b 100644 --- a/src/java/org/apache/poi/ss/usermodel/CellStyle.java +++ b/src/java/org/apache/poi/ss/usermodel/CellStyle.java @@ -113,7 +113,7 @@ public interface CellStyle { * dot border */ - public final static short BORDER_HAIR = 0x4; + public final static short BORDER_HAIR = 0x7; /** * Thick border @@ -131,7 +131,7 @@ public interface CellStyle { * hair-line border */ - public final static short BORDER_DOTTED = 0x7; + public final static short BORDER_DOTTED = 0x4; /** * Medium dashed border diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java index 11b724f4a..303cba95e 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java @@ -229,6 +229,136 @@ public class TestXSSFCellStyle extends TestCase { assertFalse(ctBorder.isSetTop()); } + public void testGetSetBorderThin() { + cellStyle.setBorderTop(CellStyle.BORDER_THIN); + assertEquals(CellStyle.BORDER_THIN, cellStyle.getBorderTop()); + int borderId = (int)cellStyle.getCoreXf().getBorderId(); + assertTrue(borderId > 0); + //check changes in the underlying xml bean + CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder(); + assertEquals(STBorderStyle.THIN, ctBorder.getTop().getStyle()); + } + + public void testGetSetBorderMedium() { + cellStyle.setBorderTop(CellStyle.BORDER_MEDIUM); + assertEquals(CellStyle.BORDER_MEDIUM, cellStyle.getBorderTop()); + int borderId = (int)cellStyle.getCoreXf().getBorderId(); + assertTrue(borderId > 0); + //check changes in the underlying xml bean + CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder(); + assertEquals(STBorderStyle.MEDIUM, ctBorder.getTop().getStyle()); + } + + public void testGetSetBorderThick() { + cellStyle.setBorderTop(CellStyle.BORDER_THICK); + assertEquals(CellStyle.BORDER_THICK, cellStyle.getBorderTop()); + int borderId = (int)cellStyle.getCoreXf().getBorderId(); + assertTrue(borderId > 0); + //check changes in the underlying xml bean + CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder(); + assertEquals(STBorderStyle.THICK, ctBorder.getTop().getStyle()); + } + + public void testGetSetBorderHair() { + cellStyle.setBorderTop(CellStyle.BORDER_HAIR); + assertEquals(CellStyle.BORDER_HAIR, cellStyle.getBorderTop()); + int borderId = (int)cellStyle.getCoreXf().getBorderId(); + assertTrue(borderId > 0); + //check changes in the underlying xml bean + CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder(); + assertEquals(STBorderStyle.HAIR, ctBorder.getTop().getStyle()); + } + + public void testGetSetBorderDotted() { + cellStyle.setBorderTop(CellStyle.BORDER_DOTTED); + assertEquals(CellStyle.BORDER_DOTTED, cellStyle.getBorderTop()); + int borderId = (int)cellStyle.getCoreXf().getBorderId(); + assertTrue(borderId > 0); + //check changes in the underlying xml bean + CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder(); + assertEquals(STBorderStyle.DOTTED, ctBorder.getTop().getStyle()); + } + + public void testGetSetBorderDashed() { + cellStyle.setBorderTop(CellStyle.BORDER_DASHED); + assertEquals(CellStyle.BORDER_DASHED, cellStyle.getBorderTop()); + int borderId = (int)cellStyle.getCoreXf().getBorderId(); + assertTrue(borderId > 0); + //check changes in the underlying xml bean + CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder(); + assertEquals(STBorderStyle.DASHED, ctBorder.getTop().getStyle()); + } + + public void testGetSetBorderDashDot() { + cellStyle.setBorderTop(CellStyle.BORDER_DASH_DOT); + assertEquals(CellStyle.BORDER_DASH_DOT, cellStyle.getBorderTop()); + int borderId = (int)cellStyle.getCoreXf().getBorderId(); + assertTrue(borderId > 0); + //check changes in the underlying xml bean + CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder(); + assertEquals(STBorderStyle.DASH_DOT, ctBorder.getTop().getStyle()); + } + + public void testGetSetBorderDashDotDot() { + cellStyle.setBorderTop(CellStyle.BORDER_DASH_DOT_DOT); + assertEquals(CellStyle.BORDER_DASH_DOT_DOT, cellStyle.getBorderTop()); + int borderId = (int)cellStyle.getCoreXf().getBorderId(); + assertTrue(borderId > 0); + //check changes in the underlying xml bean + CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder(); + assertEquals(STBorderStyle.DASH_DOT_DOT, ctBorder.getTop().getStyle()); + } + + public void testGetSetBorderMediumDashDot() { + cellStyle.setBorderTop(CellStyle.BORDER_MEDIUM_DASH_DOT); + assertEquals(CellStyle.BORDER_MEDIUM_DASH_DOT, cellStyle.getBorderTop()); + int borderId = (int)cellStyle.getCoreXf().getBorderId(); + assertTrue(borderId > 0); + //check changes in the underlying xml bean + CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder(); + assertEquals(STBorderStyle.MEDIUM_DASH_DOT, ctBorder.getTop().getStyle()); + } + + public void testGetSetBorderMediumDashDotDot() { + cellStyle.setBorderTop(CellStyle.BORDER_MEDIUM_DASH_DOT_DOT); + assertEquals(CellStyle.BORDER_MEDIUM_DASH_DOT_DOT, cellStyle.getBorderTop()); + int borderId = (int)cellStyle.getCoreXf().getBorderId(); + assertTrue(borderId > 0); + //check changes in the underlying xml bean + CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder(); + assertEquals(STBorderStyle.MEDIUM_DASH_DOT_DOT, ctBorder.getTop().getStyle()); + } + + public void testGetSetBorderMediumDashed() { + cellStyle.setBorderTop(CellStyle.BORDER_MEDIUM_DASHED); + assertEquals(CellStyle.BORDER_MEDIUM_DASHED, cellStyle.getBorderTop()); + int borderId = (int)cellStyle.getCoreXf().getBorderId(); + assertTrue(borderId > 0); + //check changes in the underlying xml bean + CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder(); + assertEquals(STBorderStyle.MEDIUM_DASHED, ctBorder.getTop().getStyle()); + } + + public void testGetSetBorderSlantDashDot() { + cellStyle.setBorderTop(CellStyle.BORDER_SLANTED_DASH_DOT); + assertEquals(CellStyle.BORDER_SLANTED_DASH_DOT, cellStyle.getBorderTop()); + int borderId = (int)cellStyle.getCoreXf().getBorderId(); + assertTrue(borderId > 0); + //check changes in the underlying xml bean + CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder(); + assertEquals(STBorderStyle.SLANT_DASH_DOT, ctBorder.getTop().getStyle()); + } + + public void testGetSetBorderDouble() { + cellStyle.setBorderTop(CellStyle.BORDER_DOUBLE); + assertEquals(CellStyle.BORDER_DOUBLE, cellStyle.getBorderTop()); + int borderId = (int)cellStyle.getCoreXf().getBorderId(); + assertTrue(borderId > 0); + //check changes in the underlying xml bean + CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder(); + assertEquals(STBorderStyle.DOUBLE, ctBorder.getTop().getStyle()); + } + public void testGetSetBottomBorderColor() { //defaults assertEquals(IndexedColors.BLACK.getIndex(), cellStyle.getBottomBorderColor()); diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java b/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java index baaad8c42..2457032a6 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java @@ -17,16 +17,18 @@ package org.apache.poi.hssf.usermodel; -import junit.framework.TestCase; -import org.apache.poi.hssf.HSSFTestDataSamples; -import org.apache.poi.util.TempFile; - import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.util.Calendar; import java.util.Date; +import junit.framework.TestCase; + +import org.apache.poi.hssf.HSSFTestDataSamples; +import org.apache.poi.ss.usermodel.CellStyle; +import org.apache.poi.util.TempFile; + /** * Class to test cell styling functionality * @@ -331,5 +333,47 @@ public final class TestCellStyle extends TestCase { c4.setCellStyle(cs2); assertEquals("style1", c4.getCellStyle().getParentStyle().getUserStyleName()); } + + public void testGetSetBorderHair() { + HSSFWorkbook wb = openSample("55341_CellStyleBorder.xls"); + HSSFSheet s = wb.getSheetAt(0); + HSSFCellStyle cs; + + cs = s.getRow(0).getCell(0).getCellStyle(); + assertEquals(CellStyle.BORDER_HAIR, cs.getBorderRight()); + + cs = s.getRow(1).getCell(1).getCellStyle(); + assertEquals(CellStyle.BORDER_DOTTED, cs.getBorderRight()); + + cs = s.getRow(2).getCell(2).getCellStyle(); + assertEquals(CellStyle.BORDER_DASH_DOT_DOT, cs.getBorderRight()); + + cs = s.getRow(3).getCell(3).getCellStyle(); + assertEquals(CellStyle.BORDER_DASHED, cs.getBorderRight()); + + cs = s.getRow(4).getCell(4).getCellStyle(); + assertEquals(CellStyle.BORDER_THIN, cs.getBorderRight()); + + cs = s.getRow(5).getCell(5).getCellStyle(); + assertEquals(CellStyle.BORDER_MEDIUM_DASH_DOT_DOT, cs.getBorderRight()); + + cs = s.getRow(6).getCell(6).getCellStyle(); + assertEquals(CellStyle.BORDER_SLANTED_DASH_DOT, cs.getBorderRight()); + + cs = s.getRow(7).getCell(7).getCellStyle(); + assertEquals(CellStyle.BORDER_MEDIUM_DASH_DOT, cs.getBorderRight()); + + cs = s.getRow(8).getCell(8).getCellStyle(); + assertEquals(CellStyle.BORDER_MEDIUM_DASHED, cs.getBorderRight()); + + cs = s.getRow(9).getCell(9).getCellStyle(); + assertEquals(CellStyle.BORDER_MEDIUM, cs.getBorderRight()); + + cs = s.getRow(10).getCell(10).getCellStyle(); + assertEquals(CellStyle.BORDER_THICK, cs.getBorderRight()); + + cs = s.getRow(11).getCell(11).getCellStyle(); + assertEquals(CellStyle.BORDER_DOUBLE, cs.getBorderRight()); + } } diff --git a/test-data/spreadsheet/55341_CellStyleBorder.xls b/test-data/spreadsheet/55341_CellStyleBorder.xls new file mode 100644 index 000000000..6de09bc32 Binary files /dev/null and b/test-data/spreadsheet/55341_CellStyleBorder.xls differ