Added fill example and added fill constants

git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352135 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Glen Stampoultzis 2002-03-03 09:27:13 +00:00
parent 939b8dd089
commit 14f47e5567
3 changed files with 224 additions and 10 deletions

View File

@ -0,0 +1,100 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hssf.usermodel.examples;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.HSSFColor;
import java.io.FileOutputStream;
import java.io.IOException;
/**
* Shows how to use various fills.
*
* @author Glen Stampoultzis (glens at apache.org)
*/
public class FrillsAndFills
{
public static void main(String[] args)
throws IOException
{
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
// Create a row and put some cells in it. Rows are 0 based.
HSSFRow row = sheet.createRow((short) 1);
// Aqua background
HSSFCellStyle style = wb.createCellStyle();
style.setFillBackgroundColor(HSSFColor.AQUA.index);
style.setFillPattern(HSSFCellStyle.BIG_SPOTS);
HSSFCell cell = row.createCell((short) 1);
cell.setCellValue("X");
cell.setCellStyle(style);
// Orange "foreground", foreground being the fill foreground not the font color.
style = wb.createCellStyle();
style.setFillForegroundColor(HSSFColor.ORANGE.index);
style.setFillPattern(HSSFCellStyle.SOLID_FILL);
cell = row.createCell((short) 2);
cell.setCellValue("X");
cell.setCellStyle(style);
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
}
}

View File

@ -80,7 +80,7 @@ public class ExtendedFormatRecord
public final static short sid = 0xE0;
// null constant
public final static short NULL = 0xfffffff0;
public final static short NULL = (short)0xfff0;
// xf type
public final static short XF_STYLE = 1;
@ -117,6 +117,25 @@ public class ExtendedFormatRecord
public final static short VERTICAL_BOTTOM = 0x2;
public final static short VERTICAL_JUSTIFY = 0x3;
// fill
public final static short NO_FILL = 0 ;
public final static short SOLID_FILL = 1 ;
public final static short FINE_DOTS = 2 ;
public final static short ALT_BARS = 3 ;
public final static short SPARSE_DOTS = 4 ;
public final static short THICK_HORZ_BANDS = 5 ;
public final static short THICK_VERT_BANDS = 6 ;
public final static short THICK_BACKWARD_DIAG = 7 ;
public final static short THICK_FORWARD_DIAG = 8 ;
public final static short BIG_SPOTS = 9 ;
public final static short BRICKS = 10 ;
public final static short THIN_HORZ_BANDS = 11 ;
public final static short THIN_VERT_BANDS = 12 ;
public final static short THIN_BACKWARD_DIAG = 13 ;
public final static short THIN_FORWARD_DIAG = 14 ;
public final static short SQUARES = 15 ;
public final static short DIAMONDS = 16 ;
// fields in BOTH style and Cell XF records
private short field_1_font_index; // not bit-mapped
private short field_2_format_index; // not bit-mapped
@ -374,7 +393,7 @@ public class ExtendedFormatRecord
* for cell XF types this is the parent style (usually 0/normal). For
* style this should be NULL.
*
* @param index of parent XF
* @param parent index of parent XF
* @see #NULL
* @see #setCellOptions(short)
*/
@ -439,7 +458,7 @@ public class ExtendedFormatRecord
* set the vertical alignment of text in the cell
*
*
* @param where to align the text
* @param align where to align the text
* @see #VERTICAL_TOP
* @see #VERTICAL_CENTER
* @see #VERTICAL_BOTTOM
@ -938,8 +957,25 @@ public class ExtendedFormatRecord
}
/**
* set the fill pattern - ???
* set the fill pattern
*
* @see #NO_FILL
* @see #SOLID_FILL
* @see #FINE_DOTS
* @see #ALT_BARS
* @see #SPARSE_DOTS
* @see #THICK_HORZ_BANDS
* @see #THICK_VERT_BANDS
* @see #THICK_BACKWARD_DIAG
* @see #THICK_FORWARD_DIAG
* @see #BIG_SPOTS
* @see #BRICKS
* @see #THIN_HORZ_BANDS
* @see #THIN_VERT_BANDS
* @see #THIN_BACKWARD_DIAG
* @see #THIN_FORWARD_DIAG
* @see #SQUARES
* @see #DIAMONDS
*
* @param fill - fill pattern??
* @see #setAdtlPaletteOptions(short)
@ -1633,8 +1669,25 @@ public class ExtendedFormatRecord
}
/**
* get the additional fill pattern - ???
* get the additional fill pattern
*
* @see #NO_FILL
* @see #SOLID_FILL
* @see #FINE_DOTS
* @see #ALT_BARS
* @see #SPARSE_DOTS
* @see #THICK_HORZ_BANDS
* @see #THICK_VERT_BANDS
* @see #THICK_BACKWARD_DIAG
* @see #THICK_FORWARD_DIAG
* @see #BIG_SPOTS
* @see #BRICKS
* @see #THIN_HORZ_BANDS
* @see #THIN_VERT_BANDS
* @see #THIN_BACKWARD_DIAG
* @see #THIN_FORWARD_DIAG
* @see #SQUARES
* @see #DIAMONDS
*
* @return fill - fill pattern??
* @see #getAdtlPaletteOptions()
@ -1680,8 +1733,7 @@ public class ExtendedFormatRecord
/**
* get the background palette color index
*
*
* @param color - palette index
* @retyrb color palette index
* @see #getFillPaletteOptions()
*/

View File

@ -230,6 +230,42 @@ public class HSSFCellStyle
public final static short BORDER_SLANTED_DASH_DOT = 0xD;
/** No background */
public final static short NO_FILL = 0 ;
/** Solidly filled */
public final static short SOLID_FILL = 1 ;
/** Small fine dots */
public final static short FINE_DOTS = 2 ;
/** Wide dots */
public final static short ALT_BARS = 3 ;
/** Sparse dots */
public final static short SPARSE_DOTS = 4 ;
/** Thick horizontal bands */
public final static short THICK_HORZ_BANDS = 5 ;
/** Thick vertical bands */
public final static short THICK_VERT_BANDS = 6 ;
/** Thick backward facing diagonals */
public final static short THICK_BACKWARD_DIAG = 7 ;
/** Thick forward facing diagonals */
public final static short THICK_FORWARD_DIAG = 8 ;
/** Large spots */
public final static short BIG_SPOTS = 9 ;
/** Brick-like layout */
public final static short BRICKS = 10 ;
/** Thin horizontal bands */
public final static short THIN_HORZ_BANDS = 11 ;
/** Thin vertical bands */
public final static short THIN_VERT_BANDS = 12 ;
/** Thin backward diagonal */
public final static short THIN_BACKWARD_DIAG = 13 ;
/** Thin forward diagonal */
public final static short THIN_FORWARD_DIAG = 14 ;
/** Squares */
public final static short SQUARES = 15 ;
/** Diamonds */
public final static short DIAMONDS = 16 ;
/** Creates new HSSFCellStyle why would you want to do this?? */
protected HSSFCellStyle(short index, ExtendedFormatRecord rec)
@ -755,9 +791,27 @@ public class HSSFCellStyle
/**
* setting to one fills the cell with the foreground color... No idea about
* other values
* @param fp fill pattern (set to 1 to fill w/foreground color
*
* @see #NO_FILL
* @see #SOLID_FILL
* @see #FINE_DOTS
* @see #ALT_BARS
* @see #SPARSE_DOTS
* @see #THICK_HORZ_BANDS
* @see #THICK_VERT_BANDS
* @see #THICK_BACKWARD_DIAG
* @see #THICK_FORWARD_DIAG
* @see #BIG_SPOTS
* @see #BRICKS
* @see #THIN_HORZ_BANDS
* @see #THIN_VERT_BANDS
* @see #THIN_BACKWARD_DIAG
* @see #THIN_FORWARD_DIAG
* @see #SQUARES
* @see #DIAMONDS
*
* @param fp fill pattern (set to 1 to fill w/foreground color)
*/
public void setFillPattern(short fp)
{
format.setAdtlFillPattern(fp);
@ -774,7 +828,15 @@ public class HSSFCellStyle
}
/**
* set the background fill color
* set the background fill color.
* <p>
* For example:
* <pre>
* cs.setFillPattern( (short) 1 );
* cs.setFillBackgroundColor(HSSFColor.RED.index);
* </pre>
* You will need to set the fill style first.
*
* @param bg color
*/