poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject svn commit: r645234 - in /poi/branches/ooxml/src/ooxml: java/org/apache/poi/xssf/model/ java/org/apache/poi/xssf/usermodel/ java/org/apache/poi/xssf/usermodel/extensions/ testcases/org/apache/poi/xssf/usermodel/
Date Sun, 06 Apr 2008 13:05:15 GMT
Author: paolo
Date: Sun Apr  6 06:05:13 2008
New Revision: 645234

URL: http://svn.apache.org/viewvc?rev=645234&view=rev
Log:
Completed StylesTable initialization in order to create a new 'POIzed' file readable by Excel

Modified:
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellBorder.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellFill.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFColor.java
    poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java?rev=645234&r1=645233&r2=645234&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java Sun Apr 
6 06:05:13 2008
@@ -35,15 +35,19 @@
 import org.apache.xmlbeans.XmlException;
 import org.apache.xmlbeans.XmlOptions;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorders;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellStyleXfs;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellXfs;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFills;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFonts;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTNumFmt;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTNumFmts;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTStylesheet;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.STFontScheme;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPatternType;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.StyleSheetDocument;
 
 
@@ -84,16 +88,8 @@
     public StylesTable() {
     	doc = StyleSheetDocument.Factory.newInstance();
     	doc.addNewStyleSheet();
-    	
-    	// Add a single, default cell xf and cell style xf
-    	// Excel seems to require these
-    	CTXf[] ctxfs = new CTXf[2];
-    	for (int i = 0; i < ctxfs.length; i++) {
-			ctxfs[i] = CTXf.Factory.newInstance(); 
-			ctxfs[i].setNumFmtId(0);
-		}
-    	xfs.add(ctxfs[0]);
-    	styleXfs.add(ctxfs[1]);
+    	// Initialization required in order to make the document readable by MSExcel
+    	initialize();
     }
 
     /**
@@ -279,18 +275,24 @@
     	doc.getStyleSheet().setNumFmts(formats);
     	
     	// Fonts
-    	CTFonts fnts = CTFonts.Factory.newInstance();
-    	fnts.setCount(fonts.size());
-    	fnts.setFontArray(
+    	CTFonts ctFonts = CTFonts.Factory.newInstance();
+    	ctFonts.setCount(fonts.size());
+    	ctFonts.setFontArray(
     			fonts.toArray(new CTFont[fonts.size()])
     	);
-    	doc.getStyleSheet().setFonts(fnts);
+    	doc.getStyleSheet().setFonts(ctFonts);
     	
     	// Fills
-    	// TODO
+    	CTFills ctFills = CTFills.Factory.newInstance();
+    	ctFills.setCount(fills.size());
+    	ctFills.setFillArray(fills.toArray(new CTFill[fills.size()]));
+    	doc.getStyleSheet().setFills(ctFills);
     	
     	// Borders
-    	// TODO
+    	CTBorders ctBorders = CTBorders.Factory.newInstance();
+    	ctBorders.setCount(borders.size());
+    	ctBorders.setBorderArray(borders.toArray(new CTBorder[borders.size()]));
+    	doc.getStyleSheet().setBorders(ctBorders);
     	
     	// Xfs
     	if(xfs.size() > 0) {
@@ -326,5 +328,52 @@
 
     private long putFont(XSSFFont font, LinkedList<CTFont> fonts) {
     	return font.putFont(fonts);
+	}
+	private void initialize() {
+		CTFont ctFont = createDefaultFont();
+    	fonts.add(ctFont);
+    	
+    	CTFill ctFill = createDefaultFill();
+    	fills.add(ctFill);
+    	
+    	CTBorder ctBorder = createDefaultBorder();
+    	borders.add(ctBorder);
+    	
+    	CTXf styleXf = createDefaultXf();
+    	styleXfs.add(styleXf);
+    	CTXf xf = createDefaultXf();
+    	xf.setXfId(0);
+    	xfs.add(xf);
+	}
+	private CTXf createDefaultXf() {
+		CTXf ctXf = CTXf.Factory.newInstance();
+    	ctXf.setNumFmtId(0);
+    	ctXf.setFontId(0);
+    	ctXf.setFillId(0);
+    	ctXf.setBorderId(0);
+    	return ctXf;
+	}
+	private CTBorder createDefaultBorder() {
+		CTBorder ctBorder = CTBorder.Factory.newInstance();
+    	ctBorder.addNewBottom();
+    	ctBorder.addNewTop();
+    	ctBorder.addNewLeft();
+    	ctBorder.addNewRight();
+    	ctBorder.addNewDiagonal();
+		return ctBorder;
+	}
+	private CTFill createDefaultFill() {
+		CTFill ctFill = CTFill.Factory.newInstance();
+    	ctFill.addNewPatternFill().setPatternType(STPatternType.NONE);
+		return ctFill;
+	}
+	private CTFont createDefaultFont() {
+		CTFont ctFont = CTFont.Factory.newInstance();
+    	ctFont.addNewSz().setVal(11);
+    	ctFont.addNewColor().setTheme(1);
+    	ctFont.addNewName().setVal("Calibri");
+    	ctFont.addNewFamily().setVal(2);
+    	ctFont.addNewScheme().setVal(STFontScheme.MINOR);
+		return ctFont;
 	}
 }

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java?rev=645234&r1=645233&r2=645234&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java Sun
Apr  6 06:05:13 2008
@@ -33,7 +33,6 @@
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.STBorderStyle;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.STHorizontalAlignment;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.STVerticalAlignment;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STVerticalAlignment.Enum;
 
 
 public class XSSFCellStyle implements CellStyle {
@@ -313,6 +312,14 @@
 		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
@@ -372,10 +379,6 @@
 
 	private short getBorderColorIndexed(BorderSide side) {
 		return (short) getBorderColor(side).getIndexed();
-	}
-
-	private XSSFColor getBorderColor(BorderSide side) {
-		return getCellBorder().getBorderColor(side);
 	}
 	
 	private void setBorderColorIndexed(BorderSide side, long color) {

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellBorder.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellBorder.java?rev=645234&r1=645233&r2=645234&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellBorder.java
(original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellBorder.java
Sun Apr  6 06:05:13 2008
@@ -22,7 +22,6 @@
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorderPr;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.STBorderStyle;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STBorderStyle.Enum;
 
 
 public class XSSFCellBorder {
@@ -68,6 +67,10 @@
 			borderPr.addNewColor();
 		}
 		return new XSSFColor(getBorder(side).getColor());
+	}
+
+	public void setBorderColor(BorderSide side, XSSFColor color) {
+		color.setToBorder(getBorder(side));
 	}
 	
 	private CTBorderPr getBorder(BorderSide side) {

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellFill.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellFill.java?rev=645234&r1=645233&r2=645234&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellFill.java
(original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellFill.java
Sun Apr  6 06:05:13 2008
@@ -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.extensions;
 
 import java.util.LinkedList;

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFColor.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFColor.java?rev=645234&r1=645233&r2=645234&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFColor.java
(original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFColor.java
Sun Apr  6 06:05:13 2008
@@ -16,6 +16,7 @@
 ==================================================================== */
 package org.apache.poi.xssf.usermodel.extensions;
 
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorderPr;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
 
 public class XSSFColor {
@@ -64,5 +65,9 @@
 	
 	public void setTint(double tint) {
 		color.setTint(tint);
+	}
+
+	public void setToBorder(CTBorderPr border) {
+		border.setColor(this.color);
 	}
 }

Modified: poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java?rev=645234&r1=645233&r2=645234&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java
(original)
+++ poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java
Sun Apr  6 06:05:13 2008
@@ -22,6 +22,8 @@
 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.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellXfs;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
@@ -134,6 +136,66 @@
 	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() {



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message