Start on HSSF/XSSF Shrink To Fit support, see bug #55661

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1539848 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2013-11-07 22:28:06 +00:00
parent 3e91be2c5a
commit 9332cdcc18
4 changed files with 53 additions and 10 deletions

View File

@ -18,7 +18,6 @@
package org.apache.poi.hssf.usermodel;
import java.util.Arrays;
import java.util.List;
import org.apache.poi.hssf.model.InternalWorkbook;
@ -807,6 +806,21 @@ public final class HSSFCellStyle implements CellStyle {
sr.setName(styleName);
}
/**
* Controls if the Cell should be auto-sized
* to shrink to fit if the text is too long
*/
public void setShrinkToFit(boolean shrinkToFit) {
_format.setShrinkToFit(shrinkToFit);
}
/**
* Should the Cell be auto-sized by Excel to shrink
* it to fit if this text is too long?
*/
public boolean getShrinkToFit() {
return _format.getShrinkToFit();
}
/**
* Verifies that this style belongs to the supplied Workbook.
* Will throw an exception if it belongs to a different one.

View File

@ -701,4 +701,16 @@ public interface CellStyle {
* XSSFCellStyle)
*/
public void cloneStyleFrom(CellStyle source);
/**
* Controls if the Cell should be auto-sized
* to shrink to fit if the text is too long
*/
public void setShrinkToFit(boolean shrinkToFit);
/**
* Should the Cell be auto-sized by Excel to shrink
* it to fit if this text is too long?
*/
public boolean getShrinkToFit();
}

View File

@ -30,8 +30,8 @@ import org.apache.poi.xssf.model.StylesTable;
import org.apache.poi.xssf.model.ThemesTable;
import org.apache.poi.xssf.usermodel.extensions.XSSFCellAlignment;
import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder;
import org.apache.poi.xssf.usermodel.extensions.XSSFCellFill;
import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder.BorderSide;
import org.apache.poi.xssf.usermodel.extensions.XSSFCellFill;
import org.apache.xmlbeans.XmlException;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorderPr;
@ -668,6 +668,11 @@ public class XSSFCellStyle implements CellStyle {
return (short)(align == null ? 0 : align.getTextRotation());
}
public boolean getShrinkToFit() {
CTCellAlignment align = _cellXf.getAlignment();
return align != null && align.getShrinkToFit();
}
/**
* Get the color to use for the top border
*
@ -1390,6 +1395,11 @@ public class XSSFCellStyle implements CellStyle {
break;
}
}
public void setShrinkToFit(boolean shrinkToFit) {
getCellAlignment().setShrinkToFit(shrinkToFit);
}
private int getFontId() {
if (_cellXf.isSetFontId()) {
return (int) _cellXf.getFontId();

View File

@ -16,19 +16,18 @@
==================================================================== */
package org.apache.poi.xssf.usermodel.extensions;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellAlignment;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STHorizontalAlignment;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STVerticalAlignment;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.util.Internal;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellAlignment;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STHorizontalAlignment;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STVerticalAlignment;
/**
* Cell settings avaiable in the Format/Alignment tab
* Cell settings available in the Format/Alignment tab
*/
public class XSSFCellAlignment {
private CTCellAlignment cellAlignement;
/**
@ -158,6 +157,14 @@ public class XSSFCellAlignment {
cellAlignement.setWrapText(wrapped);
}
public boolean getShrinkToFit() {
return cellAlignement.getShrinkToFit();
}
public void setShrinkToFit(boolean shrink) {
cellAlignement.setShrinkToFit(shrink);
}
/**
* Access to low-level data
*/