]> source.dussan.org Git - poi.git/commitdiff
refactored cell align accessors in xssf and added samples based on the quick guide
authorYegor Kozlov <yegor@apache.org>
Mon, 15 Sep 2008 10:39:37 +0000 (10:39 +0000)
committerYegor Kozlov <yegor@apache.org>
Mon, 15 Sep 2008 10:39:37 +0000 (10:39 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@695411 13f79535-47bb-0310-9956-ffa450edef68

12 files changed:
src/examples/src/org/apache/poi/xssf/usermodel/examples/AligningCells.java [new file with mode: 0755]
src/examples/src/org/apache/poi/xssf/usermodel/examples/CreateNewSpreadsheet.java
src/examples/src/org/apache/poi/xssf/usermodel/examples/FillsAndColors.java [new file with mode: 0755]
src/examples/src/org/apache/poi/xssf/usermodel/examples/IterateCells.java [new file with mode: 0755]
src/examples/src/org/apache/poi/xssf/usermodel/examples/MergingCells.java [new file with mode: 0755]
src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkingWithBorders.java [new file with mode: 0755]
src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkingWithFonts.java [new file with mode: 0755]
src/ooxml/java/org/apache/poi/xssf/usermodel/HorizontalAlignment.java [new file with mode: 0755]
src/ooxml/java/org/apache/poi/xssf/usermodel/VerticalAlignment.java [new file with mode: 0755]
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java
src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellAlignment.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java

diff --git a/src/examples/src/org/apache/poi/xssf/usermodel/examples/AligningCells.java b/src/examples/src/org/apache/poi/xssf/usermodel/examples/AligningCells.java
new file mode 100755 (executable)
index 0000000..3237f5a
--- /dev/null
@@ -0,0 +1,71 @@
+/* ====================================================================\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to You under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+==================================================================== */\r
+package org.apache.poi.xssf.usermodel.examples;\r
+\r
+import org.apache.poi.xssf.usermodel.*;\r
+import org.apache.poi.ss.usermodel.*;\r
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.STHorizontalAlignment;\r
+\r
+import java.io.FileOutputStream;\r
+\r
+/**\r
+ *  Demonstrates various alignment options\r
+ */\r
+public class AligningCells {\r
+\r
+    public static void main(String[] args)\r
+                throws Exception\r
+        {\r
+            Workbook wb = new XSSFWorkbook();\r
+\r
+            Sheet sheet = wb.createSheet("new sheet");\r
+            Row row = sheet.createRow((short) 2);\r
+\r
+            createCell(wb, row, (short) 0, XSSFCellStyle.ALIGN_CENTER, XSSFCellStyle.VERTICAL_BOTTOM);\r
+            createCell(wb, row, (short) 1, XSSFCellStyle.ALIGN_CENTER_SELECTION, XSSFCellStyle.VERTICAL_BOTTOM);\r
+            createCell(wb, row, (short) 2, XSSFCellStyle.ALIGN_FILL, XSSFCellStyle.VERTICAL_CENTER);\r
+            createCell(wb, row, (short) 3, XSSFCellStyle.ALIGN_GENERAL, XSSFCellStyle.VERTICAL_CENTER);\r
+            createCell(wb, row, (short) 4, XSSFCellStyle.ALIGN_JUSTIFY, XSSFCellStyle.VERTICAL_JUSTIFY);\r
+            createCell(wb, row, (short) 5, XSSFCellStyle.ALIGN_LEFT, XSSFCellStyle.VERTICAL_TOP);\r
+            createCell(wb, row, (short) 6, XSSFCellStyle.ALIGN_RIGHT, XSSFCellStyle.VERTICAL_TOP);\r
+\r
+            // Write the output to a file\r
+            FileOutputStream fileOut = new FileOutputStream("aligning.xlsx");\r
+            wb.write(fileOut);\r
+            fileOut.close();\r
+\r
+        }\r
+\r
+        /**\r
+         * Creates a cell and aligns it a certain way.\r
+         *\r
+         * @param wb        the workbook\r
+         * @param row       the row to create the cell in\r
+         * @param column    the column number to create the cell in\r
+         * @param halign    the horizontal alignment for the cell.\r
+         */\r
+        private static void createCell(Workbook wb, Row row, short column, short halign, short valign)\r
+        {\r
+            Cell cell = row.createCell(column);\r
+            cell.setCellValue(new XSSFRichTextString("Align It"));\r
+            CellStyle cellStyle = wb.createCellStyle();\r
+            cellStyle.setAlignment(halign);\r
+            cellStyle.setVerticalAlignment(valign);\r
+            cell.setCellStyle(cellStyle);\r
+        }\r
+\r
+}\r
index f653d560f2b0544c1a87ff123fb890c45cfc9079..afef75271593b4dc7c4bf2660c1d80ad3f51b8e9 100644 (file)
@@ -1,3 +1,19 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
 package org.apache.poi.xssf.usermodel.examples;
 
 import java.io.FileOutputStream;
@@ -48,7 +64,7 @@ public class CreateNewSpreadsheet {
                s1.getRow(1).getCell(1).setCellValue(createHelper.createRichTextString("Link to POI"));
                
                // Save
-               FileOutputStream fout = new FileOutputStream("/tmp/NewFile.xlsx");
+               FileOutputStream fout = new FileOutputStream("NewFile.xlsx");
                wb.write(fout);
                fout.close();
                System.out.println("Done");
diff --git a/src/examples/src/org/apache/poi/xssf/usermodel/examples/FillsAndColors.java b/src/examples/src/org/apache/poi/xssf/usermodel/examples/FillsAndColors.java
new file mode 100755 (executable)
index 0000000..11e3af9
--- /dev/null
@@ -0,0 +1,59 @@
+/* ====================================================================\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to You under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+==================================================================== */\r
+package org.apache.poi.xssf.usermodel.examples;\r
+\r
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;\r
+import org.apache.poi.xssf.usermodel.XSSFRichTextString;\r
+import org.apache.poi.ss.usermodel.*;\r
+import org.apache.poi.hssf.util.HSSFColor;\r
+\r
+import java.io.FileOutputStream;\r
+\r
+/**\r
+ * Fills and Colors\r
+ */\r
+public class FillsAndColors {\r
+    public static void main(String[] args) throws Exception {\r
+        Workbook wb = new XSSFWorkbook();\r
+            Sheet sheet = wb.createSheet("new sheet");\r
+\r
+            // Create a row and put some cells in it. Rows are 0 based.\r
+            Row row = sheet.createRow((short) 1);\r
+\r
+            // Aqua background\r
+            CellStyle style = wb.createCellStyle();\r
+            style.setFillBackgroundColor(HSSFColor.AQUA.index);\r
+            style.setFillPattern(CellStyle.BIG_SPOTS);\r
+            Cell cell = row.createCell((short) 1);\r
+            cell.setCellValue(new XSSFRichTextString("X"));\r
+            cell.setCellStyle(style);\r
+\r
+            // Orange "foreground", foreground being the fill foreground not the font color.\r
+            style = wb.createCellStyle();\r
+            style.setFillForegroundColor(HSSFColor.ORANGE.index);\r
+            style.setFillPattern(CellStyle.SOLID_FOREGROUND);\r
+            cell = row.createCell((short) 2);\r
+            cell.setCellValue(new XSSFRichTextString("X"));\r
+            cell.setCellStyle(style);\r
+\r
+            // Write the output to a file\r
+            FileOutputStream fileOut = new FileOutputStream("fill_colors.xlsx");\r
+            wb.write(fileOut);\r
+            fileOut.close();\r
+\r
+    }\r
+}\r
diff --git a/src/examples/src/org/apache/poi/xssf/usermodel/examples/IterateCells.java b/src/examples/src/org/apache/poi/xssf/usermodel/examples/IterateCells.java
new file mode 100755 (executable)
index 0000000..fc41e27
--- /dev/null
@@ -0,0 +1,44 @@
+/* ====================================================================\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to You under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+==================================================================== */\r
+package org.apache.poi.xssf.usermodel.examples;\r
+\r
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;\r
+import org.apache.poi.ss.usermodel.Workbook;\r
+import org.apache.poi.ss.usermodel.Sheet;\r
+import org.apache.poi.ss.usermodel.Cell;\r
+import org.apache.poi.ss.usermodel.Row;\r
+\r
+/**\r
+ *  Iterate over rows and cells\r
+ */\r
+public class IterateCells {\r
+\r
+    public static void main(String[] args) throws Exception {\r
+        Workbook wb = new XSSFWorkbook(args[0]);\r
+        for (int i = 0; i < wb.getNumberOfSheets(); i++) {\r
+            Sheet sheet = wb.getSheetAt(i);\r
+            System.out.println(wb.getSheetName(i));\r
+            for (Row row : sheet) {\r
+                System.out.println("rownum: " + row.getRowNum());\r
+                for (Cell cell : row) {\r
+                    System.out.println(cell.toString());\r
+                }\r
+            }\r
+        }\r
+\r
+    }\r
+}\r
diff --git a/src/examples/src/org/apache/poi/xssf/usermodel/examples/MergingCells.java b/src/examples/src/org/apache/poi/xssf/usermodel/examples/MergingCells.java
new file mode 100755 (executable)
index 0000000..e103152
--- /dev/null
@@ -0,0 +1,49 @@
+/* ====================================================================\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to You under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+==================================================================== */\r
+package org.apache.poi.xssf.usermodel.examples;\r
+\r
+import org.apache.poi.ss.usermodel.Workbook;\r
+import org.apache.poi.ss.usermodel.Sheet;\r
+import org.apache.poi.ss.usermodel.Row;\r
+import org.apache.poi.ss.usermodel.Cell;\r
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;\r
+import org.apache.poi.xssf.usermodel.XSSFRichTextString;\r
+import org.apache.poi.hssf.util.Region;\r
+\r
+import java.io.FileOutputStream;\r
+\r
+/**\r
+ * Merging cells\r
+ */\r
+public class MergingCells {\r
+    public static void main(String[] args) throws Exception {\r
+        Workbook wb = new XSSFWorkbook();\r
+        Sheet sheet = wb.createSheet("new sheet");\r
+\r
+        Row row = sheet.createRow((short) 1);\r
+        Cell cell = row.createCell((short) 1);\r
+        cell.setCellValue(new XSSFRichTextString("This is a test of merging"));\r
+\r
+        sheet.addMergedRegion(new Region(1,(short)1,1,(short)2));\r
+\r
+        // Write the output to a file\r
+        FileOutputStream fileOut = new FileOutputStream("merging_cells.xlsx");\r
+        wb.write(fileOut);\r
+        fileOut.close();\r
+\r
+    }\r
+}\r
diff --git a/src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkingWithBorders.java b/src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkingWithBorders.java
new file mode 100755 (executable)
index 0000000..f70596f
--- /dev/null
@@ -0,0 +1,58 @@
+/* ====================================================================\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to You under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+==================================================================== */\r
+package org.apache.poi.xssf.usermodel.examples;\r
+\r
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;\r
+import org.apache.poi.xssf.util.IndexedColors;\r
+import org.apache.poi.ss.usermodel.*;\r
+\r
+import java.io.FileOutputStream;\r
+\r
+/**\r
+ * Working with borders\r
+ */\r
+public class WorkingWithBorders {\r
+    public static void main(String[] args) throws Exception {\r
+        Workbook wb = new XSSFWorkbook();\r
+        Sheet sheet = wb.createSheet("new sheet");\r
+\r
+        // Create a row and put some cells in it. Rows are 0 based.\r
+        Row row = sheet.createRow((short) 1);\r
+\r
+        // Create a cell and put a value in it.\r
+        Cell cell = row.createCell((short) 1);\r
+        cell.setCellValue(4);\r
+\r
+        // Style the cell with borders all around.\r
+        CellStyle style = wb.createCellStyle();\r
+        style.setBorderBottom(CellStyle.BORDER_THIN);\r
+        style.setBottomBorderColor((short)IndexedColors.BLACK);\r
+        style.setBorderLeft(CellStyle.BORDER_THIN);\r
+        style.setLeftBorderColor((short)IndexedColors.GREEN);\r
+        style.setBorderRight(CellStyle.BORDER_THIN);\r
+        style.setRightBorderColor((short)IndexedColors.BLUE);\r
+        style.setBorderTop(CellStyle.BORDER_MEDIUM_DASHED);\r
+        style.setTopBorderColor((short)IndexedColors.BLACK);\r
+        cell.setCellStyle(style);\r
+\r
+        // Write the output to a file\r
+        FileOutputStream fileOut = new FileOutputStream("workbook_borders.xlsx");\r
+        wb.write(fileOut);\r
+        fileOut.close();\r
+\r
+    }\r
+}\r
diff --git a/src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkingWithFonts.java b/src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkingWithFonts.java
new file mode 100755 (executable)
index 0000000..e86e56e
--- /dev/null
@@ -0,0 +1,66 @@
+/* ====================================================================\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to You under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+==================================================================== */\r
+package org.apache.poi.xssf.usermodel.examples;\r
+\r
+import org.apache.poi.hssf.usermodel.HSSFFont;\r
+import org.apache.poi.hssf.util.HSSFColor;\r
+import org.apache.poi.ss.usermodel.*;\r
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;\r
+import org.apache.poi.xssf.usermodel.XSSFRichTextString;\r
+import org.apache.poi.xssf.usermodel.extensions.XSSFColor;\r
+import org.apache.poi.xssf.util.IndexedColors;\r
+\r
+import java.io.FileOutputStream;\r
+\r
+/**\r
+ * Working with Fonts\r
+ */\r
+public class WorkingWithFonts {\r
+    public static void main(String[] args) throws Exception {\r
+        Workbook wb = new XSSFWorkbook();\r
+        Sheet sheet = wb.createSheet("new sheet");\r
+\r
+        // Create a row and put some cells in it. Rows are 0 based.\r
+        Row row = sheet.createRow((short) 1);\r
+\r
+        // Create a new font and alter it.\r
+        Font font = wb.createFont();\r
+        font.setFontHeightInPoints((short)24);\r
+        font.setFontName("Courier New");\r
+\r
+        font.setColor((short)IndexedColors.RED);\r
+\r
+        font.setItalic(true);\r
+        font.setStrikeout(true);\r
+\r
+        // Fonts are set into a style so create a new one to use.\r
+        CellStyle style = wb.createCellStyle();\r
+        style.setFont(font);\r
+\r
+        // Create a cell and put a value in it.\r
+        Cell cell = row.createCell((short) 1);\r
+        cell.setCellValue(1974);\r
+        //cell.setCellValue(new XSSFRichTextString("This is a test of fonts"));\r
+        cell.setCellStyle(style);\r
+\r
+        // Write the output to a file\r
+\r
+        FileOutputStream fileOut = new FileOutputStream("fonts.xlsx");\r
+        wb.write(fileOut);\r
+        fileOut.close();\r
+    }\r
+}\r
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/HorizontalAlignment.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/HorizontalAlignment.java
new file mode 100755 (executable)
index 0000000..da2c153
--- /dev/null
@@ -0,0 +1,95 @@
+/* ====================================================================\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to You under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+==================================================================== */\r
+\r
+package org.apache.poi.xssf.usermodel;\r
+\r
+/**\r
+ * The enumeration value indicating horizontal alignment of a cell,\r
+ * i.e., whether it is aligned general, left, right, horizontally centered, filled (replicated),\r
+ * justified, centered across multiple cells, or distributed.\r
+ */\r
+public enum HorizontalAlignment {\r
+    /**\r
+     * The horizontal alignment is general-aligned. Text data is left-aligned.\r
+     * Numbers, dates, and times are rightaligned. Boolean types are centered.\r
+     * Changing the alignment does not change the type of data.\r
+     */\r
+    GENERAL,\r
+\r
+    /**\r
+     * The horizontal alignment is left-aligned, even in Rightto-Left mode.\r
+     * Aligns contents at the left edge of the cell. If an indent amount is specified, the contents of\r
+     * the cell is indented from the left by the specified number of character spaces. The character spaces are\r
+     * based on the default font and font size for the workbook.\r
+     */\r
+    LEFT,\r
+\r
+    /**\r
+     * The horizontal alignment is centered, meaning the text is centered across the cell.\r
+     */\r
+    CENTER,\r
+\r
+    /**\r
+     * The horizontal alignment is right-aligned, meaning that cell contents are aligned at the right edge of the cell,\r
+     * even in Right-to-Left mode.\r
+     */\r
+    RIGHT,\r
+\r
+    /**\r
+     * Indicates that the value of the cell should be filled\r
+     * across the entire width of the cell. If blank cells to the right also have the fill alignment,\r
+     * they are also filled with the value, using a convention similar to centerContinuous.\r
+     * <p>\r
+     * Additional rules:\r
+     * <ol>\r
+     * <li>Only whole values can be appended, not partial values.</li>\r
+     * <li>The column will not be widened to 'best fit' the filled value</li>\r
+     * <li>If appending an additional occurrence of the value exceeds the boundary of the cell\r
+     * left/right edge, don't append the additional occurrence of the value.</li>\r
+     * <li>The display value of the cell is filled, not the underlying raw number.</li>\r
+     * </ol>\r
+     * </p>\r
+     */\r
+    FILL,\r
+\r
+    /**\r
+     * The horizontal alignment is justified (flush left and right).\r
+     * For each line of text, aligns each line of the wrapped text in a cell to the right and left\r
+     * (except the last line). If no single line of text wraps in the cell, then the text is not justified.\r
+     */\r
+    JUSTIFY,\r
+\r
+    /**\r
+     * The horizontal alignment is centered across multiple cells.\r
+     * The information about how many cells to span is expressed in the Sheet Part,\r
+     * in the row of the cell in question. For each cell that is spanned in the alignment,\r
+     * a cell element needs to be written out, with the same style Id which references the centerContinuous alignment.\r
+     */\r
+    CENTER_SELECTION,\r
+\r
+    /**\r
+     * Indicates that each 'word' in each line of text inside the cell is evenly distributed\r
+     * across the width of the cell, with flush right and left margins.\r
+     * <p>\r
+     * When there is also an indent value to apply, both the left and right side of the cell\r
+     * are padded by the indent value.\r
+     * </p>\r
+     * <p> A 'word' is a set of characters with no space character in them. </p>\r
+     * <p> Two lines inside a cell are separated by a carriage return. </p>\r
+     */\r
+    DISTRIBUTED\r
+}\r
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/VerticalAlignment.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/VerticalAlignment.java
new file mode 100755 (executable)
index 0000000..e583336
--- /dev/null
@@ -0,0 +1,69 @@
+/* ====================================================================\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to You under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+==================================================================== */\r
+\r
+package org.apache.poi.xssf.usermodel;\r
+\r
+/**\r
+ * This enumeration value indicates the type of vertical alignment for a cell, i.e.,\r
+ * whether it is aligned top, bottom, vertically centered, justified or distributed.\r
+ */\r
+public enum VerticalAlignment {\r
+    /**\r
+     * The vertical alignment is aligned-to-top.\r
+     */\r
+    TOP,\r
+\r
+    /**\r
+     * The vertical alignment is centered across the height of the cell.\r
+     */\r
+    CENTER,\r
+\r
+    /**\r
+     * The vertical alignment is aligned-to-bottom.\r
+     */\r
+    BOTTOM,\r
+\r
+    /**\r
+     * <p>\r
+     * When text direction is horizontal: the vertical alignment of lines of text is distributed vertically,\r
+     * where each line of text inside the cell is evenly distributed across the height of the cell,\r
+     * with flush top and bottom margins.\r
+     * </p>\r
+     * <p>\r
+     * When text direction is vertical: similar behavior as horizontal justification.\r
+     * The alignment is justified (flush top and bottom in this case). For each line of text, each\r
+     * line of the wrapped text in a cell is aligned to the top and bottom (except the last line).\r
+     * If no single line of text wraps in the cell, then the text is not justified.\r
+     *  </p>\r
+     */\r
+    JUSTIFY,\r
+\r
+    /**\r
+     * <p>\r
+     * When text direction is horizontal: the vertical alignment of lines of text is distributed vertically,\r
+     * where each line of text inside the cell is evenly distributed across the height of the cell,\r
+     * with flush top\r
+     * </p>\r
+     * <p>\r
+     * When text direction is vertical: behaves exactly as distributed horizontal alignment.\r
+     * The first words in a line of text (appearing at the top of the cell) are flush\r
+     * with the top edge of the cell, and the last words of a line of text are flush with the bottom edge of the cell,\r
+     * and the line of text is distributed evenly from top to bottom.\r
+     * </p>\r
+     */\r
+    DISTRIBUTED\r
+}\r
index aaa37f3026489fdfd34a2d5eca1bccf199161f5a..cf1efaa99043aa7e73af479b799c3bf04fbc3580 100644 (file)
 
 package org.apache.poi.xssf.usermodel;
 
-import org.apache.poi.ss.usermodel.CellStyle;
-import org.apache.poi.ss.usermodel.Font;
-import org.apache.poi.ss.usermodel.StylesSource;
-import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.xssf.model.StylesTable;
 import org.apache.poi.xssf.usermodel.extensions.XSSFCellAlignment;
 import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder;
@@ -31,410 +28,409 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellAlignment;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellProtection;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.STBorderStyle;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STHorizontalAlignment;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STVerticalAlignment;
 
 
 public class XSSFCellStyle implements CellStyle {
-       private int cellXfId;
-       private int cellStyleXfId;
-       private StylesSource stylesSource;
-       private CTXf cellXf;
-       private CTXf cellStyleXf;
-       private XSSFCellBorder cellBorder;
-       private XSSFCellFill cellFill;
-       private XSSFFont font;
-       private XSSFCellAlignment cellAlignment;
-       
-       /**
-        * Creates a Cell Style from the supplied parts
-        * @param cellXf The main XF for the cell
-        * @param cellStyleXf Optional, style xf
-        * @param stylesSource Styles Source to work off
-        */
-       public XSSFCellStyle(int cellXfId, int cellStyleXfId, StylesTable stylesSource) {
-               this.cellXfId = cellXfId;
-               this.cellStyleXfId = cellStyleXfId;
-               this.stylesSource = stylesSource;
-               this.cellXf = stylesSource.getCellXfAt(this.cellXfId);
-               this.cellStyleXf = stylesSource.getCellStyleXfAt(this.cellStyleXfId);
-       }
-       
-       /**
-        * Used so that StylesSource can figure out our location
-        */
-       public CTXf getCoreXf() {
-               return cellXf;
-       }
-       /**
-        * Used so that StylesSource can figure out our location
-        */
-       public CTXf getStyleXf() {
-               return cellStyleXf;
-       }
-       
-       /**
-        * Creates an empty Cell Style
-        */
-       public XSSFCellStyle(StylesSource stylesSource) {
-               this.stylesSource = stylesSource;
-               
-               // We need a new CTXf for the main styles
-               // TODO decide on a style ctxf
-               cellXf = CTXf.Factory.newInstance();
-       cellStyleXf = null;
-       }
-
-       /**
-        * Verifies that this style belongs to the supplied Workbook
-        *  Styles Source.
-        * Will throw an exception if it belongs to a different one.
-        * This is normally called when trying to assign a style to a
-        *  cell, to ensure the cell and the style are from the same
-        *  workbook (if they're not, it won't work)
-        * @throws IllegalArgumentException if there's a workbook mis-match
-        */
-       public void verifyBelongsToStylesSource(StylesSource src) {
-               if(this.stylesSource != src) {
-                       throw new IllegalArgumentException("This Style does not belong to the supplied Workbook Stlyes Source. Are you trying to assign a style from one workbook to the cell of a differnt workbook?");
-               }
-       }
+
+    private int cellXfId;
+    private int cellStyleXfId;
+    private StylesSource stylesSource;
+    private CTXf cellXf;
+    private CTXf cellStyleXf;
+    private XSSFCellBorder cellBorder;
+    private XSSFCellFill cellFill;
+    private XSSFFont font;
+    private XSSFCellAlignment cellAlignment;
+
+    /**
+     * Creates a Cell Style from the supplied parts
+     * @param cellXf The main XF for the cell
+     * @param cellStyleXf Optional, style xf
+     * @param stylesSource Styles Source to work off
+     */
+    public XSSFCellStyle(int cellXfId, int cellStyleXfId, StylesTable stylesSource) {
+        this.cellXfId = cellXfId;
+        this.cellStyleXfId = cellStyleXfId;
+        this.stylesSource = stylesSource;
+        this.cellXf = stylesSource.getCellXfAt(this.cellXfId);
+        this.cellStyleXf = stylesSource.getCellStyleXfAt(this.cellStyleXfId);
+    }
+
+    /**
+     * Used so that StylesSource can figure out our location
+     */
+    public CTXf getCoreXf() {
+        return cellXf;
+    }
+    /**
+     * Used so that StylesSource can figure out our location
+     */
+    public CTXf getStyleXf() {
+        return cellStyleXf;
+    }
+
+    /**
+     * Creates an empty Cell Style
+     */
+    public XSSFCellStyle(StylesSource stylesSource) {
+        this.stylesSource = stylesSource;
+
+        // We need a new CTXf for the main styles
+        // TODO decide on a style ctxf
+        cellXf = CTXf.Factory.newInstance();
+        cellStyleXf = null;
+    }
+
+    /**
+     * Verifies that this style belongs to the supplied Workbook
+     *  Styles Source.
+     * Will throw an exception if it belongs to a different one.
+     * This is normally called when trying to assign a style to a
+     *  cell, to ensure the cell and the style are from the same
+     *  workbook (if they're not, it won't work)
+     * @throws IllegalArgumentException if there's a workbook mis-match
+     */
+    public void verifyBelongsToStylesSource(StylesSource src) {
+        if(this.stylesSource != src) {
+            throw new IllegalArgumentException("This Style does not belong to the supplied Workbook Stlyes Source. Are you trying to assign a style from one workbook to the cell of a differnt workbook?");
+        }
+    }
 
     /**
      * Clones all the style information from another
-     *  XSSFCellStyle, onto this one. This 
+     *  XSSFCellStyle, onto this one. This
      *  XSSFCellStyle will then have all the same
      *  properties as the source, but the two may
      *  be edited independently.
-     * Any stylings on this XSSFCellStyle will be lost! 
-     *  
+     * Any stylings on this XSSFCellStyle will be lost!
+     *
      * The source XSSFCellStyle could be from another
      *  XSSFWorkbook if you like. This allows you to
      *  copy styles from one XSSFWorkbook to another.
      */
     public void cloneStyleFrom(CellStyle source) {
-               if(source instanceof XSSFCellStyle) {
-                       this.cloneStyleFrom((XSSFCellStyle)source);
-               }
-               throw new IllegalArgumentException("Can only clone from one XSSFCellStyle to another, not between HSSFCellStyle and XSSFCellStyle");
-       }
+        if(source instanceof XSSFCellStyle) {
+            this.cloneStyleFrom((XSSFCellStyle)source);
+        }
+        throw new IllegalArgumentException("Can only clone from one XSSFCellStyle to another, not between HSSFCellStyle and XSSFCellStyle");
+    }
     public void cloneStyleFrom(XSSFCellStyle source) {
-               throw new IllegalStateException("TODO");
-       }
-       
-       public short getAlignment() {
-               return (short)getAlignmentEnum().intValue();
-       }
-       
-       public STHorizontalAlignment.Enum getAlignmentEnum() {
-               return getCellAlignment().getHorizontal();
-       }
-
-       public short getBorderBottom() {
-               return getBorderStyleAsShort(BorderSide.BOTTOM);
-       }
-       
-       public String getBorderBottomAsString() {
-               return getBorderStyleAsString(BorderSide.BOTTOM);
-       }
-
-       public short getBorderLeft() {
-               return getBorderStyleAsShort(BorderSide.LEFT);
-       }
-       
-       public String getBorderLeftAsString() {
-               return getBorderStyleAsString(BorderSide.LEFT);
-       }
-
-       public short getBorderRight() {
-               return getBorderStyleAsShort(BorderSide.RIGHT);
-       }
-       
-       public String getBorderRightAsString() {
-               return getBorderStyleAsString(BorderSide.RIGHT);
-       }
-
-       public short getBorderTop() {
-               return getBorderStyleAsShort(BorderSide.TOP);
-       }
-       
-       public String getBorderTopAsString() {
-               return getBorderStyleAsString(BorderSide.TOP);
-       }
-
-       public short getBottomBorderColor() {
-               return getBorderColorIndexed(BorderSide.BOTTOM);
-       }
-
-       public short getDataFormat() {
-               return (short)cellXf.getNumFmtId();
-       }
-       public String getDataFormatString() {
-               return stylesSource.getNumberFormatAt(getDataFormat());
-       }
-
-       public short getFillBackgroundColor() {
-               return (short) getCellFill().getFillBackgroundColor().getIndexed();
-       }
-
-       public short getFillForegroundColor() {
-               return (short) getCellFill().getFillForegroundColor().getIndexed();
-       }
-
-       public short getFillPattern() {
-               return (short) getCellFill().getPatternType().intValue();
-       }
-
-       public Font getFont(Workbook parentWorkbook) {
-               return getFont();
-       }
-       
-       public Font getFont() {
-               if (font == null) {
-                       font = (XSSFFont) ((StylesTable)stylesSource).getFontAt(getFontId());
-               }
-               return font;
-       }
-
-       public short getFontIndex() {
-               return (short) getFontId();
-       }
-
-       public boolean getHidden() {
-               return getCellProtection().getHidden();
-       }
-
-       public short getIndention() {
-               return (short) getCellAlignment().getIndent();
-       }
-
-       public short getIndex() {
-               return (short) this.cellXfId;
-       }
-
-       public short getLeftBorderColor() {
-               return getBorderColorIndexed(BorderSide.LEFT);
-       }
-
-       public boolean getLocked() {
-               return getCellProtection().getLocked();
-       }
-
-       public short getRightBorderColor() {
-               return getBorderColorIndexed(BorderSide.RIGHT);
-       }
-
-       public short getRotation() {
-               return (short) getCellAlignment().getTextRotation();
-       }
-
-       public short getTopBorderColor() {
-               return getBorderColorIndexed(BorderSide.TOP);
-       }
-
-       public short getVerticalAlignment() {
-               return (short) getVerticalAlignmentEnum().intValue();
-       }
-       
-       public STVerticalAlignment.Enum getVerticalAlignmentEnum() {
-               return getCellAlignment().getVertical();
-       }
-
-       public boolean getWrapText() {
-               return getCellAlignment().getWrapText();
-       }
-
-       public void setAlignment(short align) {
-               getCellAlignment().setHorizontal(STHorizontalAlignment.Enum.forInt(align));
-       }
-       
-       public void setAlignementEnum(STHorizontalAlignment.Enum align) {
-               getCellAlignment().setHorizontal(align);
-       }
-
-       public void setBorderBottom(short border) {
-               setBorderBottomEnum(STBorderStyle.Enum.forInt(border));
-       }
-       
-       public void setBorderBottomEnum(STBorderStyle.Enum style) {
-               getCellBorder().setBorderStyle(BorderSide.BOTTOM, style);
-       }
-
-       public void setBorderLeft(short border) {
-               setBorderLeftEnum(STBorderStyle.Enum.forInt(border));
-       }
-       
-       public void setBorderLeftEnum(STBorderStyle.Enum style) {
-               getCellBorder().setBorderStyle(BorderSide.LEFT, style);
-       }
-
-       public void setBorderRight(short border) {
-               setBorderRightEnum(STBorderStyle.Enum.forInt(border));
-       }
-       
-       public void setBorderRightEnum(STBorderStyle.Enum style) {
-               getCellBorder().setBorderStyle(BorderSide.RIGHT, style);
-       }
-
-       public void setBorderTop(short border) {
-               setBorderTopEnum(STBorderStyle.Enum.forInt(border));
-       }
-       
-       public void setBorderTopEnum(STBorderStyle.Enum style) {
-               getCellBorder().setBorderStyle(BorderSide.TOP, style);
-       }
-
-       public void setBottomBorderColor(short color) {
-               setBorderColorIndexed(BorderSide.BOTTOM, color);
-       }
-
-       public void setDataFormat(short fmt) {
-               cellXf.setNumFmtId((long)fmt);
-       }
-
-       public void setFillBackgroundColor(short bg) {
-               getCellFill().setFillBackgroundColor(bg);
-       }
-
-       public void setFillForegroundColor(short bg) {
-               getCellFill().setFillForegroundColor(bg);
-       }
-
-       public void setFillPattern(short fp) {
-               // TODO Auto-generated method stub
-               
-       }
-
-       public void setFont(Font font) {
-               if(font!=null){
-                       long index=this.stylesSource.putFont(font);
-                       this.cellXf.setFontId(index);
-               }
-       }
-
-       public void setHidden(boolean hidden) {
-               getCellProtection().setHidden(hidden);
-       }
-
-       public void setIndention(short indent) {
-               getCellAlignment().setIndent(indent);
-       }
-
-       public void setLeftBorderColor(short color) {
-               setBorderColorIndexed(BorderSide.LEFT, color);
-       }
-
-       public void setLocked(boolean locked) {
-               getCellProtection().setLocked(locked);
-       }
-
-       public void setRightBorderColor(short color) {
-               setBorderColorIndexed(BorderSide.RIGHT, color);
-       }
-
-       public void setRotation(short rotation) {
-               getCellAlignment().setTextRotation(rotation);
-       }
-
-       public void setTopBorderColor(short color) {
-               setBorderColorIndexed(BorderSide.TOP, color);
-       }
-
-       public void setVerticalAlignment(short align) {
-               setVerticalAlignmentEnum(STVerticalAlignment.Enum.forInt(align));
-       }
-
-       public void setVerticalAlignmentEnum(STVerticalAlignment.Enum align) {
-               getCellAlignment().setVertical(align);
-       }
-
-       public void setWrapText(boolean wrapped) {
-               getCellAlignment().setWrapText(wrapped);
-       }
-
-       public XSSFColor getBorderColor(BorderSide side) {
-               return getCellBorder().getBorderColor(side);
-       }
-       
-       public void setBorderColor(BorderSide side, XSSFColor color) {
-               getCellBorder().setBorderColor(side, color);
-       }
-
-       private XSSFCellBorder getCellBorder() {
-               if (cellBorder == null) {
-                       // TODO make a common Cell Border object
-                       cellBorder = ((StylesTable)stylesSource).getBorderAt(getBorderId());
-               }
-               return cellBorder;
-       }
-
-       private int getBorderId() {
-               if (cellXf.isSetBorderId()) {
-                       return (int) cellXf.getBorderId();
-               }
-               return (int) cellStyleXf.getBorderId();
-       }
-       
-       private XSSFCellFill getCellFill() {
-               if (cellFill == null) {
-                       cellFill = ((StylesTable)stylesSource).getFillAt(getFillId());
-               }
-               return cellFill;
-       }
-       
-       private int getFillId() {
-               if (cellXf.isSetFillId()) {
-                       return (int) cellXf.getFillId();
-               }
-               return (int) cellStyleXf.getFillId();
-       }
-       
-       private int getFontId() {
-               if (cellXf.isSetFontId()) {
-                       return (int) cellXf.getFontId();
-               }
-               return (int) cellStyleXf.getFontId();
-       }
-
-       private CTCellProtection getCellProtection() {
-               if (cellXf.getProtection() == null) {
-                       cellXf.addNewProtection();
-               }
-               return cellXf.getProtection();
-       }
-
-       private XSSFCellAlignment getCellAlignment() {
-               if (this.cellAlignment == null) {
-                       this.cellAlignment = new XSSFCellAlignment(getCTCellAlignment());
-               }
-               return this.cellAlignment;
-       }
-
-       private CTCellAlignment getCTCellAlignment() {
-               if (cellXf.getAlignment() == null) {
-                       cellXf.setAlignment(CTCellAlignment.Factory.newInstance());
-               }
-               return cellXf.getAlignment();
-       }
-
-       private short getBorderColorIndexed(BorderSide side) {
-               return (short) getBorderColor(side).getIndexed();
-       }
-       
-       private void setBorderColorIndexed(BorderSide side, long color) {
-               getBorderColor(side).setIndexed(color);
-       }
-
-       private short getBorderStyleAsShort(BorderSide side) {
-               return (short) (getBorderStyle(side).intValue() - 1);
-       }
-       
-       private String getBorderStyleAsString(BorderSide side) {
-               return getBorderStyle(side).toString();
-       }
-
-       private STBorderStyle.Enum getBorderStyle(BorderSide side) {
-               return getCellBorder().getBorderStyle(side);
-       }
-       
+        throw new IllegalStateException("TODO");
+    }
+
+    public short getAlignment() {
+        return (short)(getAlignmentEnum().ordinal());
+    }
+
+    public HorizontalAlignment getAlignmentEnum() {
+        return getCellAlignment().getHorizontal();
+    }
+
+    public short getBorderBottom() {
+        return getBorderStyleAsShort(BorderSide.BOTTOM);
+    }
+
+    public String getBorderBottomAsString() {
+        return getBorderStyleAsString(BorderSide.BOTTOM);
+    }
+
+    public short getBorderLeft() {
+        return getBorderStyleAsShort(BorderSide.LEFT);
+    }
+
+    public String getBorderLeftAsString() {
+        return getBorderStyleAsString(BorderSide.LEFT);
+    }
+
+    public short getBorderRight() {
+        return getBorderStyleAsShort(BorderSide.RIGHT);
+    }
+
+    public String getBorderRightAsString() {
+        return getBorderStyleAsString(BorderSide.RIGHT);
+    }
+
+    public short getBorderTop() {
+        return getBorderStyleAsShort(BorderSide.TOP);
+    }
+
+    public String getBorderTopAsString() {
+        return getBorderStyleAsString(BorderSide.TOP);
+    }
+
+    public short getBottomBorderColor() {
+        return getBorderColorIndexed(BorderSide.BOTTOM);
+    }
+
+    public short getDataFormat() {
+        return (short)cellXf.getNumFmtId();
+    }
+    public String getDataFormatString() {
+        return stylesSource.getNumberFormatAt(getDataFormat());
+    }
+
+    public short getFillBackgroundColor() {
+        return (short) getCellFill().getFillBackgroundColor().getIndexed();
+    }
+
+    public short getFillForegroundColor() {
+        return (short) getCellFill().getFillForegroundColor().getIndexed();
+    }
+
+    public short getFillPattern() {
+        return (short) getCellFill().getPatternType().intValue();
+    }
+
+    public Font getFont(Workbook parentWorkbook) {
+        return getFont();
+    }
+
+    public Font getFont() {
+        if (font == null) {
+            font = (XSSFFont) ((StylesTable)stylesSource).getFontAt(getFontId());
+        }
+        return font;
+    }
+
+    public short getFontIndex() {
+        return (short) getFontId();
+    }
+
+    public boolean getHidden() {
+        return getCellProtection().getHidden();
+    }
+
+    public short getIndention() {
+        return (short) getCellAlignment().getIndent();
+    }
+
+    public short getIndex() {
+        return (short) this.cellXfId;
+    }
+
+    public short getLeftBorderColor() {
+        return getBorderColorIndexed(BorderSide.LEFT);
+    }
+
+    public boolean getLocked() {
+        return getCellProtection().getLocked();
+    }
+
+    public short getRightBorderColor() {
+        return getBorderColorIndexed(BorderSide.RIGHT);
+    }
+
+    public short getRotation() {
+        return (short) getCellAlignment().getTextRotation();
+    }
+
+    public short getTopBorderColor() {
+        return getBorderColorIndexed(BorderSide.TOP);
+    }
+
+    public short getVerticalAlignment() {
+        return (short) (getVerticalAlignmentEnum().ordinal());
+    }
+
+    public VerticalAlignment getVerticalAlignmentEnum() {
+        return getCellAlignment().getVertical();
+    }
+
+    public boolean getWrapText() {
+        return getCellAlignment().getWrapText();
+    }
+
+    public void setAlignment(short align) {
+        getCellAlignment().setHorizontal(HorizontalAlignment.values()[align]);
+    }
+
+    public void setAlignment(HorizontalAlignment align) {
+        setAlignment((short)align.ordinal());
+    }
+
+    public void setBorderBottom(short border) {
+        setBorderBottomEnum(STBorderStyle.Enum.forInt(border));
+    }
+
+    public void setBorderBottomEnum(STBorderStyle.Enum style) {
+        getCellBorder().setBorderStyle(BorderSide.BOTTOM, style);
+    }
+
+    public void setBorderLeft(short border) {
+        setBorderLeftEnum(STBorderStyle.Enum.forInt(border));
+    }
+
+    public void setBorderLeftEnum(STBorderStyle.Enum style) {
+        getCellBorder().setBorderStyle(BorderSide.LEFT, style);
+    }
+
+    public void setBorderRight(short border) {
+        setBorderRightEnum(STBorderStyle.Enum.forInt(border));
+    }
+
+    public void setBorderRightEnum(STBorderStyle.Enum style) {
+        getCellBorder().setBorderStyle(BorderSide.RIGHT, style);
+    }
+
+    public void setBorderTop(short border) {
+        setBorderTopEnum(STBorderStyle.Enum.forInt(border));
+    }
+
+    public void setBorderTopEnum(STBorderStyle.Enum style) {
+        getCellBorder().setBorderStyle(BorderSide.TOP, style);
+    }
+
+    public void setBottomBorderColor(short color) {
+        setBorderColorIndexed(BorderSide.BOTTOM, color);
+    }
+
+    public void setDataFormat(short fmt) {
+        cellXf.setNumFmtId((long)fmt);
+    }
+
+    public void setFillBackgroundColor(short bg) {
+        getCellFill().setFillBackgroundColor(bg);
+    }
+
+    public void setFillForegroundColor(short bg) {
+        getCellFill().setFillForegroundColor(bg);
+    }
+
+    public void setFillPattern(short fp) {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void setFont(Font font) {
+        if(font!=null){
+            long index=this.stylesSource.putFont(font);
+            this.cellXf.setFontId(index);
+        }
+    }
+
+    public void setHidden(boolean hidden) {
+        getCellProtection().setHidden(hidden);
+    }
+
+    public void setIndention(short indent) {
+        getCellAlignment().setIndent(indent);
+    }
+
+    public void setLeftBorderColor(short color) {
+        setBorderColorIndexed(BorderSide.LEFT, color);
+    }
+
+    public void setLocked(boolean locked) {
+        getCellProtection().setLocked(locked);
+    }
+
+    public void setRightBorderColor(short color) {
+        setBorderColorIndexed(BorderSide.RIGHT, color);
+    }
+
+    public void setRotation(short rotation) {
+        getCellAlignment().setTextRotation(rotation);
+    }
+
+    public void setTopBorderColor(short color) {
+        setBorderColorIndexed(BorderSide.TOP, color);
+    }
+
+    public void setVerticalAlignment(short align) {
+        getCellAlignment().setVertical(VerticalAlignment.values()[align]);
+    }
+
+    public void setVerticalAlignment(VerticalAlignment align) {
+        getCellAlignment().setVertical(align);
+    }
+
+    public void setWrapText(boolean wrapped) {
+        getCellAlignment().setWrapText(wrapped);
+    }
+
+    public XSSFColor getBorderColor(BorderSide side) {
+        return getCellBorder().getBorderColor(side);
+    }
+
+    public void setBorderColor(BorderSide side, XSSFColor color) {
+        getCellBorder().setBorderColor(side, color);
+    }
+
+    private XSSFCellBorder getCellBorder() {
+        if (cellBorder == null) {
+            // TODO make a common Cell Border object
+            cellBorder = ((StylesTable)stylesSource).getBorderAt(getBorderId());
+        }
+        return cellBorder;
+    }
+
+    private int getBorderId() {
+        if (cellXf.isSetBorderId()) {
+            return (int) cellXf.getBorderId();
+        }
+        return (int) cellStyleXf.getBorderId();
+    }
+
+    private XSSFCellFill getCellFill() {
+        if (cellFill == null) {
+            cellFill = ((StylesTable)stylesSource).getFillAt(getFillId());
+        }
+        return cellFill;
+    }
+
+    private int getFillId() {
+        if (cellXf.isSetFillId()) {
+            return (int) cellXf.getFillId();
+        }
+        return (int) cellStyleXf.getFillId();
+    }
+
+    private int getFontId() {
+        if (cellXf.isSetFontId()) {
+            return (int) cellXf.getFontId();
+        }
+        return (int) cellStyleXf.getFontId();
+    }
+
+    private CTCellProtection getCellProtection() {
+        if (cellXf.getProtection() == null) {
+            cellXf.addNewProtection();
+        }
+        return cellXf.getProtection();
+    }
+
+    public XSSFCellAlignment getCellAlignment() {
+        if (this.cellAlignment == null) {
+            this.cellAlignment = new XSSFCellAlignment(getCTCellAlignment());
+        }
+        return this.cellAlignment;
+    }
+
+    private CTCellAlignment getCTCellAlignment() {
+        if (cellXf.getAlignment() == null) {
+            cellXf.setAlignment(CTCellAlignment.Factory.newInstance());
+        }
+        return cellXf.getAlignment();
+    }
+
+    private short getBorderColorIndexed(BorderSide side) {
+        return (short) getBorderColor(side).getIndexed();
+    }
+
+    private void setBorderColorIndexed(BorderSide side, long color) {
+        getBorderColor(side).setIndexed(color);
+    }
+
+    private short getBorderStyleAsShort(BorderSide side) {
+        return (short) (getBorderStyle(side).intValue() - 1);
+    }
+
+    private String getBorderStyleAsString(BorderSide side) {
+        return getBorderStyle(side).toString();
+    }
+
+    private STBorderStyle.Enum getBorderStyle(BorderSide side) {
+        return getCellBorder().getBorderStyle(side);
+    }
+
 }
index 71a32d4df32a15e16178c4eea33d312055eae43f..5e448b6f0ab90b2a5ec0c63a9bf913bce3a35a58 100644 (file)
@@ -19,59 +19,71 @@ 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.xssf.usermodel.HorizontalAlignment;
+import org.apache.poi.xssf.usermodel.VerticalAlignment;
 
 
+/**
+ * Cell settings avaiable in the Format/Alignment tab
+ */
 public class XSSFCellAlignment {
-       
-       private CTCellAlignment cellAlignement;
-       
-       public XSSFCellAlignment(CTCellAlignment cellAlignment) {
-               this.cellAlignement = cellAlignment;
-       }
-       
-       public STVerticalAlignment.Enum getVertical() {
-               if (cellAlignement.getVertical() == null) {
-                       cellAlignement.setVertical(STVerticalAlignment.TOP);
-               }
-               return cellAlignement.getVertical();
-       }
-       
-       public void setVertical(STVerticalAlignment.Enum vertical) {
-               cellAlignement.setVertical(vertical);
-       }
-       
-       public STHorizontalAlignment.Enum getHorizontal() {
-               if (cellAlignement.getHorizontal() == null) {
-                       cellAlignement.setHorizontal(STHorizontalAlignment.GENERAL);
-               }
-               return cellAlignement.getHorizontal();
-       }
-       
-       public void setHorizontal(STHorizontalAlignment.Enum horizontal) {
-               cellAlignement.setHorizontal(horizontal);
-       }
-       
-       public long getIndent() {
-               return cellAlignement.getIndent();
-       }
-       
-       public void setIndent(long indent) {
-               cellAlignement.setIndent(indent);
-       }
-       
-       public long getTextRotation() {
-               return cellAlignement.getTextRotation();
-       }
-       
-       public void setTextRotation(long rotation) {
-               cellAlignement.setTextRotation(rotation);
-       }
-       
-       public boolean getWrapText() {
-               return cellAlignement.getWrapText();
-       }
-       
-       public void setWrapText(boolean wrapped) {
-               cellAlignement.setWrapText(wrapped);
-       }
+
+    private CTCellAlignment cellAlignement;
+
+    public XSSFCellAlignment(CTCellAlignment cellAlignment) {
+        this.cellAlignement = cellAlignment;
+    }
+
+    public VerticalAlignment getVertical() {
+        STVerticalAlignment.Enum align = cellAlignement.getVertical();
+        if(align == null) align = STVerticalAlignment.BOTTOM;
+
+        return VerticalAlignment.values()[align.intValue() - 1];
+    }
+
+    public void setVertical(VerticalAlignment vertical) {
+        cellAlignement.setVertical(STVerticalAlignment.Enum.forInt(vertical.ordinal() + 1));
+    }
+
+    public HorizontalAlignment getHorizontal() {
+        STHorizontalAlignment.Enum align = cellAlignement.getHorizontal();
+        if(align == null) align = STHorizontalAlignment.GENERAL;
+
+        return HorizontalAlignment.values()[align.intValue() - 1];
+    }
+
+    public void setHorizontal(HorizontalAlignment align) {
+        cellAlignement.setHorizontal(STHorizontalAlignment.Enum.forInt(align.ordinal() + 1));
+    }
+
+    public long getIndent() {
+        return cellAlignement.getIndent();
+    }
+
+    public void setIndent(long indent) {
+        cellAlignement.setIndent(indent);
+    }
+
+    public long getTextRotation() {
+        return cellAlignement.getTextRotation();
+    }
+
+    public void setTextRotation(long rotation) {
+        cellAlignement.setTextRotation(rotation);
+    }
+
+    public boolean getWrapText() {
+        return cellAlignement.getWrapText();
+    }
+
+    public void setWrapText(boolean wrapped) {
+        cellAlignement.setWrapText(wrapped);
+    }
+
+    /**
+     * Access to low-level data
+     */
+    public CTCellAlignment getCTCellAlignment() {
+        return cellAlignement;
+    }
 }
index e7e9bb7606829834d43f52fb85c010dd2ef0939b..1ce50656b4582dce4621a5cd258e39af0dc3a962 100644 (file)
@@ -19,324 +19,280 @@ package org.apache.poi.xssf.usermodel;
 
 import junit.framework.TestCase;
 
-import org.apache.poi.ss.usermodel.StylesSource;
 import org.apache.poi.xssf.model.StylesTable;
 import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder;
 import org.apache.poi.xssf.usermodel.extensions.XSSFCellFill;
 import org.apache.poi.xssf.usermodel.extensions.XSSFColor;
 import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder.BorderSide;
-import org.apache.poi.xssf.util.IndexedColors;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellXfs;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPatternFill;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTStylesheet;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STBorderStyle;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STHorizontalAlignment;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPatternType;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STVerticalAlignment;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
 
 
 public class TestXSSFCellStyle extends TestCase {
-       
-       private StylesTable stylesTable;
-       private CTBorder ctBorderA;
-       private CTFill ctFill;
-       private CTFont ctFont;
-       private CTXf cellStyleXf;
-       private CTXf cellXf;
-       private CTCellXfs cellXfs;
-       private XSSFCellStyle cellStyle;
-       private CTStylesheet ctStylesheet;
-
-       public void setUp() {
-               stylesTable = new StylesTable();
-               
-               ctStylesheet = stylesTable._getRawStylesheet();
-               
-               // Until we do XSSFBorder properly, cheat
-               ctBorderA = CTBorder.Factory.newInstance();
-               XSSFCellBorder borderA = new XSSFCellBorder(ctBorderA);
-               long borderId = stylesTable.putBorder(borderA);
-               assertEquals(1, borderId);
-               
-               XSSFCellBorder borderB = new XSSFCellBorder();
-               assertEquals(2, stylesTable.putBorder(borderB));
-               
-               ctFill = CTFill.Factory.newInstance();
-               XSSFCellFill fill = new XSSFCellFill(ctFill);
-               long fillId = stylesTable.putFill(fill);
-               assertEquals(1, fillId);
-               
-               ctFont = CTFont.Factory.newInstance();
-               XSSFFont font = new XSSFFont(ctFont);
-               long fontId = stylesTable.putFont(font);
-               assertEquals(1, fontId);
-               
-               cellStyleXf = ctStylesheet.addNewCellStyleXfs().addNewXf();
-               cellStyleXf.setBorderId(1);
-               cellStyleXf.setFillId(1);
-               cellStyleXf.setFontId(1);
-               cellXfs = ctStylesheet.addNewCellXfs();
-               cellXf = cellXfs.addNewXf();
-               cellXf.setXfId(1);
-               stylesTable.putCellStyleXf(cellStyleXf);
-               stylesTable.putCellXf(cellXf);
-               cellStyle = new XSSFCellStyle(1, 1, stylesTable);
-       }
-       
-       public void testGetSetBorderBottom() {          
-               ctBorderA.addNewBottom().setStyle(STBorderStyle.THIN);
-               assertEquals((short)1, cellStyle.getBorderBottom());
-               cellStyle.setBorderBottom((short) 2);
-               assertEquals(STBorderStyle.THIN, ctBorderA.getBottom().getStyle());
-               cellStyle.setBorderBottomEnum(STBorderStyle.THICK);
-               assertEquals(6, ctBorderA.getBottom().getStyle().intValue());
-       }
-
-       public void testGetBorderBottomAsString() {
-               ctBorderA.addNewBottom().setStyle(STBorderStyle.THIN);
-               assertEquals("thin", cellStyle.getBorderBottomAsString());
-       }
-       
-       public void testGetSetBorderRight() {
-               ctBorderA.addNewRight().setStyle(STBorderStyle.MEDIUM);
-               assertEquals((short)2, cellStyle.getBorderRight());
-               cellStyle.setBorderRight((short) 2);
-               assertEquals(STBorderStyle.THIN, ctBorderA.getRight().getStyle());
-               cellStyle.setBorderRightEnum(STBorderStyle.THICK);
-               assertEquals(6, ctBorderA.getRight().getStyle().intValue());
-       }
-
-       public void testGetBorderRightAsString() {
-               ctBorderA.addNewRight().setStyle(STBorderStyle.MEDIUM);
-               assertEquals("medium", cellStyle.getBorderRightAsString());
-       }
-       
-       public void testGetSetBorderLeft() {
-               ctBorderA.addNewLeft().setStyle(STBorderStyle.DASHED);
-               assertEquals((short)3, cellStyle.getBorderLeft());
-               cellStyle.setBorderLeft((short) 2);
-               assertEquals(STBorderStyle.THIN, ctBorderA.getLeft().getStyle());
-               cellStyle.setBorderLeftEnum(STBorderStyle.THICK);
-               assertEquals(6, ctBorderA.getLeft().getStyle().intValue());
-       }
-
-       public void testGetBorderLeftAsString() {
-               ctBorderA.addNewLeft().setStyle(STBorderStyle.DASHED);
-               assertEquals("dashed", cellStyle.getBorderLeftAsString());
-       }
-       
-       public void testGetSetBorderTop() {
-               ctBorderA.addNewTop().setStyle(STBorderStyle.HAIR);
-               assertEquals((short)7, cellStyle.getBorderTop());
-               cellStyle.setBorderTop((short) 2);
-               assertEquals(STBorderStyle.THIN, ctBorderA.getTop().getStyle());
-               cellStyle.setBorderTopEnum(STBorderStyle.THICK);
-               assertEquals(6, ctBorderA.getTop().getStyle().intValue());
-       }
-
-       public void testGetBorderTopAsString() {
-               ctBorderA.addNewTop().setStyle(STBorderStyle.HAIR);
-               assertEquals("hair", cellStyle.getBorderTopAsString());
-       }
-       
-       public void testGetSetBottomBorderColor() {
-               CTColor ctColor = ctBorderA.addNewBottom().addNewColor();
-               ctColor.setIndexed(2);
-               XSSFColor color = new XSSFColor(ctColor);
-               assertEquals((short)2, cellStyle.getBottomBorderColor());
-               CTColor anotherCtColor = CTColor.Factory.newInstance();
-               anotherCtColor.setIndexed(4);
-               anotherCtColor.setTheme(3);
-               anotherCtColor.setRgb("1234".getBytes());
-               XSSFColor anotherColor = new XSSFColor(anotherCtColor);
-               cellStyle.setBorderColor(BorderSide.BOTTOM, anotherColor);
-               assertEquals((short)4, cellStyle.getBottomBorderColor());
-               assertEquals(new String("1234".getBytes()), new String(cellStyle.getBorderColor(BorderSide.BOTTOM).getRgb()));
-       }
-       
-       public void testGetSetTopBorderColor() {
-               CTColor ctColor = ctBorderA.addNewTop().addNewColor();
-               ctColor.setIndexed(5);
-               XSSFColor color = new XSSFColor(ctColor);
-               assertEquals((short)5, cellStyle.getTopBorderColor());
-               CTColor anotherCtColor = CTColor.Factory.newInstance();
-               anotherCtColor.setIndexed(7);
-               anotherCtColor.setTheme(3);
-               anotherCtColor.setRgb("abcd".getBytes());
-               XSSFColor anotherColor = new XSSFColor(anotherCtColor);
-               cellStyle.setBorderColor(BorderSide.TOP, anotherColor);
-               assertEquals((short)7, cellStyle.getTopBorderColor());
-               assertEquals(new String("abcd".getBytes()), new String(cellStyle.getBorderColor(BorderSide.TOP).getRgb()));
-       }
-       
-       public void testGetSetLeftBorderColor() {
-               CTColor ctColor = ctBorderA.addNewLeft().addNewColor();
-               ctColor.setIndexed(2);
-               XSSFColor color = new XSSFColor(ctColor);
-               assertEquals((short)2, cellStyle.getLeftBorderColor());
-               CTColor anotherCtColor = CTColor.Factory.newInstance();
-               anotherCtColor.setIndexed(4);
-               anotherCtColor.setTheme(3);
-               anotherCtColor.setRgb("1234".getBytes());
-               XSSFColor anotherColor = new XSSFColor(anotherCtColor);
-               cellStyle.setBorderColor(BorderSide.LEFT, anotherColor);
-               assertEquals((short)4, cellStyle.getLeftBorderColor());
-               assertEquals(new String("1234".getBytes()), new String(cellStyle.getBorderColor(BorderSide.LEFT).getRgb()));
-       }
-       
-       public void testGetSetRightBorderColor() {
-               CTColor ctColor = ctBorderA.addNewRight().addNewColor();
-               ctColor.setIndexed(8);
-               XSSFColor color = new XSSFColor(ctColor);
-               assertEquals((short)8, cellStyle.getRightBorderColor());
-               CTColor anotherCtColor = CTColor.Factory.newInstance();
-               anotherCtColor.setIndexed(14);
-               anotherCtColor.setTheme(3);
-               anotherCtColor.setRgb("af67".getBytes());
-               XSSFColor anotherColor = new XSSFColor(anotherCtColor);
-               cellStyle.setBorderColor(BorderSide.RIGHT, anotherColor);
-               assertEquals((short)14, cellStyle.getRightBorderColor());
-               assertEquals(new String("af67".getBytes()), new String(cellStyle.getBorderColor(BorderSide.RIGHT).getRgb()));
-       }
-       
-       public void testGetFillBackgroundColor() {
-               CTPatternFill ctPatternFill = ctFill.addNewPatternFill();
-               CTColor ctBgColor = ctPatternFill.addNewBgColor();
-               ctBgColor.setIndexed(4);
-               assertEquals(4, cellStyle.getFillBackgroundColor());
-       }
-       
-       public void testGetFillForegroundColor() {
-               CTPatternFill ctPatternFill = ctFill.addNewPatternFill();
-               CTColor ctFgColor = ctPatternFill.addNewFgColor();
-               ctFgColor.setIndexed(5);
-               assertEquals(5, cellStyle.getFillForegroundColor());
-       }
-       
-       public void testGetFillPattern() {
-               CTPatternFill ctPatternFill = ctFill.addNewPatternFill();
-               ctPatternFill.setPatternType(STPatternType.DARK_DOWN);
-               assertEquals(8, cellStyle.getFillPattern());
-       }
-       
-       public void testGetSetFont() {
-               assertNotNull(this.cellStyle.getFont());
-               
-               StylesSource stylesSource=new StylesTable();
-               XSSFFont xssfFont=new XSSFFont();
-               xssfFont.setFontName("Arial");
-               stylesSource.putFont(xssfFont);
-               XSSFCellStyle cellStyle=new XSSFCellStyle(stylesSource);
-       
-               XSSFFont xssfFont2=new XSSFFont();
-               xssfFont2.setFontName("courier");
-               xssfFont2.setFontHeightInPoints((short)10);
-               
-               cellStyle.setFont(xssfFont2);
-               assertEquals(2,cellStyle.getFontIndex());
-               assertEquals(xssfFont2.getFontName(),cellStyle.getFont().getFontName());
-               assertEquals(stylesSource.getFontAt(2).getFontHeightInPoints(),cellStyle.getFont().getFontHeightInPoints());
-
-               cellStyle.setFont(xssfFont);
-               assertEquals(1,cellStyle.getFontIndex());
-               
-               
-               XSSFFont xssfFont3=new XSSFFont();
-               xssfFont3.setFontName("Arial");
-               cellStyle.setFont(xssfFont3);
-               assertNotSame(1,cellStyle.getFontIndex());
-               
-       }
-       
-       public void testGetSetHidden() {
-               assertFalse(cellStyle.getHidden());
-               cellXf.getProtection().setHidden(true);
-               assertTrue(cellStyle.getHidden());
-               cellStyle.setHidden(false);
-               assertFalse(cellStyle.getHidden());
-       }
-       
-       public void testGetSetLocked() {
-               assertFalse(cellStyle.getLocked());
-               cellXf.getProtection().setLocked(true);
-               assertTrue(cellStyle.getLocked());
-               cellStyle.setLocked(false);
-               assertFalse(cellStyle.getLocked());
-       }
-       
-       public void testGetSetIndent() {
-               assertEquals((short)0, cellStyle.getIndention());
-               cellXf.getAlignment().setIndent(3);
-               assertEquals((short)3, cellStyle.getIndention());
-               cellStyle.setIndention((short) 13);
-               assertEquals((short)13, cellXf.getAlignment().getIndent());
-       }
-       
-       public void testGetSetAlignement() {
-               assertEquals(1, cellStyle.getAlignment());
-               cellStyle.setAlignment((short)2);
-               assertEquals(STHorizontalAlignment.LEFT, cellStyle.getAlignmentEnum());
-               cellStyle.setAlignementEnum(STHorizontalAlignment.JUSTIFY);
-               assertEquals((short)6, cellStyle.getAlignment());
-       }
-       
-       public void testGetSetVerticalAlignment() {
-               assertEquals(1, cellStyle.getVerticalAlignment());
-               cellStyle.setVerticalAlignment((short)2);
-               assertEquals(STVerticalAlignment.CENTER, cellStyle.getVerticalAlignmentEnum());
-               cellStyle.setVerticalAlignmentEnum(STVerticalAlignment.JUSTIFY);
-               assertEquals((short)4, cellStyle.getVerticalAlignment());
-       }
-       
-       public void testGetSetWrapText() {
-               assertFalse(cellStyle.getWrapText());
-               cellXf.getAlignment().setWrapText(true);
-               assertTrue(cellStyle.getWrapText());
-               cellStyle.setWrapText(false);
-               assertFalse(cellXf.getAlignment().getWrapText());
-       }
-
-       public void testGetSetFillBackgroundColor() {
-               setUp();
-               CTPatternFill ctPatternFill = ctFill.addNewPatternFill();
-               CTColor ctBgColor = ctPatternFill.addNewBgColor();
-               ctBgColor.setIndexed(IndexedColors.BLUE);
-               assertEquals(IndexedColors.BLUE, cellStyle.getFillBackgroundColor());
-               
-               cellStyle.setFillBackgroundColor((short)IndexedColors.GREEN);
-               assertEquals(IndexedColors.GREEN,ctFill.getPatternFill().getBgColor().getIndexed());
-       }
-        
-       public void testGetSetFillForegroundColor() {
-               setUp();
-
-               CTPatternFill ctPatternFill = ctFill.addNewPatternFill();
-               CTColor ctFgColor = ctPatternFill.addNewFgColor();
-               ctFgColor.setIndexed(5);
-               assertEquals(5, cellStyle.getFillForegroundColor());
-               
-               ctFgColor.setIndexed(IndexedColors.BLUE);
-               assertEquals(IndexedColors.BLUE, cellStyle.getFillForegroundColor());
-               
-               cellStyle.setFillForegroundColor((short)IndexedColors.GREEN);
-               assertEquals(IndexedColors.GREEN,ctFill.getPatternFill().getFgColor().getIndexed());
-       }
-        
-       /**
-        * Cloning one XSSFCellStyle onto Another, same XSSFWorkbook
-        */
-       public void testCloneStyleSameWB() throws Exception {
-               // TODO
-       }
-       /**
-        * Cloning one XSSFCellStyle onto Another, different XSSFWorkbooks
-        */
-       public void testCloneStyleDiffWB() throws Exception {
-               // TODO
-       }
+
+    private StylesTable stylesTable;
+    private CTBorder ctBorderA;
+    private CTFill ctFill;
+    private CTFont ctFont;
+    private CTXf cellStyleXf;
+    private CTXf cellXf;
+    private CTCellXfs cellXfs;
+    private XSSFCellStyle cellStyle;
+    private CTStylesheet ctStylesheet;
+
+    public void setUp() {
+        stylesTable = new StylesTable();
+
+        ctStylesheet = stylesTable._getRawStylesheet();
+
+        // Until we do XSSFBorder properly, cheat
+        ctBorderA = CTBorder.Factory.newInstance();
+        XSSFCellBorder borderA = new XSSFCellBorder(ctBorderA);
+        long borderId = stylesTable.putBorder(borderA);
+        assertEquals(1, borderId);
+
+        XSSFCellBorder borderB = new XSSFCellBorder();
+        assertEquals(2, stylesTable.putBorder(borderB));
+
+        ctFill = CTFill.Factory.newInstance();
+        XSSFCellFill fill = new XSSFCellFill(ctFill);
+        long fillId = stylesTable.putFill(fill);
+        assertEquals(1, fillId);
+
+        ctFont = CTFont.Factory.newInstance();
+        XSSFFont font = new XSSFFont(ctFont);
+        long fontId = stylesTable.putFont(font);
+        assertEquals(1, fontId);
+
+        cellStyleXf = ctStylesheet.addNewCellStyleXfs().addNewXf();
+        cellStyleXf.setBorderId(1);
+        cellStyleXf.setFillId(1);
+        cellStyleXf.setFontId(1);
+        cellXfs = ctStylesheet.addNewCellXfs();
+        cellXf = cellXfs.addNewXf();
+        cellXf.setXfId(1);
+        stylesTable.putCellStyleXf(cellStyleXf);
+        stylesTable.putCellXf(cellXf);
+        cellStyle = new XSSFCellStyle(1, 1, stylesTable);
+    }
+
+    public void testGetSetBorderBottom() {
+        ctBorderA.addNewBottom().setStyle(STBorderStyle.THIN);
+        assertEquals((short)1, cellStyle.getBorderBottom());
+        cellStyle.setBorderBottom((short) 2);
+        assertEquals(STBorderStyle.THIN, ctBorderA.getBottom().getStyle());
+        cellStyle.setBorderBottomEnum(STBorderStyle.THICK);
+        assertEquals(6, ctBorderA.getBottom().getStyle().intValue());
+    }
+
+    public void testGetBorderBottomAsString() {
+        ctBorderA.addNewBottom().setStyle(STBorderStyle.THIN);
+        assertEquals("thin", cellStyle.getBorderBottomAsString());
+    }
+
+    public void testGetSetBorderRight() {
+        ctBorderA.addNewRight().setStyle(STBorderStyle.MEDIUM);
+        assertEquals((short)2, cellStyle.getBorderRight());
+        cellStyle.setBorderRight((short) 2);
+        assertEquals(STBorderStyle.THIN, ctBorderA.getRight().getStyle());
+        cellStyle.setBorderRightEnum(STBorderStyle.THICK);
+        assertEquals(6, ctBorderA.getRight().getStyle().intValue());
+    }
+
+    public void testGetBorderRightAsString() {
+        ctBorderA.addNewRight().setStyle(STBorderStyle.MEDIUM);
+        assertEquals("medium", cellStyle.getBorderRightAsString());
+    }
+
+    public void testGetSetBorderLeft() {
+        ctBorderA.addNewLeft().setStyle(STBorderStyle.DASHED);
+        assertEquals((short)3, cellStyle.getBorderLeft());
+        cellStyle.setBorderLeft((short) 2);
+        assertEquals(STBorderStyle.THIN, ctBorderA.getLeft().getStyle());
+        cellStyle.setBorderLeftEnum(STBorderStyle.THICK);
+        assertEquals(6, ctBorderA.getLeft().getStyle().intValue());
+    }
+
+    public void testGetBorderLeftAsString() {
+        ctBorderA.addNewLeft().setStyle(STBorderStyle.DASHED);
+        assertEquals("dashed", cellStyle.getBorderLeftAsString());
+    }
+
+    public void testGetSetBorderTop() {
+        ctBorderA.addNewTop().setStyle(STBorderStyle.HAIR);
+        assertEquals((short)7, cellStyle.getBorderTop());
+        cellStyle.setBorderTop((short) 2);
+        assertEquals(STBorderStyle.THIN, ctBorderA.getTop().getStyle());
+        cellStyle.setBorderTopEnum(STBorderStyle.THICK);
+        assertEquals(6, ctBorderA.getTop().getStyle().intValue());
+    }
+
+    public void testGetBorderTopAsString() {
+        ctBorderA.addNewTop().setStyle(STBorderStyle.HAIR);
+        assertEquals("hair", cellStyle.getBorderTopAsString());
+    }
+
+    public void testGetSetBottomBorderColor() {
+        CTColor ctColor = ctBorderA.addNewBottom().addNewColor();
+        ctColor.setIndexed(2);
+        XSSFColor color = new XSSFColor(ctColor);
+        assertEquals((short)2, cellStyle.getBottomBorderColor());
+        CTColor anotherCtColor = CTColor.Factory.newInstance();
+        anotherCtColor.setIndexed(4);
+        anotherCtColor.setTheme(3);
+        anotherCtColor.setRgb("1234".getBytes());
+        XSSFColor anotherColor = new XSSFColor(anotherCtColor);
+        cellStyle.setBorderColor(BorderSide.BOTTOM, anotherColor);
+        assertEquals((short)4, cellStyle.getBottomBorderColor());
+        assertEquals(new String("1234".getBytes()), new String(cellStyle.getBorderColor(BorderSide.BOTTOM).getRgb()));
+    }
+
+    public void testGetSetTopBorderColor() {
+        CTColor ctColor = ctBorderA.addNewTop().addNewColor();
+        ctColor.setIndexed(5);
+        XSSFColor color = new XSSFColor(ctColor);
+        assertEquals((short)5, cellStyle.getTopBorderColor());
+        CTColor anotherCtColor = CTColor.Factory.newInstance();
+        anotherCtColor.setIndexed(7);
+        anotherCtColor.setTheme(3);
+        anotherCtColor.setRgb("abcd".getBytes());
+        XSSFColor anotherColor = new XSSFColor(anotherCtColor);
+        cellStyle.setBorderColor(BorderSide.TOP, anotherColor);
+        assertEquals((short)7, cellStyle.getTopBorderColor());
+        assertEquals(new String("abcd".getBytes()), new String(cellStyle.getBorderColor(BorderSide.TOP).getRgb()));
+    }
+
+    public void testGetSetLeftBorderColor() {
+        CTColor ctColor = ctBorderA.addNewLeft().addNewColor();
+        ctColor.setIndexed(2);
+        XSSFColor color = new XSSFColor(ctColor);
+        assertEquals((short)2, cellStyle.getLeftBorderColor());
+        CTColor anotherCtColor = CTColor.Factory.newInstance();
+        anotherCtColor.setIndexed(4);
+        anotherCtColor.setTheme(3);
+        anotherCtColor.setRgb("1234".getBytes());
+        XSSFColor anotherColor = new XSSFColor(anotherCtColor);
+        cellStyle.setBorderColor(BorderSide.LEFT, anotherColor);
+        assertEquals((short)4, cellStyle.getLeftBorderColor());
+        assertEquals(new String("1234".getBytes()), new String(cellStyle.getBorderColor(BorderSide.LEFT).getRgb()));
+    }
+
+    public void testGetSetRightBorderColor() {
+        CTColor ctColor = ctBorderA.addNewRight().addNewColor();
+        ctColor.setIndexed(8);
+        XSSFColor color = new XSSFColor(ctColor);
+        assertEquals((short)8, cellStyle.getRightBorderColor());
+        CTColor anotherCtColor = CTColor.Factory.newInstance();
+        anotherCtColor.setIndexed(14);
+        anotherCtColor.setTheme(3);
+        anotherCtColor.setRgb("af67".getBytes());
+        XSSFColor anotherColor = new XSSFColor(anotherCtColor);
+        cellStyle.setBorderColor(BorderSide.RIGHT, anotherColor);
+        assertEquals((short)14, cellStyle.getRightBorderColor());
+        assertEquals(new String("af67".getBytes()), new String(cellStyle.getBorderColor(BorderSide.RIGHT).getRgb()));
+    }
+
+    public void testGetFillBackgroundColor() {
+        CTPatternFill ctPatternFill = ctFill.addNewPatternFill();
+        CTColor ctBgColor = ctPatternFill.addNewBgColor();
+        ctBgColor.setIndexed(4);
+        assertEquals(4, cellStyle.getFillBackgroundColor());
+    }
+
+    public void testGetFillForegroundColor() {
+        CTPatternFill ctPatternFill = ctFill.addNewPatternFill();
+        CTColor ctFgColor = ctPatternFill.addNewFgColor();
+        ctFgColor.setIndexed(5);
+        assertEquals(5, cellStyle.getFillForegroundColor());
+    }
+
+    public void testGetFillPattern() {
+        CTPatternFill ctPatternFill = ctFill.addNewPatternFill();
+        ctPatternFill.setPatternType(STPatternType.DARK_DOWN);
+        assertEquals(8, cellStyle.getFillPattern());
+    }
+
+    public void testGetFont() {
+        assertNotNull(cellStyle.getFont());
+    }
+
+    public void testGetSetHidden() {
+        assertFalse(cellStyle.getHidden());
+        cellXf.getProtection().setHidden(true);
+        assertTrue(cellStyle.getHidden());
+        cellStyle.setHidden(false);
+        assertFalse(cellStyle.getHidden());
+    }
+
+    public void testGetSetLocked() {
+        assertFalse(cellStyle.getLocked());
+        cellXf.getProtection().setLocked(true);
+        assertTrue(cellStyle.getLocked());
+        cellStyle.setLocked(false);
+        assertFalse(cellStyle.getLocked());
+    }
+
+    public void testGetSetIndent() {
+        assertEquals((short)0, cellStyle.getIndention());
+        cellXf.getAlignment().setIndent(3);
+        assertEquals((short)3, cellStyle.getIndention());
+        cellStyle.setIndention((short) 13);
+        assertEquals((short)13, cellXf.getAlignment().getIndent());
+    }
+
+    public void testGetSetAlignement() {
+        assertNull(cellStyle.getCellAlignment().getCTCellAlignment().getHorizontal());
+        assertEquals(HorizontalAlignment.GENERAL, cellStyle.getAlignmentEnum());
+
+        cellStyle.setAlignment(XSSFCellStyle.ALIGN_LEFT);
+        assertEquals(XSSFCellStyle.ALIGN_LEFT, cellStyle.getAlignment());
+        assertEquals(HorizontalAlignment.LEFT, cellStyle.getAlignmentEnum());
+        assertEquals(STHorizontalAlignment.LEFT, cellStyle.getCellAlignment().getCTCellAlignment().getHorizontal());
+
+        cellStyle.setAlignment(HorizontalAlignment.JUSTIFY);
+        assertEquals(XSSFCellStyle.ALIGN_JUSTIFY, cellStyle.getAlignment());
+        assertEquals(HorizontalAlignment.JUSTIFY, cellStyle.getAlignmentEnum());
+        assertEquals(STHorizontalAlignment.JUSTIFY, cellStyle.getCellAlignment().getCTCellAlignment().getHorizontal());
+
+        cellStyle.setAlignment(HorizontalAlignment.CENTER);
+        assertEquals(XSSFCellStyle.ALIGN_CENTER, cellStyle.getAlignment());
+        assertEquals(HorizontalAlignment.CENTER, cellStyle.getAlignmentEnum());
+        assertEquals(STHorizontalAlignment.CENTER, cellStyle.getCellAlignment().getCTCellAlignment().getHorizontal());
+    }
+
+    public void testGetSetVerticalAlignment() {
+        assertEquals(VerticalAlignment.BOTTOM, cellStyle.getVerticalAlignmentEnum());
+        assertEquals(XSSFCellStyle.VERTICAL_BOTTOM, cellStyle.getVerticalAlignment());
+        assertNull(cellStyle.getCellAlignment().getCTCellAlignment().getVertical());
+
+        cellStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);
+        assertEquals(XSSFCellStyle.VERTICAL_CENTER, cellStyle.getVerticalAlignment());
+        assertEquals(VerticalAlignment.CENTER, cellStyle.getVerticalAlignmentEnum());
+        assertEquals(STVerticalAlignment.CENTER, cellStyle.getCellAlignment().getCTCellAlignment().getVertical());
+
+        cellStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_JUSTIFY);
+        assertEquals(XSSFCellStyle.VERTICAL_JUSTIFY, cellStyle.getVerticalAlignment());
+        assertEquals(VerticalAlignment.JUSTIFY, cellStyle.getVerticalAlignmentEnum());
+        assertEquals(STVerticalAlignment.JUSTIFY, cellStyle.getCellAlignment().getCTCellAlignment().getVertical());
+    }
+
+    public void testGetSetWrapText() {
+        assertFalse(cellStyle.getWrapText());
+        cellXf.getAlignment().setWrapText(true);
+        assertTrue(cellStyle.getWrapText());
+        cellStyle.setWrapText(false);
+        assertFalse(cellXf.getAlignment().getWrapText());
+    }
+
+    /**
+     * Cloning one XSSFCellStyle onto Another, same XSSFWorkbook
+     */
+    public void testCloneStyleSameWB() throws Exception {
+        // TODO
+    }
+    /**
+     * Cloning one XSSFCellStyle onto Another, different XSSFWorkbooks
+     */
+    public void testCloneStyleDiffWB() throws Exception {
+        // TODO
+    }
 }