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
This commit is contained in:
parent
8047e7e84d
commit
46bbc6add4
@ -34,6 +34,8 @@
|
||||
|
||||
<changes>
|
||||
<release version="3.7-beta2" date="2010-??-??">
|
||||
<action dev="POI-DEVELOPERS" type="add">49524 - Support for setting cell text to be vertically rotated, via style.setRotation(0xff)</action>
|
||||
<action dev="POI-DEVELOPERS" type="fix">49609 - Case insensitive matching of OOXML part names</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">49581 - Ability to add, modify and remove series from HSSF Charts</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">49185 - Support for HSSFNames where the comment is stored in a NameCommentRecord</action>
|
||||
<action dev="POI-DEVELOPERS" type="fix">49599 - Correct writing of NoteRecord author text when switching between ASCII and Unicode</action>
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
BIN
test-data/spreadsheet/49524.xls
Normal file
BIN
test-data/spreadsheet/49524.xls
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user