From: Dominik Stadler Date: Sun, 29 Sep 2013 20:23:20 +0000 (+0000) Subject: Apply patch from bug 55341 X-Git-Tag: REL_3_10_FINAL~105 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=927dc0ce1d49f221752cea6e997f1b59be4dd125;p=poi.git Apply patch from bug 55341 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1527397 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/poi/ss/usermodel/CellStyle.java b/src/java/org/apache/poi/ss/usermodel/CellStyle.java index 7b62c1ee80..3eed0604bd 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 11b724f4ab..303cba95ee 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 baaad8c425..2457032a66 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 0000000000..6de09bc32d Binary files /dev/null and b/test-data/spreadsheet/55341_CellStyleBorder.xls differ