Author: nick
Date: Thu Nov 7 22:28:06 2013
New Revision: 1539848
URL: http://svn.apache.org/r1539848
Log:
Start on HSSF/XSSF Shrink To Fit support, see bug #55661
Modified:
poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java
poi/trunk/src/java/org/apache/poi/ss/usermodel/CellStyle.java
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellAlignment.java
Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java?rev=1539848&r1=1539847&r2=1539848&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java
(original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java Thu Nov
7 22:28:06 2013
@@ -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;
@@ -808,6 +807,21 @@ public final class HSSFCellStyle impleme
}
/**
+ * 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.
* This is normally called when trying to assign a style to a
Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/CellStyle.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/CellStyle.java?rev=1539848&r1=1539847&r2=1539848&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/CellStyle.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/CellStyle.java Thu Nov 7
22:28:06 2013
@@ -113,7 +113,7 @@ public interface CellStyle {
* dot border
*/
- public final static short BORDER_HAIR = 0x7;
+ 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 = 0x4;
+ public final static short BORDER_DOTTED = 0x4;
/**
* Medium dashed border
@@ -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();
+}
\ No newline at end of file
Modified:
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java?rev=1539848&r1=1539847&r2=1539848&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java
(original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java
Thu Nov 7 22:28:06 2013
@@ -30,8 +30,8 @@ import org.apache.poi.xssf.model.StylesT
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 Ce
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 Ce
break;
}
}
+
+ public void setShrinkToFit(boolean shrinkToFit) {
+ getCellAlignment().setShrinkToFit(shrinkToFit);
+ }
+
private int getFontId() {
if (_cellXf.isSetFontId()) {
return (int) _cellXf.getFontId();
Modified:
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellAlignment.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellAlignment.java?rev=1539848&r1=1539847&r2=1539848&view=diff
==============================================================================
---
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellAlignment.java
(original)
+++
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellAlignment.java
Thu Nov 7 22:28:06 2013
@@ -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
*/
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]