From 46bbc6add4709fa2bab66b7916246e0fa88136ff Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Sun, 18 Jul 2010 18:00:36 +0000 Subject: [PATCH] Fix bug #49524 - Support for setting cell text to be vertically rotated, via style.setRotation(0xff) git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@965267 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/status.xml | 2 + .../poi/hssf/usermodel/HSSFCellStyle.java | 23 ++++++--- .../apache/poi/hssf/usermodel/TestBugs.java | 44 +++++++++++++++++- test-data/spreadsheet/49524.xls | Bin 0 -> 13824 bytes 4 files changed, 61 insertions(+), 8 deletions(-) create mode 100644 test-data/spreadsheet/49524.xls 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 0000000000000000000000000000000000000000..ca9dde2d78f1eb06729d947ee794cfaee2ef7705 GIT binary patch literal 13824 zcmeHOU1(fI6#njJH`z34yGhz=Y8!4hmge77&=yOZSghznF*ZmGMq;|%Wwuq{Z}2Dfok6eGp0B1Syt675kJH-$hZd(sup6bN4pckd!DW8s=QioS8E} zXXd+eXXkG(eOots?$eFeuz>cU0=J9RsGO(w=x+?e2{67`R4|nH(odD6{}BS!alXjP z7^WI8R?SS)TLD}{1fN7_=mOWt19%ZtKq{3P8Xtbh|5s?Q)nUj}9j4jwcGKtK47F?6 z2c@kyx53qPCAmmb*3bYQ+ikzPyprnyOT*UMk#bVHLFvaU>U}T2NXk=?=8vL10i-Y4gLHm4X8;rWk15 zRZ=87ldSh(OYb19bfJ|Gv(C@g=FiX6=9lH@K?fcwHx{&@+@4i!p2?n`IinAwo$qkY zXqf+w-7vG6p36Clb?OWFt>~K!oM~TrbraM78b;k+uYS8&`la+Lb+Pm-S?|GD^GX!r z*&g8V`$B!|68erM^leM%s~6SF8tYR82g!h@{nL>s5`~JQWL=@sWPKrOvY}9A5(SuC zSBMp#w-M$9$F1*TDx(tpnRGh8{Uo9++rx|(C-a;8%EQgl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