diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 18ae27fb9..29cb7a2b6 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,8 @@ + 49524 - Support for setting cell text to be vertically rotated, via style.setRotation(0xff) + 49609 - Case insensitive matching of OOXML part names 49581 - Ability to add, modify and remove series from HSSF Charts 49185 - Support for HSSFNames where the comment is stored in a NameCommentRecord 49599 - Correct writing of NoteRecord author text when switching between ASCII and Unicode diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java b/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java index 72ba1749e..fbf2a868c 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java @@ -283,31 +283,40 @@ public final class HSSFCellStyle implements CellStyle { /** * set the degree of rotation for the text in the cell - * @param rotation degrees (between -90 and 90 degrees) + * @param rotation degrees (between -90 and 90 degrees, of 0xff for vertical) */ public void setRotation(short rotation) { - if ((rotation < 0)&&(rotation >= -90)) { + if (rotation == 0xff) { + // Special cases for vertically aligned text + } + else if ((rotation < 0)&&(rotation >= -90)) { //Take care of the funny 4th quadrant issue //The 4th quadrant (-1 to -90) is stored as (91 to 180) rotation = (short)(90 - rotation); } - else if ((rotation < -90) ||(rotation > 90)) + else if ((rotation < -90) ||(rotation > 90)) { //Do not allow an incorrect rotation to be set - throw new IllegalArgumentException("The rotation must be between -90 and 90 degrees"); - _format.setRotation(rotation); + throw new IllegalArgumentException("The rotation must be between -90 and 90 degrees, or 0xff"); + } + _format.setRotation(rotation); } /** * get the degree of rotation for the text in the cell - * @return rotation degrees (between -90 and 90 degrees) + * @return rotation degrees (between -90 and 90 degrees, or 0xff for vertical) */ public short getRotation() { short rotation = _format.getRotation(); - if (rotation > 90) + if (rotation == 0xff) { + // Vertical aligned special case + return rotation; + } + if (rotation > 90) { //This is actually the 4th quadrant rotation = (short)(90-rotation); + } return rotation; } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java index 706ccbfa0..4afa0a7cb 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java @@ -42,7 +42,12 @@ import org.apache.poi.hssf.record.common.UnicodeString; import org.apache.poi.hssf.record.formula.Area3DPtg; import org.apache.poi.hssf.record.formula.DeletedArea3DPtg; import org.apache.poi.hssf.record.formula.Ptg; -import org.apache.poi.ss.usermodel.*; +import org.apache.poi.ss.usermodel.BaseTestBugzillaIssues; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.CellStyle; +import org.apache.poi.ss.usermodel.Name; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.util.TempFile; /** @@ -1761,4 +1766,41 @@ if(1==2) { name = wb.getName("ChangedName"); assertEquals("Changed Comment", name.getComment()); } + + /** + * Vertically aligned text + */ + public void test49524() throws Exception { + HSSFWorkbook wb = openSample("49524.xls"); + Sheet s = wb.getSheetAt(0); + Row r = s.getRow(0); + Cell rotated = r.getCell(0); + Cell normal = r.getCell(1); + + // Check the current ones + assertEquals(0, normal.getCellStyle().getRotation()); + assertEquals(0xff, rotated.getCellStyle().getRotation()); + + // Add a new style, also rotated + CellStyle cs = wb.createCellStyle(); + cs.setRotation((short)0xff); + Cell nc = r.createCell(2); + nc.setCellValue("New Rotated Text"); + nc.setCellStyle(cs); + assertEquals(0xff, nc.getCellStyle().getRotation()); + + // Write out and read back + wb = writeOutAndReadBack(wb); + + // Re-check + s = wb.getSheetAt(0); + r = s.getRow(0); + rotated = r.getCell(0); + normal = r.getCell(1); + nc = r.getCell(2); + + assertEquals(0, normal.getCellStyle().getRotation()); + assertEquals(0xff, rotated.getCellStyle().getRotation()); + assertEquals(0xff, nc.getCellStyle().getRotation()); + } } diff --git a/test-data/spreadsheet/49524.xls b/test-data/spreadsheet/49524.xls new file mode 100644 index 000000000..ca9dde2d7 Binary files /dev/null and b/test-data/spreadsheet/49524.xls differ