You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2013/11/07 23:39:12 UTC
svn commit: r1539850 - in /poi/trunk:
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java
src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java
test-data/spreadsheet/ShrinkToFit.xls test-data/spreadsheet/ShrinkToFit.xlsx
Author: nick
Date: Thu Nov 7 22:39:11 2013
New Revision: 1539850
URL: http://svn.apache.org/r1539850
Log:
Unit tests for Shrink To Fit cell style support (#55661)
Added:
poi/trunk/test-data/spreadsheet/ShrinkToFit.xls (with props)
poi/trunk/test-data/spreadsheet/ShrinkToFit.xlsx (with props)
Modified:
poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java
poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java?rev=1539850&r1=1539849&r2=1539850&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java Thu Nov 7 22:39:11 2013
@@ -24,6 +24,8 @@ import org.apache.poi.hssf.usermodel.HSS
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.IndexedColors;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.xssf.model.StylesTable;
@@ -40,9 +42,7 @@ import org.openxmlformats.schemas.spread
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPatternType;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STVerticalAlignment;
-
public class TestXSSFCellStyle extends TestCase {
-
private StylesTable stylesTable;
private CTBorder ctBorderA;
private CTFill ctFill;
@@ -850,4 +850,33 @@ public class TestXSSFCellStyle extends T
assertNull(style.getStyleXf());
}
+ public void testShrinkToFit() {
+ // Existing file
+ XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("ShrinkToFit.xlsx");
+ Sheet s = wb.getSheetAt(0);
+ Row r = s.getRow(0);
+ CellStyle cs = r.getCell(0).getCellStyle();
+
+ assertEquals(true, cs.getShrinkToFit());
+
+ // New file
+ XSSFWorkbook wbOrig = new XSSFWorkbook();
+ s = wbOrig.createSheet();
+ r = s.createRow(0);
+
+ cs = wbOrig.createCellStyle();
+ cs.setShrinkToFit(false);
+ r.createCell(0).setCellStyle(cs);
+
+ cs = wbOrig.createCellStyle();
+ cs.setShrinkToFit(true);
+ r.createCell(1).setCellStyle(cs);
+
+ // Write out, read, and check
+ wb = XSSFTestDataSamples.writeOutAndReadBack(wbOrig);
+ s = wb.getSheetAt(0);
+ r = s.getRow(0);
+ assertEquals(false, r.getCell(0).getCellStyle().getShrinkToFit());
+ assertEquals(true, r.getCell(1).getCellStyle().getShrinkToFit());
+ }
}
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java?rev=1539850&r1=1539849&r2=1539850&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java Thu Nov 7 22:39:11 2013
@@ -333,47 +333,76 @@ public final class TestCellStyle extends
c4.setCellStyle(cs2);
assertEquals("style1", c4.getCellStyle().getParentStyle().getUserStyleName());
}
-
- public void testGetSetBorderHair() {
- HSSFWorkbook wb = openSample("55341_CellStyleBorder.xls");
- HSSFSheet s = wb.getSheetAt(0);
- HSSFCellStyle cs;
-
- cs = s.getRow(0).getCell(0).getCellStyle();
- assertEquals(CellStyle.BORDER_HAIR, cs.getBorderRight());
-
- cs = s.getRow(1).getCell(1).getCellStyle();
- assertEquals(CellStyle.BORDER_DOTTED, cs.getBorderRight());
-
- cs = s.getRow(2).getCell(2).getCellStyle();
- assertEquals(CellStyle.BORDER_DASH_DOT_DOT, cs.getBorderRight());
-
- cs = s.getRow(3).getCell(3).getCellStyle();
- assertEquals(CellStyle.BORDER_DASHED, cs.getBorderRight());
-
- cs = s.getRow(4).getCell(4).getCellStyle();
- assertEquals(CellStyle.BORDER_THIN, cs.getBorderRight());
-
- cs = s.getRow(5).getCell(5).getCellStyle();
- assertEquals(CellStyle.BORDER_MEDIUM_DASH_DOT_DOT, cs.getBorderRight());
-
- cs = s.getRow(6).getCell(6).getCellStyle();
- assertEquals(CellStyle.BORDER_SLANTED_DASH_DOT, cs.getBorderRight());
-
- cs = s.getRow(7).getCell(7).getCellStyle();
- assertEquals(CellStyle.BORDER_MEDIUM_DASH_DOT, cs.getBorderRight());
-
- cs = s.getRow(8).getCell(8).getCellStyle();
- assertEquals(CellStyle.BORDER_MEDIUM_DASHED, cs.getBorderRight());
-
- cs = s.getRow(9).getCell(9).getCellStyle();
- assertEquals(CellStyle.BORDER_MEDIUM, cs.getBorderRight());
-
- cs = s.getRow(10).getCell(10).getCellStyle();
- assertEquals(CellStyle.BORDER_THICK, cs.getBorderRight());
-
- cs = s.getRow(11).getCell(11).getCellStyle();
- assertEquals(CellStyle.BORDER_DOUBLE, cs.getBorderRight());
- }
+
+ public void testGetSetBorderHair() {
+ HSSFWorkbook wb = openSample("55341_CellStyleBorder.xls");
+ HSSFSheet s = wb.getSheetAt(0);
+ HSSFCellStyle cs;
+ cs = s.getRow(0).getCell(0).getCellStyle();
+ assertEquals(CellStyle.BORDER_HAIR, cs.getBorderRight());
+
+ cs = s.getRow(1).getCell(1).getCellStyle();
+ assertEquals(CellStyle.BORDER_DOTTED, cs.getBorderRight());
+
+ cs = s.getRow(2).getCell(2).getCellStyle();
+ assertEquals(CellStyle.BORDER_DASH_DOT_DOT, cs.getBorderRight());
+
+ cs = s.getRow(3).getCell(3).getCellStyle();
+ assertEquals(CellStyle.BORDER_DASHED, cs.getBorderRight());
+
+ cs = s.getRow(4).getCell(4).getCellStyle();
+ assertEquals(CellStyle.BORDER_THIN, cs.getBorderRight());
+
+ cs = s.getRow(5).getCell(5).getCellStyle();
+ assertEquals(CellStyle.BORDER_MEDIUM_DASH_DOT_DOT, cs.getBorderRight());
+
+ cs = s.getRow(6).getCell(6).getCellStyle();
+ assertEquals(CellStyle.BORDER_SLANTED_DASH_DOT, cs.getBorderRight());
+
+ cs = s.getRow(7).getCell(7).getCellStyle();
+ assertEquals(CellStyle.BORDER_MEDIUM_DASH_DOT, cs.getBorderRight());
+
+ cs = s.getRow(8).getCell(8).getCellStyle();
+ assertEquals(CellStyle.BORDER_MEDIUM_DASHED, cs.getBorderRight());
+
+ cs = s.getRow(9).getCell(9).getCellStyle();
+ assertEquals(CellStyle.BORDER_MEDIUM, cs.getBorderRight());
+
+ cs = s.getRow(10).getCell(10).getCellStyle();
+ assertEquals(CellStyle.BORDER_THICK, cs.getBorderRight());
+
+ cs = s.getRow(11).getCell(11).getCellStyle();
+ assertEquals(CellStyle.BORDER_DOUBLE, cs.getBorderRight());
+ }
+
+ public void testShrinkToFit() {
+ // Existing file
+ HSSFWorkbook wb = openSample("ShrinkToFit.xls");
+ HSSFSheet s = wb.getSheetAt(0);
+ HSSFRow r = s.getRow(0);
+ HSSFCellStyle cs = r.getCell(0).getCellStyle();
+
+ assertEquals(true, cs.getShrinkToFit());
+
+ // New file
+ HSSFWorkbook wbOrig = new HSSFWorkbook();
+ s = wbOrig.createSheet();
+ r = s.createRow(0);
+
+ cs = wbOrig.createCellStyle();
+ cs.setShrinkToFit(false);
+ r.createCell(0).setCellStyle(cs);
+
+ cs = wbOrig.createCellStyle();
+ cs.setShrinkToFit(true);
+ r.createCell(1).setCellStyle(cs);
+
+ // Write out, read, and check
+ wb = HSSFTestDataSamples.writeOutAndReadBack(wbOrig);
+ s = wb.getSheetAt(0);
+ r = s.getRow(0);
+ assertEquals(false, r.getCell(0).getCellStyle().getShrinkToFit());
+ assertEquals(true, r.getCell(1).getCellStyle().getShrinkToFit());
+ }
}
Added: poi/trunk/test-data/spreadsheet/ShrinkToFit.xls
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/ShrinkToFit.xls?rev=1539850&view=auto
==============================================================================
Binary file - no diff available.
Propchange: poi/trunk/test-data/spreadsheet/ShrinkToFit.xls
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: poi/trunk/test-data/spreadsheet/ShrinkToFit.xlsx
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/ShrinkToFit.xlsx?rev=1539850&view=auto
==============================================================================
Binary file - no diff available.
Propchange: poi/trunk/test-data/spreadsheet/ShrinkToFit.xlsx
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org