2008-03-13 07:50:50 -04:00
/ * = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
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 ;
2010-09-20 16:10:14 -04:00
import org.apache.poi.POIXMLException ;
2009-11-03 18:02:06 -05:00
import org.apache.poi.ss.usermodel.BorderStyle ;
import org.apache.poi.ss.usermodel.CellStyle ;
import org.apache.poi.ss.usermodel.FillPatternType ;
import org.apache.poi.ss.usermodel.Font ;
import org.apache.poi.ss.usermodel.HorizontalAlignment ;
import org.apache.poi.ss.usermodel.IndexedColors ;
import org.apache.poi.ss.usermodel.VerticalAlignment ;
2010-05-26 13:46:46 -04:00
import org.apache.poi.util.Internal ;
2008-03-16 20:10:17 -04:00
import org.apache.poi.xssf.model.StylesTable ;
2010-05-19 07:55:17 -04:00
import org.apache.poi.xssf.model.ThemesTable ;
2008-04-05 12:19:56 -04:00
import org.apache.poi.xssf.usermodel.extensions.XSSFCellAlignment ;
2008-03-13 07:50:50 -04:00
import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder ;
2008-04-05 13:35:28 -04:00
import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder.BorderSide ;
2013-11-07 17:28:06 -05:00
import org.apache.poi.xssf.usermodel.extensions.XSSFCellFill ;
2010-09-20 16:10:14 -04:00
import org.apache.xmlbeans.XmlException ;
2009-11-03 18:02:06 -05:00
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder ;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorderPr ;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellAlignment ;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill ;
2010-09-20 16:10:14 -04:00
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont ;
2009-11-03 18:02:06 -05:00
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPatternFill ;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf ;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STBorderStyle ;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPatternType ;
2008-03-13 07:50:50 -04:00
2008-10-05 09:56:28 -04:00
/ * *
*
* High level representation of the the possible formatting information for the contents of the cells on a sheet in a
* SpreadsheetML document .
*
* @see org . apache . poi . xssf . usermodel . XSSFWorkbook # createCellStyle ( )
* @see org . apache . poi . xssf . usermodel . XSSFWorkbook # getCellStyleAt ( short )
* @see org . apache . poi . xssf . usermodel . XSSFCell # setCellStyle ( org . apache . poi . ss . usermodel . CellStyle )
* /
2008-10-29 15:12:47 -04:00
public class XSSFCellStyle implements CellStyle {
2008-09-15 06:39:37 -04:00
2009-08-18 12:50:24 -04:00
private int _cellXfId ;
private StylesTable _stylesSource ;
private CTXf _cellXf ;
private CTXf _cellStyleXf ;
private XSSFFont _font ;
private XSSFCellAlignment _cellAlignment ;
2010-05-19 07:55:17 -04:00
private ThemesTable _theme ;
2008-09-15 06:39:37 -04:00
/ * *
* Creates a Cell Style from the supplied parts
2011-12-19 04:06:10 -05:00
* @param cellXfId The main XF for the cell . Must be a valid 0 - based index into the XF table
* @param cellStyleXfId Optional , style xf . A value of < code > - 1 < / code > means no xf .
2008-09-15 06:39:37 -04:00
* @param stylesSource Styles Source to work off
* /
2010-05-19 07:55:17 -04:00
public XSSFCellStyle ( int cellXfId , int cellStyleXfId , StylesTable stylesSource , ThemesTable theme ) {
2009-08-18 12:50:24 -04:00
_cellXfId = cellXfId ;
_stylesSource = stylesSource ;
_cellXf = stylesSource . getCellXfAt ( this . _cellXfId ) ;
2011-12-19 04:06:10 -05:00
_cellStyleXf = cellStyleXfId = = - 1 ? null : stylesSource . getCellStyleXfAt ( cellStyleXfId ) ;
2010-05-19 07:55:17 -04:00
_theme = theme ;
2008-09-15 06:39:37 -04:00
}
/ * *
* Used so that StylesSource can figure out our location
* /
2009-12-03 11:50:34 -05:00
@Internal
2008-09-15 06:39:37 -04:00
public CTXf getCoreXf ( ) {
2009-08-18 12:50:24 -04:00
return _cellXf ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
2008-09-15 06:39:37 -04:00
/ * *
* Used so that StylesSource can figure out our location
* /
2009-12-03 11:50:34 -05:00
@Internal
2008-09-15 06:39:37 -04:00
public CTXf getStyleXf ( ) {
2009-08-18 12:50:24 -04:00
return _cellStyleXf ;
2008-09-15 06:39:37 -04:00
}
/ * *
* Creates an empty Cell Style
* /
2008-10-25 07:48:50 -04:00
public XSSFCellStyle ( StylesTable stylesSource ) {
2009-08-18 12:50:24 -04:00
_stylesSource = stylesSource ;
2008-09-15 06:39:37 -04:00
// We need a new CTXf for the main styles
// TODO decide on a style ctxf
2009-08-18 12:50:24 -04:00
_cellXf = CTXf . Factory . newInstance ( ) ;
_cellStyleXf = null ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
2008-09-15 06:39:37 -04:00
/ * *
* 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
* /
2008-10-25 07:48:50 -04:00
public void verifyBelongsToStylesSource ( StylesTable src ) {
2009-08-18 12:50:24 -04:00
if ( this . _stylesSource ! = src ) {
2008-09-15 06:39:37 -04:00
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? " ) ;
}
}
Merged revisions 638786-638802,638805-638811,638813-638814,638816-639230,639233-639241,639243-639253,639255-639486,639488-639601,639603-639835,639837-639917,639919-640056,640058-640710,640712-641156,641158-641184,641186-641795,641797-641798,641800-641933,641935-641963,641965-641966,641968-641995,641997-642230,642232-642562,642564-642565,642568-642570,642572-642573,642576-642736,642739-642877,642879,642881-642890,642892-642903,642905-642945,642947-643624,643626-643653,643655-643669,643671,643673-643830,643832-643833,643835-644342,644344-644472,644474-644508,644510-645347,645349-645351,645353-645559,645561-645565,645568-645951,645953-646193,646195-646311,646313-646404,646406-646665,646667-646853,646855-646869,646871-647151,647153-647185,647187-647277,647279-647566,647568-647573,647575,647578-647711,647714-647737,647739-647823,647825-648155,648157-648202,648204-648273,648275,648277-648302,648304-648333,648335-648588,648590-648622,648625-648673,648675-649141,649144,649146-649556,649558-649795,649799,649801-649910,649912-649913,649915-650128,650131-650132,650134-650137,650140-650914,650916-651991,651993-652284,652286-652287,652289,652291,652293-652297,652299-652328,652330-652425,652427-652445,652447-652560,652562-652933,652935,652937-652993,652995-653116,653118-653124,653126-653483,653487-653519,653522-653550,653552-653607,653609-653667,653669-653674,653676-653814,653817-653830,653832-653891,653893-653944,653946-654055,654057-654355,654357-654365,654367-654648,654651-655215,655217-655277,655279-655281,655283-655911,655913-656212,656214,656216-656251,656253-656698,656700-656756,656758-656892,656894-657135,657137-657165,657168-657179,657181-657354,657356-657357,657359-657701,657703-657874,657876-658032,658034-658284,658286,658288-658301,658303-658307,658309-658321,658323-658335,658337-658348,658351,658353-658832,658834-658983,658985,658987-659066,659068-659402,659404-659428,659430-659451,659453-659454,659456-659461,659463-659477,659479-659524,659526-659571,659574,659576-660255,660257-660262,660264-660279,660281-660343,660345-660473,660475-660827,660829-660833,660835-660888,660890-663321,663323-663435,663437-663764,663766-663854,663856-664219,664221-664489,664494-664514,664516-668013,668015-668142,668144-668152,668154,668156-668256,668258,668260-669139,669141-669455,669457-669657,669659-669808,669810-670189,670191-671321,671323-672229,672231-672549,672551-672552,672554-672561,672563-672566,672568,672571-673049,673051-673852,673854-673862,673864-673986,673988-673996,673998-674347,674349-674890,674892-674910,674912-674936,674938-674952,674954-675078,675080-675085,675087-675217,675219-675660,675662-675670,675672-675716,675718-675726,675728-675733,675735-675775,675777-675782,675784,675786-675791,675794-676205 via svnmerge from
https://svn.apache.org:443/repos/asf/poi/trunk
........
r675853 | josh | 2008-07-11 08:59:44 +0100 (Fri, 11 Jul 2008) | 1 line
Patch 45289 - finished support for special comparison operators in COUNTIF
........
r676201 | nick | 2008-07-12 17:56:55 +0100 (Sat, 12 Jul 2008) | 1 line
Support for cloning one font record onto another, plus tests
........
r676203 | nick | 2008-07-12 18:21:54 +0100 (Sat, 12 Jul 2008) | 1 line
Support for cloning one extended format record onto another, plus tests
........
r676205 | nick | 2008-07-12 18:38:10 +0100 (Sat, 12 Jul 2008) | 1 line
Allow the cloning of one HSSFCellStyle onto another, including cloning styles from one HSSFWorkbook onto another
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@676209 13f79535-47bb-0310-9956-ffa450edef68
2008-07-12 14:17:16 -04:00
/ * *
* Clones all the style information from another
2008-09-15 06:39:37 -04:00
* XSSFCellStyle , onto this one . This
Merged revisions 638786-638802,638805-638811,638813-638814,638816-639230,639233-639241,639243-639253,639255-639486,639488-639601,639603-639835,639837-639917,639919-640056,640058-640710,640712-641156,641158-641184,641186-641795,641797-641798,641800-641933,641935-641963,641965-641966,641968-641995,641997-642230,642232-642562,642564-642565,642568-642570,642572-642573,642576-642736,642739-642877,642879,642881-642890,642892-642903,642905-642945,642947-643624,643626-643653,643655-643669,643671,643673-643830,643832-643833,643835-644342,644344-644472,644474-644508,644510-645347,645349-645351,645353-645559,645561-645565,645568-645951,645953-646193,646195-646311,646313-646404,646406-646665,646667-646853,646855-646869,646871-647151,647153-647185,647187-647277,647279-647566,647568-647573,647575,647578-647711,647714-647737,647739-647823,647825-648155,648157-648202,648204-648273,648275,648277-648302,648304-648333,648335-648588,648590-648622,648625-648673,648675-649141,649144,649146-649556,649558-649795,649799,649801-649910,649912-649913,649915-650128,650131-650132,650134-650137,650140-650914,650916-651991,651993-652284,652286-652287,652289,652291,652293-652297,652299-652328,652330-652425,652427-652445,652447-652560,652562-652933,652935,652937-652993,652995-653116,653118-653124,653126-653483,653487-653519,653522-653550,653552-653607,653609-653667,653669-653674,653676-653814,653817-653830,653832-653891,653893-653944,653946-654055,654057-654355,654357-654365,654367-654648,654651-655215,655217-655277,655279-655281,655283-655911,655913-656212,656214,656216-656251,656253-656698,656700-656756,656758-656892,656894-657135,657137-657165,657168-657179,657181-657354,657356-657357,657359-657701,657703-657874,657876-658032,658034-658284,658286,658288-658301,658303-658307,658309-658321,658323-658335,658337-658348,658351,658353-658832,658834-658983,658985,658987-659066,659068-659402,659404-659428,659430-659451,659453-659454,659456-659461,659463-659477,659479-659524,659526-659571,659574,659576-660255,660257-660262,660264-660279,660281-660343,660345-660473,660475-660827,660829-660833,660835-660888,660890-663321,663323-663435,663437-663764,663766-663854,663856-664219,664221-664489,664494-664514,664516-668013,668015-668142,668144-668152,668154,668156-668256,668258,668260-669139,669141-669455,669457-669657,669659-669808,669810-670189,670191-671321,671323-672229,672231-672549,672551-672552,672554-672561,672563-672566,672568,672571-673049,673051-673852,673854-673862,673864-673986,673988-673996,673998-674347,674349-674890,674892-674910,674912-674936,674938-674952,674954-675078,675080-675085,675087-675217,675219-675660,675662-675670,675672-675716,675718-675726,675728-675733,675735-675775,675777-675782,675784,675786-675791,675794-676205 via svnmerge from
https://svn.apache.org:443/repos/asf/poi/trunk
........
r675853 | josh | 2008-07-11 08:59:44 +0100 (Fri, 11 Jul 2008) | 1 line
Patch 45289 - finished support for special comparison operators in COUNTIF
........
r676201 | nick | 2008-07-12 17:56:55 +0100 (Sat, 12 Jul 2008) | 1 line
Support for cloning one font record onto another, plus tests
........
r676203 | nick | 2008-07-12 18:21:54 +0100 (Sat, 12 Jul 2008) | 1 line
Support for cloning one extended format record onto another, plus tests
........
r676205 | nick | 2008-07-12 18:38:10 +0100 (Sat, 12 Jul 2008) | 1 line
Allow the cloning of one HSSFCellStyle onto another, including cloning styles from one HSSFWorkbook onto another
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@676209 13f79535-47bb-0310-9956-ffa450edef68
2008-07-12 14:17:16 -04:00
* XSSFCellStyle will then have all the same
* properties as the source , but the two may
* be edited independently .
2008-09-15 06:39:37 -04:00
* Any stylings on this XSSFCellStyle will be lost !
*
Merged revisions 638786-638802,638805-638811,638813-638814,638816-639230,639233-639241,639243-639253,639255-639486,639488-639601,639603-639835,639837-639917,639919-640056,640058-640710,640712-641156,641158-641184,641186-641795,641797-641798,641800-641933,641935-641963,641965-641966,641968-641995,641997-642230,642232-642562,642564-642565,642568-642570,642572-642573,642576-642736,642739-642877,642879,642881-642890,642892-642903,642905-642945,642947-643624,643626-643653,643655-643669,643671,643673-643830,643832-643833,643835-644342,644344-644472,644474-644508,644510-645347,645349-645351,645353-645559,645561-645565,645568-645951,645953-646193,646195-646311,646313-646404,646406-646665,646667-646853,646855-646869,646871-647151,647153-647185,647187-647277,647279-647566,647568-647573,647575,647578-647711,647714-647737,647739-647823,647825-648155,648157-648202,648204-648273,648275,648277-648302,648304-648333,648335-648588,648590-648622,648625-648673,648675-649141,649144,649146-649556,649558-649795,649799,649801-649910,649912-649913,649915-650128,650131-650132,650134-650137,650140-650914,650916-651991,651993-652284,652286-652287,652289,652291,652293-652297,652299-652328,652330-652425,652427-652445,652447-652560,652562-652933,652935,652937-652993,652995-653116,653118-653124,653126-653483,653487-653519,653522-653550,653552-653607,653609-653667,653669-653674,653676-653814,653817-653830,653832-653891,653893-653944,653946-654055,654057-654355,654357-654365,654367-654648,654651-655215,655217-655277,655279-655281,655283-655911,655913-656212,656214,656216-656251,656253-656698,656700-656756,656758-656892,656894-657135,657137-657165,657168-657179,657181-657354,657356-657357,657359-657701,657703-657874,657876-658032,658034-658284,658286,658288-658301,658303-658307,658309-658321,658323-658335,658337-658348,658351,658353-658832,658834-658983,658985,658987-659066,659068-659402,659404-659428,659430-659451,659453-659454,659456-659461,659463-659477,659479-659524,659526-659571,659574,659576-660255,660257-660262,660264-660279,660281-660343,660345-660473,660475-660827,660829-660833,660835-660888,660890-663321,663323-663435,663437-663764,663766-663854,663856-664219,664221-664489,664494-664514,664516-668013,668015-668142,668144-668152,668154,668156-668256,668258,668260-669139,669141-669455,669457-669657,669659-669808,669810-670189,670191-671321,671323-672229,672231-672549,672551-672552,672554-672561,672563-672566,672568,672571-673049,673051-673852,673854-673862,673864-673986,673988-673996,673998-674347,674349-674890,674892-674910,674912-674936,674938-674952,674954-675078,675080-675085,675087-675217,675219-675660,675662-675670,675672-675716,675718-675726,675728-675733,675735-675775,675777-675782,675784,675786-675791,675794-676205 via svnmerge from
https://svn.apache.org:443/repos/asf/poi/trunk
........
r675853 | josh | 2008-07-11 08:59:44 +0100 (Fri, 11 Jul 2008) | 1 line
Patch 45289 - finished support for special comparison operators in COUNTIF
........
r676201 | nick | 2008-07-12 17:56:55 +0100 (Sat, 12 Jul 2008) | 1 line
Support for cloning one font record onto another, plus tests
........
r676203 | nick | 2008-07-12 18:21:54 +0100 (Sat, 12 Jul 2008) | 1 line
Support for cloning one extended format record onto another, plus tests
........
r676205 | nick | 2008-07-12 18:38:10 +0100 (Sat, 12 Jul 2008) | 1 line
Allow the cloning of one HSSFCellStyle onto another, including cloning styles from one HSSFWorkbook onto another
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@676209 13f79535-47bb-0310-9956-ffa450edef68
2008-07-12 14:17:16 -04:00
* The source XSSFCellStyle could be from another
* XSSFWorkbook if you like . This allows you to
* copy styles from one XSSFWorkbook to another .
* /
2015-08-20 10:28:39 -04:00
@Override
Merged revisions 638786-638802,638805-638811,638813-638814,638816-639230,639233-639241,639243-639253,639255-639486,639488-639601,639603-639835,639837-639917,639919-640056,640058-640710,640712-641156,641158-641184,641186-641795,641797-641798,641800-641933,641935-641963,641965-641966,641968-641995,641997-642230,642232-642562,642564-642565,642568-642570,642572-642573,642576-642736,642739-642877,642879,642881-642890,642892-642903,642905-642945,642947-643624,643626-643653,643655-643669,643671,643673-643830,643832-643833,643835-644342,644344-644472,644474-644508,644510-645347,645349-645351,645353-645559,645561-645565,645568-645951,645953-646193,646195-646311,646313-646404,646406-646665,646667-646853,646855-646869,646871-647151,647153-647185,647187-647277,647279-647566,647568-647573,647575,647578-647711,647714-647737,647739-647823,647825-648155,648157-648202,648204-648273,648275,648277-648302,648304-648333,648335-648588,648590-648622,648625-648673,648675-649141,649144,649146-649556,649558-649795,649799,649801-649910,649912-649913,649915-650128,650131-650132,650134-650137,650140-650914,650916-651991,651993-652284,652286-652287,652289,652291,652293-652297,652299-652328,652330-652425,652427-652445,652447-652560,652562-652933,652935,652937-652993,652995-653116,653118-653124,653126-653483,653487-653519,653522-653550,653552-653607,653609-653667,653669-653674,653676-653814,653817-653830,653832-653891,653893-653944,653946-654055,654057-654355,654357-654365,654367-654648,654651-655215,655217-655277,655279-655281,655283-655911,655913-656212,656214,656216-656251,656253-656698,656700-656756,656758-656892,656894-657135,657137-657165,657168-657179,657181-657354,657356-657357,657359-657701,657703-657874,657876-658032,658034-658284,658286,658288-658301,658303-658307,658309-658321,658323-658335,658337-658348,658351,658353-658832,658834-658983,658985,658987-659066,659068-659402,659404-659428,659430-659451,659453-659454,659456-659461,659463-659477,659479-659524,659526-659571,659574,659576-660255,660257-660262,660264-660279,660281-660343,660345-660473,660475-660827,660829-660833,660835-660888,660890-663321,663323-663435,663437-663764,663766-663854,663856-664219,664221-664489,664494-664514,664516-668013,668015-668142,668144-668152,668154,668156-668256,668258,668260-669139,669141-669455,669457-669657,669659-669808,669810-670189,670191-671321,671323-672229,672231-672549,672551-672552,672554-672561,672563-672566,672568,672571-673049,673051-673852,673854-673862,673864-673986,673988-673996,673998-674347,674349-674890,674892-674910,674912-674936,674938-674952,674954-675078,675080-675085,675087-675217,675219-675660,675662-675670,675672-675716,675718-675726,675728-675733,675735-675775,675777-675782,675784,675786-675791,675794-676205 via svnmerge from
https://svn.apache.org:443/repos/asf/poi/trunk
........
r675853 | josh | 2008-07-11 08:59:44 +0100 (Fri, 11 Jul 2008) | 1 line
Patch 45289 - finished support for special comparison operators in COUNTIF
........
r676201 | nick | 2008-07-12 17:56:55 +0100 (Sat, 12 Jul 2008) | 1 line
Support for cloning one font record onto another, plus tests
........
r676203 | nick | 2008-07-12 18:21:54 +0100 (Sat, 12 Jul 2008) | 1 line
Support for cloning one extended format record onto another, plus tests
........
r676205 | nick | 2008-07-12 18:38:10 +0100 (Sat, 12 Jul 2008) | 1 line
Allow the cloning of one HSSFCellStyle onto another, including cloning styles from one HSSFWorkbook onto another
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@676209 13f79535-47bb-0310-9956-ffa450edef68
2008-07-12 14:17:16 -04:00
public void cloneStyleFrom ( CellStyle source ) {
2008-09-15 06:39:37 -04:00
if ( source instanceof XSSFCellStyle ) {
2009-04-20 14:04:37 -04:00
XSSFCellStyle src = ( XSSFCellStyle ) source ;
2015-08-20 10:28:39 -04:00
2010-09-20 16:10:14 -04:00
// Is it on our Workbook?
if ( src . _stylesSource = = _stylesSource ) {
// Nice and easy
_cellXf . set ( src . getCoreXf ( ) ) ;
_cellStyleXf . set ( src . getStyleXf ( ) ) ;
} else {
// Copy the style
try {
2011-04-21 09:22:18 -04:00
// Remove any children off the current style, to
// avoid orphaned nodes
if ( _cellXf . isSetAlignment ( ) )
_cellXf . unsetAlignment ( ) ;
if ( _cellXf . isSetExtLst ( ) )
_cellXf . unsetExtLst ( ) ;
2015-08-20 10:28:39 -04:00
2011-04-21 09:22:18 -04:00
// Create a new Xf with the same contents
2010-09-20 16:10:14 -04:00
_cellXf = CTXf . Factory . parse (
src . getCoreXf ( ) . toString ( )
) ;
2015-08-20 10:28:39 -04:00
2015-03-14 15:32:28 -04:00
// bug 56295: ensure that the fills is available and set correctly
CTFill fill = CTFill . Factory . parse (
src . getCTFill ( ) . toString ( )
) ;
addFill ( fill ) ;
2015-08-20 10:28:39 -04:00
2011-04-21 09:22:18 -04:00
// Swap it over
_stylesSource . replaceCellXfAt ( _cellXfId , _cellXf ) ;
2010-09-20 16:10:14 -04:00
} catch ( XmlException e ) {
throw new POIXMLException ( e ) ;
}
2015-08-20 10:28:39 -04:00
2010-09-20 16:10:14 -04:00
// Copy the format
String fmt = src . getDataFormatString ( ) ;
setDataFormat (
( new XSSFDataFormat ( _stylesSource ) ) . getFormat ( fmt )
) ;
2015-08-20 10:28:39 -04:00
2010-09-20 16:10:14 -04:00
// Copy the font
try {
CTFont ctFont = CTFont . Factory . parse (
src . getFont ( ) . getCTFont ( ) . toString ( )
) ;
XSSFFont font = new XSSFFont ( ctFont ) ;
font . registerTo ( _stylesSource ) ;
setFont ( font ) ;
} catch ( XmlException e ) {
throw new POIXMLException ( e ) ;
}
}
2015-08-20 10:28:39 -04:00
2010-09-20 16:10:14 -04:00
// Clear out cached details
_font = null ;
_cellAlignment = null ;
2009-04-20 12:58:29 -04:00
} else {
throw new IllegalArgumentException ( " Can only clone from one XSSFCellStyle to another, not between HSSFCellStyle and XSSFCellStyle " ) ;
2008-09-15 06:39:37 -04:00
}
}
2008-10-05 09:56:28 -04:00
2015-03-14 15:32:28 -04:00
private void addFill ( CTFill fill ) {
int idx = _stylesSource . putFill ( new XSSFCellFill ( fill ) ) ;
_cellXf . setFillId ( idx ) ;
_cellXf . setApplyFill ( true ) ;
}
2008-10-05 09:56:28 -04:00
/ * *
* Get the type of horizontal alignment for the cell
*
* @return short - the type of alignment
2008-11-07 11:57:23 -05:00
* @see org . apache . poi . ss . usermodel . CellStyle # ALIGN_GENERAL
* @see org . apache . poi . ss . usermodel . CellStyle # ALIGN_LEFT
* @see org . apache . poi . ss . usermodel . CellStyle # ALIGN_CENTER
* @see org . apache . poi . ss . usermodel . CellStyle # ALIGN_RIGHT
* @see org . apache . poi . ss . usermodel . CellStyle # ALIGN_FILL
* @see org . apache . poi . ss . usermodel . CellStyle # ALIGN_JUSTIFY
* @see org . apache . poi . ss . usermodel . CellStyle # ALIGN_CENTER_SELECTION
2008-10-05 09:56:28 -04:00
* /
2015-08-20 10:28:39 -04:00
@Override
2008-09-15 06:39:37 -04:00
public short getAlignment ( ) {
return ( short ) ( getAlignmentEnum ( ) . ordinal ( ) ) ;
}
2008-10-05 09:56:28 -04:00
/ * *
* Get the type of horizontal alignment for the cell
*
* @return HorizontalAlignment - the type of alignment
2008-11-07 11:57:23 -05:00
* @see org . apache . poi . ss . usermodel . HorizontalAlignment
2008-10-05 09:56:28 -04:00
* /
2008-09-15 06:39:37 -04:00
public HorizontalAlignment getAlignmentEnum ( ) {
2009-08-18 12:50:24 -04:00
CTCellAlignment align = _cellXf . getAlignment ( ) ;
2008-10-21 13:56:34 -04:00
if ( align ! = null & & align . isSetHorizontal ( ) ) {
return HorizontalAlignment . values ( ) [ align . getHorizontal ( ) . intValue ( ) - 1 ] ;
}
2009-08-18 01:29:53 -04:00
return HorizontalAlignment . GENERAL ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Get the type of border to use for the bottom border of the cell
*
* @return short - border type
2008-11-07 11:57:23 -05:00
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_NONE
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_THIN
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_MEDIUM
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_DASHED
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_DOTTED
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_THICK
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_DOUBLE
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_HAIR
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_MEDIUM_DASHED
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_DASH_DOT
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_MEDIUM_DASH_DOT
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_DASH_DOT_DOT
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_MEDIUM_DASH_DOT_DOT
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_SLANTED_DASH_DOT
2008-10-05 09:56:28 -04:00
* /
2015-08-20 10:28:39 -04:00
@Override
2008-09-15 06:39:37 -04:00
public short getBorderBottom ( ) {
2009-08-18 12:50:24 -04:00
if ( ! _cellXf . getApplyBorder ( ) ) return BORDER_NONE ;
2008-10-05 09:56:28 -04:00
2009-08-18 12:50:24 -04:00
int idx = ( int ) _cellXf . getBorderId ( ) ;
CTBorder ct = _stylesSource . getBorderAt ( idx ) . getCTBorder ( ) ;
2008-10-05 09:56:28 -04:00
STBorderStyle . Enum ptrn = ct . isSetBottom ( ) ? ct . getBottom ( ) . getStyle ( ) : null ;
return ptrn = = null ? BORDER_NONE : ( short ) ( ptrn . intValue ( ) - 1 ) ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Get the type of border to use for the bottom border of the cell
*
* @return border type as Java enum
* @see BorderStyle
* /
public BorderStyle getBorderBottomEnum ( ) {
int style = getBorderBottom ( ) ;
return BorderStyle . values ( ) [ style ] ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Get the type of border to use for the left border of the cell
*
2008-11-07 11:57:23 -05:00
* @return short - border type , default value is { @link org . apache . poi . ss . usermodel . CellStyle # BORDER_NONE }
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_NONE
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_THIN
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_MEDIUM
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_DASHED
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_DOTTED
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_THICK
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_DOUBLE
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_HAIR
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_MEDIUM_DASHED
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_DASH_DOT
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_MEDIUM_DASH_DOT
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_DASH_DOT_DOT
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_MEDIUM_DASH_DOT_DOT
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_SLANTED_DASH_DOT
2008-10-05 09:56:28 -04:00
* /
2015-08-20 10:28:39 -04:00
@Override
2008-09-15 06:39:37 -04:00
public short getBorderLeft ( ) {
2009-08-18 12:50:24 -04:00
if ( ! _cellXf . getApplyBorder ( ) ) return BORDER_NONE ;
2008-10-05 09:56:28 -04:00
2009-08-18 12:50:24 -04:00
int idx = ( int ) _cellXf . getBorderId ( ) ;
CTBorder ct = _stylesSource . getBorderAt ( idx ) . getCTBorder ( ) ;
2008-10-05 09:56:28 -04:00
STBorderStyle . Enum ptrn = ct . isSetLeft ( ) ? ct . getLeft ( ) . getStyle ( ) : null ;
return ptrn = = null ? BORDER_NONE : ( short ) ( ptrn . intValue ( ) - 1 ) ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Get the type of border to use for the left border of the cell
*
2008-11-07 11:57:23 -05:00
* @return border type , default value is { @link org . apache . poi . ss . usermodel . BorderStyle # NONE }
2008-10-05 09:56:28 -04:00
* /
public BorderStyle getBorderLeftEnum ( ) {
int style = getBorderLeft ( ) ;
return BorderStyle . values ( ) [ style ] ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Get the type of border to use for the right border of the cell
*
2008-11-07 11:57:23 -05:00
* @return short - border type , default value is { @link org . apache . poi . ss . usermodel . CellStyle # BORDER_NONE }
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_NONE
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_THIN
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_MEDIUM
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_DASHED
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_DOTTED
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_THICK
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_DOUBLE
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_HAIR
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_MEDIUM_DASHED
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_DASH_DOT
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_MEDIUM_DASH_DOT
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_DASH_DOT_DOT
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_MEDIUM_DASH_DOT_DOT
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_SLANTED_DASH_DOT
2008-10-05 09:56:28 -04:00
* /
2015-08-20 10:28:39 -04:00
@Override
2008-09-15 06:39:37 -04:00
public short getBorderRight ( ) {
2009-08-18 12:50:24 -04:00
if ( ! _cellXf . getApplyBorder ( ) ) return BORDER_NONE ;
2008-10-05 09:56:28 -04:00
2009-08-18 12:50:24 -04:00
int idx = ( int ) _cellXf . getBorderId ( ) ;
CTBorder ct = _stylesSource . getBorderAt ( idx ) . getCTBorder ( ) ;
2008-10-05 09:56:28 -04:00
STBorderStyle . Enum ptrn = ct . isSetRight ( ) ? ct . getRight ( ) . getStyle ( ) : null ;
return ptrn = = null ? BORDER_NONE : ( short ) ( ptrn . intValue ( ) - 1 ) ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Get the type of border to use for the right border of the cell
*
2008-11-07 11:57:23 -05:00
* @return border type , default value is { @link org . apache . poi . ss . usermodel . BorderStyle # NONE }
2008-10-05 09:56:28 -04:00
* /
public BorderStyle getBorderRightEnum ( ) {
int style = getBorderRight ( ) ;
return BorderStyle . values ( ) [ style ] ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Get the type of border to use for the top border of the cell
*
2008-11-07 11:57:23 -05:00
* @return short - border type , default value is { @link org . apache . poi . ss . usermodel . CellStyle # BORDER_NONE }
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_NONE
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_THIN
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_MEDIUM
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_DASHED
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_DOTTED
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_THICK
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_DOUBLE
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_HAIR
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_MEDIUM_DASHED
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_DASH_DOT
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_MEDIUM_DASH_DOT
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_DASH_DOT_DOT
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_MEDIUM_DASH_DOT_DOT
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_SLANTED_DASH_DOT
2008-10-05 09:56:28 -04:00
* /
2015-08-20 10:28:39 -04:00
@Override
2008-09-15 06:39:37 -04:00
public short getBorderTop ( ) {
2009-08-18 12:50:24 -04:00
if ( ! _cellXf . getApplyBorder ( ) ) return BORDER_NONE ;
2008-10-05 09:56:28 -04:00
2009-08-18 12:50:24 -04:00
int idx = ( int ) _cellXf . getBorderId ( ) ;
CTBorder ct = _stylesSource . getBorderAt ( idx ) . getCTBorder ( ) ;
2008-10-05 09:56:28 -04:00
STBorderStyle . Enum ptrn = ct . isSetTop ( ) ? ct . getTop ( ) . getStyle ( ) : null ;
return ptrn = = null ? BORDER_NONE : ( short ) ( ptrn . intValue ( ) - 1 ) ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Get the type of border to use for the top border of the cell
*
2008-11-07 11:57:23 -05:00
* @return border type , default value is { @link org . apache . poi . ss . usermodel . BorderStyle # NONE }
2008-10-05 09:56:28 -04:00
* /
public BorderStyle getBorderTopEnum ( ) {
int style = getBorderTop ( ) ;
return BorderStyle . values ( ) [ style ] ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Get the color to use for the bottom border
* < br / >
* Color is optional . When missing , IndexedColors . AUTOMATIC is implied .
2008-11-07 11:57:23 -05:00
* @return the index of the color definition , default value is { @link org . apache . poi . ss . usermodel . IndexedColors # AUTOMATIC }
* @see org . apache . poi . ss . usermodel . IndexedColors
2008-10-05 09:56:28 -04:00
* /
2015-08-20 10:28:39 -04:00
@Override
2008-09-15 06:39:37 -04:00
public short getBottomBorderColor ( ) {
2008-10-29 15:12:47 -04:00
XSSFColor clr = getBottomBorderXSSFColor ( ) ;
2009-08-21 02:08:31 -04:00
return clr = = null ? IndexedColors . BLACK . getIndex ( ) : clr . getIndexed ( ) ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Get the color to use for the bottom border as a { @link XSSFColor }
*
* @return the used color or < code > null < / code > if not set
* /
2008-10-29 15:12:47 -04:00
public XSSFColor getBottomBorderXSSFColor ( ) {
2009-08-18 12:50:24 -04:00
if ( ! _cellXf . getApplyBorder ( ) ) return null ;
2008-10-05 09:56:28 -04:00
2009-08-18 12:50:24 -04:00
int idx = ( int ) _cellXf . getBorderId ( ) ;
XSSFCellBorder border = _stylesSource . getBorderAt ( idx ) ;
2008-10-05 09:56:28 -04:00
return border . getBorderColor ( BorderSide . BOTTOM ) ;
}
/ * *
* Get the index of the number format ( numFmt ) record used by this cell format .
*
* @return the index of the number format
* /
2015-08-20 10:28:39 -04:00
@Override
2008-09-15 06:39:37 -04:00
public short getDataFormat ( ) {
2009-08-18 12:50:24 -04:00
return ( short ) _cellXf . getNumFmtId ( ) ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Get the contents of the format string , by looking up
* the StylesSource
*
* @return the number format string
* /
2015-08-20 10:28:39 -04:00
@Override
2008-09-15 06:39:37 -04:00
public String getDataFormatString ( ) {
2009-03-01 11:24:40 -05:00
int idx = getDataFormat ( ) ;
2009-08-18 12:50:24 -04:00
return new XSSFDataFormat ( _stylesSource ) . getFormat ( ( short ) idx ) ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Get the background fill color .
* < p >
* Note - many cells are actually filled with a foreground
* fill , not a background fill - see { @link # getFillForegroundColor ( ) }
* < / p >
2008-11-07 11:57:23 -05:00
* @return fill color , default value is { @link org . apache . poi . ss . usermodel . IndexedColors # AUTOMATIC }
* @see org . apache . poi . ss . usermodel . IndexedColors
2008-10-05 09:56:28 -04:00
* /
2015-08-20 10:28:39 -04:00
@Override
2008-09-15 06:39:37 -04:00
public short getFillBackgroundColor ( ) {
2008-10-29 15:12:47 -04:00
XSSFColor clr = getFillBackgroundXSSFColor ( ) ;
2009-08-21 02:08:31 -04:00
return clr = = null ? IndexedColors . AUTOMATIC . getIndex ( ) : clr . getIndexed ( ) ;
2008-09-15 06:39:37 -04:00
}
2015-08-20 10:28:39 -04:00
@Override
2010-05-26 13:46:46 -04:00
public XSSFColor getFillBackgroundColorColor ( ) {
return getFillBackgroundXSSFColor ( ) ;
}
2008-09-15 06:39:37 -04:00
2008-10-05 09:56:28 -04:00
/ * *
* Get the background fill color .
* < p >
* Note - many cells are actually filled with a foreground
* fill , not a background fill - see { @link # getFillForegroundColor ( ) }
* < / p >
2015-10-12 19:10:02 -04:00
* @see org . apache . poi . xssf . usermodel . XSSFColor # getRGB ( )
2008-10-05 09:56:28 -04:00
* @return XSSFColor - fill color or < code > null < / code > if not set
* /
2008-10-29 15:12:47 -04:00
public XSSFColor getFillBackgroundXSSFColor ( ) {
2015-03-14 15:32:28 -04:00
// bug 56295: handle missing applyFill attribute as "true" because Excel does as well
if ( _cellXf . isSetApplyFill ( ) & & ! _cellXf . getApplyFill ( ) ) return null ;
2008-10-05 09:56:28 -04:00
2009-08-18 12:50:24 -04:00
int fillIndex = ( int ) _cellXf . getFillId ( ) ;
XSSFCellFill fg = _stylesSource . getFillAt ( fillIndex ) ;
2008-10-05 09:56:28 -04:00
2010-05-19 07:55:17 -04:00
XSSFColor fillBackgroundColor = fg . getFillBackgroundColor ( ) ;
2011-03-04 09:38:13 -05:00
if ( fillBackgroundColor ! = null & & _theme ! = null ) {
_theme . inheritFromThemeAsRequired ( fillBackgroundColor ) ;
2010-05-19 07:55:17 -04:00
}
return fillBackgroundColor ;
2008-09-24 13:53:29 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Get the foreground fill color .
* < p >
* Many cells are filled with this , instead of a
* background color ( { @link # getFillBackgroundColor ( ) } )
* < / p >
* @see IndexedColors
2008-11-07 11:57:23 -05:00
* @return fill color , default value is { @link org . apache . poi . ss . usermodel . IndexedColors # AUTOMATIC }
2008-10-05 09:56:28 -04:00
* /
2015-08-20 10:28:39 -04:00
@Override
2008-09-15 06:39:37 -04:00
public short getFillForegroundColor ( ) {
2008-10-29 15:12:47 -04:00
XSSFColor clr = getFillForegroundXSSFColor ( ) ;
2009-08-21 02:08:31 -04:00
return clr = = null ? IndexedColors . AUTOMATIC . getIndex ( ) : clr . getIndexed ( ) ;
2008-09-15 06:39:37 -04:00
}
2015-08-20 10:28:39 -04:00
@Override
2010-05-26 13:46:46 -04:00
public XSSFColor getFillForegroundColorColor ( ) {
return getFillForegroundXSSFColor ( ) ;
}
2015-08-20 10:28:39 -04:00
2008-10-05 09:56:28 -04:00
/ * *
* Get the foreground fill color .
*
* @return XSSFColor - fill color or < code > null < / code > if not set
* /
2008-10-29 15:12:47 -04:00
public XSSFColor getFillForegroundXSSFColor ( ) {
2015-03-14 15:32:28 -04:00
// bug 56295: handle missing applyFill attribute as "true" because Excel does as well
if ( _cellXf . isSetApplyFill ( ) & & ! _cellXf . getApplyFill ( ) ) return null ;
2008-10-05 09:56:28 -04:00
2009-08-18 12:50:24 -04:00
int fillIndex = ( int ) _cellXf . getFillId ( ) ;
XSSFCellFill fg = _stylesSource . getFillAt ( fillIndex ) ;
2008-10-05 09:56:28 -04:00
2010-05-19 07:55:17 -04:00
XSSFColor fillForegroundColor = fg . getFillForegroundColor ( ) ;
2011-03-04 09:38:13 -05:00
if ( fillForegroundColor ! = null & & _theme ! = null ) {
_theme . inheritFromThemeAsRequired ( fillForegroundColor ) ;
2010-05-19 07:55:17 -04:00
}
return fillForegroundColor ;
2008-09-24 13:53:29 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Get the fill pattern
2008-11-07 11:57:23 -05:00
* @return fill pattern , default value is { @link org . apache . poi . ss . usermodel . CellStyle # NO_FILL }
2008-10-05 09:56:28 -04:00
*
2008-11-07 11:57:23 -05:00
* @see org . apache . poi . ss . usermodel . CellStyle # NO_FILL
* @see org . apache . poi . ss . usermodel . CellStyle # SOLID_FOREGROUND
* @see org . apache . poi . ss . usermodel . CellStyle # FINE_DOTS
* @see org . apache . poi . ss . usermodel . CellStyle # ALT_BARS
* @see org . apache . poi . ss . usermodel . CellStyle # SPARSE_DOTS
* @see org . apache . poi . ss . usermodel . CellStyle # THICK_HORZ_BANDS
* @see org . apache . poi . ss . usermodel . CellStyle # THICK_VERT_BANDS
* @see org . apache . poi . ss . usermodel . CellStyle # THICK_BACKWARD_DIAG
* @see org . apache . poi . ss . usermodel . CellStyle # THICK_FORWARD_DIAG
* @see org . apache . poi . ss . usermodel . CellStyle # BIG_SPOTS
* @see org . apache . poi . ss . usermodel . CellStyle # BRICKS
* @see org . apache . poi . ss . usermodel . CellStyle # THIN_HORZ_BANDS
* @see org . apache . poi . ss . usermodel . CellStyle # THIN_VERT_BANDS
* @see org . apache . poi . ss . usermodel . CellStyle # THIN_BACKWARD_DIAG
* @see org . apache . poi . ss . usermodel . CellStyle # THIN_FORWARD_DIAG
* @see org . apache . poi . ss . usermodel . CellStyle # SQUARES
* @see org . apache . poi . ss . usermodel . CellStyle # DIAMONDS
2008-10-05 09:56:28 -04:00
* /
2015-08-20 10:28:39 -04:00
@Override
2008-09-15 06:39:37 -04:00
public short getFillPattern ( ) {
2015-03-14 15:32:28 -04:00
// bug 56295: handle missing applyFill attribute as "true" because Excel does as well
if ( _cellXf . isSetApplyFill ( ) & & ! _cellXf . getApplyFill ( ) ) return 0 ;
2008-10-05 09:56:28 -04:00
2009-08-18 12:50:24 -04:00
int fillIndex = ( int ) _cellXf . getFillId ( ) ;
XSSFCellFill fill = _stylesSource . getFillAt ( fillIndex ) ;
2008-10-05 09:56:28 -04:00
STPatternType . Enum ptrn = fill . getPatternType ( ) ;
if ( ptrn = = null ) return CellStyle . NO_FILL ;
return ( short ) ( ptrn . intValue ( ) - 1 ) ;
}
/ * *
* Get the fill pattern
*
2008-11-07 11:57:23 -05:00
* @return the fill pattern , default value is { @link org . apache . poi . ss . usermodel . FillPatternType # NO_FILL }
2008-10-05 09:56:28 -04:00
* /
public FillPatternType getFillPatternEnum ( ) {
int style = getFillPattern ( ) ;
return FillPatternType . values ( ) [ style ] ;
}
/ * *
* Gets the font for this style
* @return Font - font
* /
public XSSFFont getFont ( ) {
2009-08-18 12:50:24 -04:00
if ( _font = = null ) {
_font = _stylesSource . getFontAt ( getFontId ( ) ) ;
2008-09-15 06:39:37 -04:00
}
2009-08-18 12:50:24 -04:00
return _font ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Gets the index of the font for this style
*
* @return short - font index
* @see org . apache . poi . xssf . usermodel . XSSFWorkbook # getFontAt ( short )
* /
2015-08-20 10:28:39 -04:00
@Override
2008-09-15 06:39:37 -04:00
public short getFontIndex ( ) {
return ( short ) getFontId ( ) ;
}
2008-10-05 09:56:28 -04:00
/ * *
* Get whether the cell ' s using this style are to be hidden
*
* @return boolean - whether the cell using this style is hidden
* /
2015-08-20 10:28:39 -04:00
@Override
2008-09-15 06:39:37 -04:00
public boolean getHidden ( ) {
2011-06-24 09:06:04 -04:00
if ( ! _cellXf . isSetProtection ( ) | | ! _cellXf . getProtection ( ) . isSetHidden ( ) ) {
return false ;
}
return _cellXf . getProtection ( ) . getHidden ( ) ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Get the number of spaces to indent the text in the cell
*
* @return indent - number of spaces
* /
2015-08-20 10:28:39 -04:00
@Override
2008-09-15 06:39:37 -04:00
public short getIndention ( ) {
2009-08-18 12:50:24 -04:00
CTCellAlignment align = _cellXf . getAlignment ( ) ;
2008-10-21 13:56:34 -04:00
return ( short ) ( align = = null ? 0 : align . getIndent ( ) ) ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Get the index within the StylesTable ( sequence within the collection of CTXf elements )
*
2015-08-24 13:55:57 -04:00
* @return unique index number of the underlying record this style represents , as a short ( may wrap )
2008-10-05 09:56:28 -04:00
* /
2015-08-20 10:28:39 -04:00
@Override
2008-09-15 06:39:37 -04:00
public short getIndex ( ) {
2009-08-18 12:50:24 -04:00
return ( short ) this . _cellXfId ;
2008-09-15 06:39:37 -04:00
}
2015-08-20 10:28:39 -04:00
/ * *
* Workaround for places where we need to support more than 32767 cell styles , ideally
* the main getIndex ( ) and others would return int , not short , but that would affect some
* public APIs
*
2015-08-24 13:55:57 -04:00
* @return unique index number of the underlying record this style represents , as an int ( always positive )
2015-08-20 10:28:39 -04:00
* /
2015-05-03 04:10:07 -04:00
protected int getUIndex ( ) {
return this . _cellXfId ;
}
2008-09-15 06:39:37 -04:00
2008-10-05 09:56:28 -04:00
/ * *
* Get the color to use for the left border
*
2008-11-07 11:57:23 -05:00
* @return the index of the color definition , default value is { @link org . apache . poi . ss . usermodel . IndexedColors # BLACK }
* @see org . apache . poi . ss . usermodel . IndexedColors
2008-10-05 09:56:28 -04:00
* /
2015-08-20 10:28:39 -04:00
@Override
2008-09-15 06:39:37 -04:00
public short getLeftBorderColor ( ) {
2008-10-29 15:12:47 -04:00
XSSFColor clr = getLeftBorderXSSFColor ( ) ;
2009-08-21 02:08:31 -04:00
return clr = = null ? IndexedColors . BLACK . getIndex ( ) : clr . getIndexed ( ) ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Get the color to use for the left border
*
* @return the index of the color definition or < code > null < / code > if not set
2008-11-07 11:57:23 -05:00
* @see org . apache . poi . ss . usermodel . IndexedColors
2008-10-05 09:56:28 -04:00
* /
2008-10-29 15:12:47 -04:00
public XSSFColor getLeftBorderXSSFColor ( ) {
2009-08-18 12:50:24 -04:00
if ( ! _cellXf . getApplyBorder ( ) ) return null ;
2008-10-05 09:56:28 -04:00
2009-08-18 12:50:24 -04:00
int idx = ( int ) _cellXf . getBorderId ( ) ;
XSSFCellBorder border = _stylesSource . getBorderAt ( idx ) ;
2008-10-05 09:56:28 -04:00
return border . getBorderColor ( BorderSide . LEFT ) ;
}
/ * *
* Get whether the cell ' s using this style are locked
*
* @return whether the cell using this style are locked
* /
2015-08-20 10:28:39 -04:00
@Override
2008-09-15 06:39:37 -04:00
public boolean getLocked ( ) {
2011-06-24 09:06:04 -04:00
if ( ! _cellXf . isSetProtection ( ) | | ! _cellXf . getProtection ( ) . isSetLocked ( ) ) {
return true ;
}
return _cellXf . getProtection ( ) . getLocked ( ) ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Get the color to use for the right border
*
2008-11-07 11:57:23 -05:00
* @return the index of the color definition , default value is { @link org . apache . poi . ss . usermodel . IndexedColors # BLACK }
* @see org . apache . poi . ss . usermodel . IndexedColors
2008-10-05 09:56:28 -04:00
* /
2015-08-20 10:28:39 -04:00
@Override
2008-09-15 06:39:37 -04:00
public short getRightBorderColor ( ) {
2008-10-29 15:12:47 -04:00
XSSFColor clr = getRightBorderXSSFColor ( ) ;
2009-08-21 02:08:31 -04:00
return clr = = null ? IndexedColors . BLACK . getIndex ( ) : clr . getIndexed ( ) ;
2008-10-05 09:56:28 -04:00
}
/ * *
* Get the color to use for the right border
*
* @return the used color or < code > null < / code > if not set
* /
2008-10-29 15:12:47 -04:00
public XSSFColor getRightBorderXSSFColor ( ) {
2009-08-18 12:50:24 -04:00
if ( ! _cellXf . getApplyBorder ( ) ) return null ;
2008-10-05 09:56:28 -04:00
2009-08-18 12:50:24 -04:00
int idx = ( int ) _cellXf . getBorderId ( ) ;
XSSFCellBorder border = _stylesSource . getBorderAt ( idx ) ;
2008-10-05 09:56:28 -04:00
return border . getBorderColor ( BorderSide . RIGHT ) ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Get the degree of rotation for the text in the cell
* < p >
* Expressed in degrees . Values range from 0 to 180 . The first letter of
* the text is considered the center - point of the arc .
* < br / >
* For 0 - 90 , the value represents degrees above horizon . For 91 - 180 the degrees below the
* horizon is calculated as :
* < br / >
* < code > [ degrees below horizon ] = 90 - textRotation . < / code >
* < / p >
*
* @return rotation degrees ( between 0 and 180 degrees )
* /
2015-08-20 10:28:39 -04:00
@Override
2008-09-15 06:39:37 -04:00
public short getRotation ( ) {
2009-08-18 12:50:24 -04:00
CTCellAlignment align = _cellXf . getAlignment ( ) ;
2008-10-21 13:56:34 -04:00
return ( short ) ( align = = null ? 0 : align . getTextRotation ( ) ) ;
2008-09-15 06:39:37 -04:00
}
2015-08-20 10:28:39 -04:00
@Override
2013-11-07 17:28:06 -05:00
public boolean getShrinkToFit ( ) {
CTCellAlignment align = _cellXf . getAlignment ( ) ;
return align ! = null & & align . getShrinkToFit ( ) ;
}
2015-08-20 10:28:39 -04:00
2008-10-05 09:56:28 -04:00
/ * *
* Get the color to use for the top border
*
2008-11-07 11:57:23 -05:00
* @return the index of the color definition , default value is { @link org . apache . poi . ss . usermodel . IndexedColors # BLACK }
* @see org . apache . poi . ss . usermodel . IndexedColors
2008-10-05 09:56:28 -04:00
* /
2015-08-20 10:28:39 -04:00
@Override
2008-09-15 06:39:37 -04:00
public short getTopBorderColor ( ) {
2008-10-29 15:12:47 -04:00
XSSFColor clr = getTopBorderXSSFColor ( ) ;
2009-08-21 02:08:31 -04:00
return clr = = null ? IndexedColors . BLACK . getIndex ( ) : clr . getIndexed ( ) ;
2008-10-05 09:56:28 -04:00
}
/ * *
* Get the color to use for the top border
*
* @return the used color or < code > null < / code > if not set
* /
2008-10-29 15:12:47 -04:00
public XSSFColor getTopBorderXSSFColor ( ) {
2009-08-18 12:50:24 -04:00
if ( ! _cellXf . getApplyBorder ( ) ) return null ;
2008-10-05 09:56:28 -04:00
2009-08-18 12:50:24 -04:00
int idx = ( int ) _cellXf . getBorderId ( ) ;
XSSFCellBorder border = _stylesSource . getBorderAt ( idx ) ;
2008-10-05 09:56:28 -04:00
return border . getBorderColor ( BorderSide . TOP ) ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Get the type of vertical alignment for the cell
*
2008-11-07 11:57:23 -05:00
* @return align the type of alignment , default value is { @link org . apache . poi . ss . usermodel . CellStyle # VERTICAL_BOTTOM }
* @see org . apache . poi . ss . usermodel . CellStyle # VERTICAL_TOP
* @see org . apache . poi . ss . usermodel . CellStyle # VERTICAL_CENTER
* @see org . apache . poi . ss . usermodel . CellStyle # VERTICAL_BOTTOM
* @see org . apache . poi . ss . usermodel . CellStyle # VERTICAL_JUSTIFY
2008-10-05 09:56:28 -04:00
* /
2015-08-20 10:28:39 -04:00
@Override
2008-09-15 06:39:37 -04:00
public short getVerticalAlignment ( ) {
return ( short ) ( getVerticalAlignmentEnum ( ) . ordinal ( ) ) ;
}
2008-10-05 09:56:28 -04:00
/ * *
* Get the type of vertical alignment for the cell
*
2008-11-07 11:57:23 -05:00
* @return the type of alignment , default value is { @link org . apache . poi . ss . usermodel . VerticalAlignment # BOTTOM }
* @see org . apache . poi . ss . usermodel . VerticalAlignment
2008-10-05 09:56:28 -04:00
* /
2008-09-15 06:39:37 -04:00
public VerticalAlignment getVerticalAlignmentEnum ( ) {
2009-08-18 12:50:24 -04:00
CTCellAlignment align = _cellXf . getAlignment ( ) ;
2008-10-21 13:56:34 -04:00
if ( align ! = null & & align . isSetVertical ( ) ) {
return VerticalAlignment . values ( ) [ align . getVertical ( ) . intValue ( ) - 1 ] ;
}
2009-08-18 12:50:24 -04:00
return VerticalAlignment . BOTTOM ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Whether the text should be wrapped
*
* @return a boolean value indicating if the text in a cell should be line - wrapped within the cell .
* /
2015-08-20 10:28:39 -04:00
@Override
2008-09-15 06:39:37 -04:00
public boolean getWrapText ( ) {
2009-08-18 12:50:24 -04:00
CTCellAlignment align = _cellXf . getAlignment ( ) ;
2008-10-21 13:56:34 -04:00
return align ! = null & & align . getWrapText ( ) ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Set the type of horizontal alignment for the cell
*
* @param align - the type of alignment
2008-11-07 11:57:23 -05:00
* @see org . apache . poi . ss . usermodel . CellStyle # ALIGN_GENERAL
* @see org . apache . poi . ss . usermodel . CellStyle # ALIGN_LEFT
* @see org . apache . poi . ss . usermodel . CellStyle # ALIGN_CENTER
* @see org . apache . poi . ss . usermodel . CellStyle # ALIGN_RIGHT
* @see org . apache . poi . ss . usermodel . CellStyle # ALIGN_FILL
* @see org . apache . poi . ss . usermodel . CellStyle # ALIGN_JUSTIFY
* @see org . apache . poi . ss . usermodel . CellStyle # ALIGN_CENTER_SELECTION
2008-10-05 09:56:28 -04:00
* /
2015-08-20 10:28:39 -04:00
@Override
2008-09-15 06:39:37 -04:00
public void setAlignment ( short align ) {
getCellAlignment ( ) . setHorizontal ( HorizontalAlignment . values ( ) [ align ] ) ;
}
2008-10-05 09:56:28 -04:00
/ * *
* Set the type of horizontal alignment for the cell
*
* @param align - the type of alignment
2008-10-28 06:03:51 -04:00
* @see org . apache . poi . ss . usermodel . HorizontalAlignment
2008-10-05 09:56:28 -04:00
* /
2008-09-15 06:39:37 -04:00
public void setAlignment ( HorizontalAlignment align ) {
setAlignment ( ( short ) align . ordinal ( ) ) ;
}
2008-10-05 09:56:28 -04:00
/ * *
* Set the type of border to use for the bottom border of the cell
*
* @param border the type of border to use
2008-11-07 11:57:23 -05:00
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_NONE
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_THIN
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_MEDIUM
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_DASHED
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_DOTTED
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_THICK
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_DOUBLE
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_HAIR
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_MEDIUM_DASHED
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_DASH_DOT
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_MEDIUM_DASH_DOT
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_DASH_DOT_DOT
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_MEDIUM_DASH_DOT_DOT
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_SLANTED_DASH_DOT
2008-10-05 09:56:28 -04:00
* /
2015-08-20 10:28:39 -04:00
@Override
2008-09-15 06:39:37 -04:00
public void setBorderBottom ( short border ) {
2008-10-05 09:56:28 -04:00
CTBorder ct = getCTBorder ( ) ;
CTBorderPr pr = ct . isSetBottom ( ) ? ct . getBottom ( ) : ct . addNewBottom ( ) ;
if ( border = = BORDER_NONE ) ct . unsetBottom ( ) ;
else pr . setStyle ( STBorderStyle . Enum . forInt ( border + 1 ) ) ;
2011-03-04 09:38:13 -05:00
int idx = _stylesSource . putBorder ( new XSSFCellBorder ( ct , _theme ) ) ;
2008-10-05 09:56:28 -04:00
2009-08-18 12:50:24 -04:00
_cellXf . setBorderId ( idx ) ;
_cellXf . setApplyBorder ( true ) ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Set the type of border to use for the bottom border of the cell
*
* @param border - type of border to use
2008-11-07 11:57:23 -05:00
* @see org . apache . poi . ss . usermodel . BorderStyle
2008-10-05 09:56:28 -04:00
* /
public void setBorderBottom ( BorderStyle border ) {
setBorderBottom ( ( short ) border . ordinal ( ) ) ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Set the type of border to use for the left border of the cell
* @param border the type of border to use
2008-11-07 11:57:23 -05:00
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_NONE
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_THIN
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_MEDIUM
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_DASHED
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_DOTTED
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_THICK
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_DOUBLE
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_HAIR
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_MEDIUM_DASHED
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_DASH_DOT
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_MEDIUM_DASH_DOT
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_DASH_DOT_DOT
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_MEDIUM_DASH_DOT_DOT
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_SLANTED_DASH_DOT
2008-10-05 09:56:28 -04:00
* /
2015-08-20 10:28:39 -04:00
@Override
2008-09-15 06:39:37 -04:00
public void setBorderLeft ( short border ) {
2008-10-05 09:56:28 -04:00
CTBorder ct = getCTBorder ( ) ;
CTBorderPr pr = ct . isSetLeft ( ) ? ct . getLeft ( ) : ct . addNewLeft ( ) ;
if ( border = = BORDER_NONE ) ct . unsetLeft ( ) ;
else pr . setStyle ( STBorderStyle . Enum . forInt ( border + 1 ) ) ;
2011-03-04 09:38:13 -05:00
int idx = _stylesSource . putBorder ( new XSSFCellBorder ( ct , _theme ) ) ;
2008-10-05 09:56:28 -04:00
2009-08-18 12:50:24 -04:00
_cellXf . setBorderId ( idx ) ;
_cellXf . setApplyBorder ( true ) ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Set the type of border to use for the left border of the cell
*
* @param border the type of border to use
* /
public void setBorderLeft ( BorderStyle border ) {
setBorderLeft ( ( short ) border . ordinal ( ) ) ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Set the type of border to use for the right border of the cell
*
* @param border the type of border to use
2008-11-07 11:57:23 -05:00
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_NONE
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_THIN
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_MEDIUM
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_DASHED
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_DOTTED
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_THICK
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_DOUBLE
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_HAIR
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_MEDIUM_DASHED
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_DASH_DOT
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_MEDIUM_DASH_DOT
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_DASH_DOT_DOT
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_MEDIUM_DASH_DOT_DOT
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_SLANTED_DASH_DOT
2008-10-05 09:56:28 -04:00
* /
2015-09-03 16:59:14 -04:00
@Override
public void setBorderRight ( short border ) {
2008-10-05 09:56:28 -04:00
CTBorder ct = getCTBorder ( ) ;
CTBorderPr pr = ct . isSetRight ( ) ? ct . getRight ( ) : ct . addNewRight ( ) ;
if ( border = = BORDER_NONE ) ct . unsetRight ( ) ;
else pr . setStyle ( STBorderStyle . Enum . forInt ( border + 1 ) ) ;
2011-03-04 09:38:13 -05:00
int idx = _stylesSource . putBorder ( new XSSFCellBorder ( ct , _theme ) ) ;
2008-10-05 09:56:28 -04:00
2009-08-18 12:50:24 -04:00
_cellXf . setBorderId ( idx ) ;
_cellXf . setApplyBorder ( true ) ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Set the type of border to use for the right border of the cell
*
* @param border the type of border to use
* /
public void setBorderRight ( BorderStyle border ) {
setBorderRight ( ( short ) border . ordinal ( ) ) ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Set the type of border to use for the top border of the cell
*
* @param border the type of border to use
2008-11-07 11:57:23 -05:00
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_NONE
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_THIN
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_MEDIUM
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_DASHED
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_DOTTED
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_THICK
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_DOUBLE
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_HAIR
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_MEDIUM_DASHED
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_DASH_DOT
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_MEDIUM_DASH_DOT
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_DASH_DOT_DOT
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_MEDIUM_DASH_DOT_DOT
* @see org . apache . poi . ss . usermodel . CellStyle # BORDER_SLANTED_DASH_DOT
2008-10-05 09:56:28 -04:00
* /
2015-08-20 10:28:39 -04:00
@Override
public void setBorderTop ( short border ) {
2008-10-05 09:56:28 -04:00
CTBorder ct = getCTBorder ( ) ;
CTBorderPr pr = ct . isSetTop ( ) ? ct . getTop ( ) : ct . addNewTop ( ) ;
if ( border = = BORDER_NONE ) ct . unsetTop ( ) ;
else pr . setStyle ( STBorderStyle . Enum . forInt ( border + 1 ) ) ;
2011-03-04 09:38:13 -05:00
int idx = _stylesSource . putBorder ( new XSSFCellBorder ( ct , _theme ) ) ;
2008-10-05 09:56:28 -04:00
2009-08-18 12:50:24 -04:00
_cellXf . setBorderId ( idx ) ;
_cellXf . setApplyBorder ( true ) ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Set the type of border to use for the top border of the cell
*
* @param border the type of border to use
* /
2008-10-29 15:12:47 -04:00
public void setBorderTop ( BorderStyle border ) {
2008-10-05 09:56:28 -04:00
setBorderTop ( ( short ) border . ordinal ( ) ) ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Set the color to use for the bottom border
* @param color the index of the color definition
2008-11-07 11:57:23 -05:00
* @see org . apache . poi . ss . usermodel . IndexedColors
2008-10-05 09:56:28 -04:00
* /
2015-08-20 10:28:39 -04:00
@Override
2008-09-15 06:39:37 -04:00
public void setBottomBorderColor ( short color ) {
2008-10-05 09:56:28 -04:00
XSSFColor clr = new XSSFColor ( ) ;
clr . setIndexed ( color ) ;
setBottomBorderColor ( clr ) ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Set the color to use for the bottom border
*
* @param color the color to use , null means no color
* /
public void setBottomBorderColor ( XSSFColor color ) {
CTBorder ct = getCTBorder ( ) ;
if ( color = = null & & ! ct . isSetBottom ( ) ) return ;
CTBorderPr pr = ct . isSetBottom ( ) ? ct . getBottom ( ) : ct . addNewBottom ( ) ;
if ( color ! = null ) pr . setColor ( color . getCTColor ( ) ) ;
else pr . unsetColor ( ) ;
2011-03-04 09:38:13 -05:00
int idx = _stylesSource . putBorder ( new XSSFCellBorder ( ct , _theme ) ) ;
2008-10-05 09:56:28 -04:00
2009-08-18 12:50:24 -04:00
_cellXf . setBorderId ( idx ) ;
_cellXf . setApplyBorder ( true ) ;
2008-10-05 09:56:28 -04:00
}
/ * *
* Set the index of a data format
*
* @param fmt the index of a data format
* /
2015-08-20 10:28:39 -04:00
@Override
2008-09-15 06:39:37 -04:00
public void setDataFormat ( short fmt ) {
2015-05-03 04:10:07 -04:00
// XSSF supports >32,767 formats
setDataFormat ( fmt & 0xffff ) ;
}
/ * *
* Set the index of a data format
*
* @param fmt the index of a data format
* /
public void setDataFormat ( int fmt ) {
2009-08-18 12:50:24 -04:00
_cellXf . setApplyNumberFormat ( true ) ;
_cellXf . setNumFmtId ( fmt ) ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Set the background fill color represented as a { @link XSSFColor } value .
* < p >
* For example :
* < pre >
* cs . setFillPattern ( XSSFCellStyle . FINE_DOTS ) ;
2008-10-29 15:12:47 -04:00
* cs . setFillBackgroundXSSFColor ( new XSSFColor ( java . awt . Color . RED ) ) ;
2008-10-05 09:56:28 -04:00
* < / pre >
* optionally a Foreground and background fill can be applied :
* < i > Note : Ensure Foreground color is set prior to background < / i >
* < pre >
* cs . setFillPattern ( XSSFCellStyle . FINE_DOTS ) ;
* cs . setFillForegroundColor ( new XSSFColor ( java . awt . Color . BLUE ) ) ;
* cs . setFillBackgroundColor ( new XSSFColor ( java . awt . Color . GREEN ) ) ;
* < / pre >
* or , for the special case of SOLID_FILL :
* < pre >
* cs . setFillPattern ( XSSFCellStyle . SOLID_FOREGROUND ) ;
* cs . setFillForegroundColor ( new XSSFColor ( java . awt . Color . GREEN ) ) ;
* < / pre >
* It is necessary to set the fill style in order
* for the color to be shown in the cell .
*
* @param color - the color to use
* /
public void setFillBackgroundColor ( XSSFColor color ) {
CTFill ct = getCTFill ( ) ;
CTPatternFill ptrn = ct . getPatternFill ( ) ;
if ( color = = null ) {
if ( ptrn ! = null ) ptrn . unsetBgColor ( ) ;
} else {
if ( ptrn = = null ) ptrn = ct . addNewPatternFill ( ) ;
ptrn . setBgColor ( color . getCTColor ( ) ) ;
}
2015-03-14 15:32:28 -04:00
addFill ( ct ) ;
2008-09-24 13:53:29 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Set the background fill color represented as a indexed color value .
* < p >
* For example :
* < pre >
* cs . setFillPattern ( XSSFCellStyle . FINE_DOTS ) ;
2008-10-29 15:12:47 -04:00
* cs . setFillBackgroundXSSFColor ( IndexedColors . RED . getIndex ( ) ) ;
2008-10-05 09:56:28 -04:00
* < / pre >
* optionally a Foreground and background fill can be applied :
* < i > Note : Ensure Foreground color is set prior to background < / i >
* < pre >
* cs . setFillPattern ( XSSFCellStyle . FINE_DOTS ) ;
* cs . setFillForegroundColor ( IndexedColors . BLUE . getIndex ( ) ) ;
* cs . setFillBackgroundColor ( IndexedColors . RED . getIndex ( ) ) ;
* < / pre >
* or , for the special case of SOLID_FILL :
* < pre >
* cs . setFillPattern ( XSSFCellStyle . SOLID_FOREGROUND ) ;
* cs . setFillForegroundColor ( IndexedColors . RED . getIndex ( ) ) ;
* < / pre >
* It is necessary to set the fill style in order
* for the color to be shown in the cell .
*
* @param bg - the color to use
2008-11-07 11:57:23 -05:00
* @see org . apache . poi . ss . usermodel . IndexedColors
2008-10-05 09:56:28 -04:00
* /
2015-08-20 10:28:39 -04:00
@Override
2008-09-15 06:39:37 -04:00
public void setFillBackgroundColor ( short bg ) {
2008-10-05 09:56:28 -04:00
XSSFColor clr = new XSSFColor ( ) ;
clr . setIndexed ( bg ) ;
setFillBackgroundColor ( clr ) ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Set the foreground fill color represented as a { @link XSSFColor } value .
* < br / >
* < i > Note : Ensure Foreground color is set prior to background color . < / i >
* @param color the color to use
2008-10-29 15:12:47 -04:00
* @see # setFillBackgroundColor ( org . apache . poi . xssf . usermodel . XSSFColor ) )
2008-10-05 09:56:28 -04:00
* /
public void setFillForegroundColor ( XSSFColor color ) {
CTFill ct = getCTFill ( ) ;
CTPatternFill ptrn = ct . getPatternFill ( ) ;
if ( color = = null ) {
if ( ptrn ! = null ) ptrn . unsetFgColor ( ) ;
} else {
if ( ptrn = = null ) ptrn = ct . addNewPatternFill ( ) ;
ptrn . setFgColor ( color . getCTColor ( ) ) ;
}
2015-03-14 15:32:28 -04:00
addFill ( ct ) ;
2008-10-05 09:56:28 -04:00
}
/ * *
* Set the foreground fill color as a indexed color value
* < br / >
* < i > Note : Ensure Foreground color is set prior to background color . < / i >
* @param fg the color to use
2008-11-07 11:57:23 -05:00
* @see org . apache . poi . ss . usermodel . IndexedColors
2008-10-05 09:56:28 -04:00
* /
2015-08-20 10:28:39 -04:00
@Override
2008-10-05 09:56:28 -04:00
public void setFillForegroundColor ( short fg ) {
XSSFColor clr = new XSSFColor ( ) ;
clr . setIndexed ( fg ) ;
setFillForegroundColor ( clr ) ;
}
/ * *
* Get a < b > copy < / b > of the currently used CTFill , if none is used , return a new instance .
* /
private CTFill getCTFill ( ) {
CTFill ct ;
2015-03-14 15:32:28 -04:00
// bug 56295: handle missing applyFill attribute as "true" because Excel does as well
if ( ! _cellXf . isSetApplyFill ( ) | | _cellXf . getApplyFill ( ) ) {
2009-08-18 12:50:24 -04:00
int fillIndex = ( int ) _cellXf . getFillId ( ) ;
XSSFCellFill cf = _stylesSource . getFillAt ( fillIndex ) ;
2008-10-05 09:56:28 -04:00
ct = ( CTFill ) cf . getCTFill ( ) . copy ( ) ;
} else {
ct = CTFill . Factory . newInstance ( ) ;
}
return ct ;
}
/ * *
* Get a < b > copy < / b > of the currently used CTBorder , if none is used , return a new instance .
* /
private CTBorder getCTBorder ( ) {
CTBorder ct ;
2009-08-18 12:50:24 -04:00
if ( _cellXf . getApplyBorder ( ) ) {
int idx = ( int ) _cellXf . getBorderId ( ) ;
XSSFCellBorder cf = _stylesSource . getBorderAt ( idx ) ;
2008-10-05 09:56:28 -04:00
ct = ( CTBorder ) cf . getCTBorder ( ) . copy ( ) ;
} else {
ct = CTBorder . Factory . newInstance ( ) ;
}
return ct ;
}
/ * *
* This element is used to specify cell fill information for pattern and solid color cell fills .
* For solid cell fills ( no pattern ) , foregorund color is used .
* For cell fills with patterns specified , then the cell fill color is specified by the background color .
*
2008-11-07 11:57:23 -05:00
* @see org . apache . poi . ss . usermodel . CellStyle # NO_FILL
* @see org . apache . poi . ss . usermodel . CellStyle # SOLID_FOREGROUND
* @see org . apache . poi . ss . usermodel . CellStyle # FINE_DOTS
* @see org . apache . poi . ss . usermodel . CellStyle # ALT_BARS
* @see org . apache . poi . ss . usermodel . CellStyle # SPARSE_DOTS
* @see org . apache . poi . ss . usermodel . CellStyle # THICK_HORZ_BANDS
* @see org . apache . poi . ss . usermodel . CellStyle # THICK_VERT_BANDS
* @see org . apache . poi . ss . usermodel . CellStyle # THICK_BACKWARD_DIAG
* @see org . apache . poi . ss . usermodel . CellStyle # THICK_FORWARD_DIAG
* @see org . apache . poi . ss . usermodel . CellStyle # BIG_SPOTS
* @see org . apache . poi . ss . usermodel . CellStyle # BRICKS
* @see org . apache . poi . ss . usermodel . CellStyle # THIN_HORZ_BANDS
* @see org . apache . poi . ss . usermodel . CellStyle # THIN_VERT_BANDS
* @see org . apache . poi . ss . usermodel . CellStyle # THIN_BACKWARD_DIAG
* @see org . apache . poi . ss . usermodel . CellStyle # THIN_FORWARD_DIAG
* @see org . apache . poi . ss . usermodel . CellStyle # SQUARES
* @see org . apache . poi . ss . usermodel . CellStyle # DIAMONDS
2008-10-05 09:56:28 -04:00
* @see # setFillBackgroundColor ( short )
* @see # setFillForegroundColor ( short )
2008-11-07 11:57:23 -05:00
* @param fp fill pattern ( set to { @link org . apache . poi . ss . usermodel . CellStyle # SOLID_FOREGROUND } to fill w / foreground color )
2008-10-05 09:56:28 -04:00
* /
2015-08-20 10:28:39 -04:00
@Override
public void setFillPattern ( short fp ) {
2008-10-05 09:56:28 -04:00
CTFill ct = getCTFill ( ) ;
CTPatternFill ptrn = ct . isSetPatternFill ( ) ? ct . getPatternFill ( ) : ct . addNewPatternFill ( ) ;
if ( fp = = NO_FILL & & ptrn . isSetPatternType ( ) ) ptrn . unsetPatternType ( ) ;
else ptrn . setPatternType ( STPatternType . Enum . forInt ( fp + 1 ) ) ;
2015-03-14 15:32:28 -04:00
addFill ( ct ) ;
2008-10-05 09:56:28 -04:00
}
/ * *
* This element is used to specify cell fill information for pattern and solid color cell fills . For solid cell fills ( no pattern ) ,
* foreground color is used is used . For cell fills with patterns specified , then the cell fill color is specified by the background color element .
*
* @param ptrn the fill pattern to use
* @see # setFillBackgroundColor ( short )
* @see # setFillForegroundColor ( short )
2008-11-07 11:57:23 -05:00
* @see org . apache . poi . ss . usermodel . FillPatternType
2008-10-05 09:56:28 -04:00
* /
public void setFillPattern ( FillPatternType ptrn ) {
setFillPattern ( ( short ) ptrn . ordinal ( ) ) ;
}
/ * *
* Set the font for this style
*
* @param font a font object created or retreived from the XSSFWorkbook object
* @see org . apache . poi . xssf . usermodel . XSSFWorkbook # createFont ( )
* @see org . apache . poi . xssf . usermodel . XSSFWorkbook # getFontAt ( short )
* /
2015-08-20 10:28:39 -04:00
@Override
2008-09-15 06:39:37 -04:00
public void setFont ( Font font ) {
2008-10-05 09:56:28 -04:00
if ( font ! = null ) {
long index = font . getIndex ( ) ;
2009-08-18 12:50:24 -04:00
this . _cellXf . setFontId ( index ) ;
this . _cellXf . setApplyFont ( true ) ;
2008-10-05 09:56:28 -04:00
} else {
2009-08-18 12:50:24 -04:00
this . _cellXf . setApplyFont ( false ) ;
2008-09-15 06:39:37 -04:00
}
}
2008-10-05 09:56:28 -04:00
/ * *
* Set the cell ' s using this style to be hidden
*
* @param hidden - whether the cell using this style should be hidden
* /
2015-08-20 10:28:39 -04:00
@Override
2008-09-15 06:39:37 -04:00
public void setHidden ( boolean hidden ) {
2011-06-24 09:06:04 -04:00
if ( ! _cellXf . isSetProtection ( ) ) {
_cellXf . addNewProtection ( ) ;
}
_cellXf . getProtection ( ) . setHidden ( hidden ) ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Set the number of spaces to indent the text in the cell
*
* @param indent - number of spaces
* /
2015-08-20 10:28:39 -04:00
@Override
2008-09-15 06:39:37 -04:00
public void setIndention ( short indent ) {
getCellAlignment ( ) . setIndent ( indent ) ;
}
2008-10-05 09:56:28 -04:00
/ * *
* Set the color to use for the left border as a indexed color value
*
* @param color the index of the color definition
2008-11-07 11:57:23 -05:00
* @see org . apache . poi . ss . usermodel . IndexedColors
2008-10-05 09:56:28 -04:00
* /
2015-08-20 10:28:39 -04:00
@Override
2008-09-15 06:39:37 -04:00
public void setLeftBorderColor ( short color ) {
2008-10-05 09:56:28 -04:00
XSSFColor clr = new XSSFColor ( ) ;
clr . setIndexed ( color ) ;
setLeftBorderColor ( clr ) ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Set the color to use for the left border as a { @link XSSFColor } value
*
* @param color the color to use
* /
public void setLeftBorderColor ( XSSFColor color ) {
CTBorder ct = getCTBorder ( ) ;
if ( color = = null & & ! ct . isSetLeft ( ) ) return ;
CTBorderPr pr = ct . isSetLeft ( ) ? ct . getLeft ( ) : ct . addNewLeft ( ) ;
if ( color ! = null ) pr . setColor ( color . getCTColor ( ) ) ;
else pr . unsetColor ( ) ;
2011-03-04 09:38:13 -05:00
int idx = _stylesSource . putBorder ( new XSSFCellBorder ( ct , _theme ) ) ;
2008-09-24 13:53:29 -04:00
2009-08-18 12:50:24 -04:00
_cellXf . setBorderId ( idx ) ;
_cellXf . setApplyBorder ( true ) ;
2008-10-05 09:56:28 -04:00
}
2008-09-24 13:53:29 -04:00
2008-10-05 09:56:28 -04:00
/ * *
* Set the cell ' s using this style to be locked
*
* @param locked - whether the cell using this style should be locked
* /
2015-08-20 10:28:39 -04:00
@Override
2008-09-15 06:39:37 -04:00
public void setLocked ( boolean locked ) {
2011-06-24 09:06:04 -04:00
if ( ! _cellXf . isSetProtection ( ) ) {
_cellXf . addNewProtection ( ) ;
}
_cellXf . getProtection ( ) . setLocked ( locked ) ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Set the color to use for the right border
*
* @param color the index of the color definition
2008-11-07 11:57:23 -05:00
* @see org . apache . poi . ss . usermodel . IndexedColors
2008-10-05 09:56:28 -04:00
* /
2015-08-20 10:28:39 -04:00
@Override
2008-09-15 06:39:37 -04:00
public void setRightBorderColor ( short color ) {
2008-10-05 09:56:28 -04:00
XSSFColor clr = new XSSFColor ( ) ;
clr . setIndexed ( color ) ;
setRightBorderColor ( clr ) ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Set the color to use for the right border as a { @link XSSFColor } value
*
* @param color the color to use
* /
public void setRightBorderColor ( XSSFColor color ) {
CTBorder ct = getCTBorder ( ) ;
if ( color = = null & & ! ct . isSetRight ( ) ) return ;
CTBorderPr pr = ct . isSetRight ( ) ? ct . getRight ( ) : ct . addNewRight ( ) ;
if ( color ! = null ) pr . setColor ( color . getCTColor ( ) ) ;
else pr . unsetColor ( ) ;
2011-03-04 09:38:13 -05:00
int idx = _stylesSource . putBorder ( new XSSFCellBorder ( ct , _theme ) ) ;
2008-10-05 09:56:28 -04:00
2009-08-18 12:50:24 -04:00
_cellXf . setBorderId ( idx ) ;
_cellXf . setApplyBorder ( true ) ;
2008-10-05 09:56:28 -04:00
}
/ * *
* Set the degree of rotation for the text in the cell
* < p >
* Expressed in degrees . Values range from 0 to 180 . The first letter of
* the text is considered the center - point of the arc .
* < br / >
* For 0 - 90 , the value represents degrees above horizon . For 91 - 180 the degrees below the
* horizon is calculated as :
* < br / >
* < code > [ degrees below horizon ] = 90 - textRotation . < / code >
* < / p >
*
* @param rotation - the rotation degrees ( between 0 and 180 degrees )
* /
2015-08-20 10:28:39 -04:00
@Override
2008-09-15 06:39:37 -04:00
public void setRotation ( short rotation ) {
getCellAlignment ( ) . setTextRotation ( rotation ) ;
}
2008-10-05 09:56:28 -04:00
/ * *
* Set the color to use for the top border
*
* @param color the index of the color definition
2008-10-28 06:03:51 -04:00
* @see org . apache . poi . ss . usermodel . IndexedColors
2008-10-05 09:56:28 -04:00
* /
2015-08-20 10:28:39 -04:00
@Override
2008-09-15 06:39:37 -04:00
public void setTopBorderColor ( short color ) {
2008-10-05 09:56:28 -04:00
XSSFColor clr = new XSSFColor ( ) ;
clr . setIndexed ( color ) ;
setTopBorderColor ( clr ) ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Set the color to use for the top border as a { @link XSSFColor } value
*
* @param color the color to use
* /
public void setTopBorderColor ( XSSFColor color ) {
CTBorder ct = getCTBorder ( ) ;
if ( color = = null & & ! ct . isSetTop ( ) ) return ;
CTBorderPr pr = ct . isSetTop ( ) ? ct . getTop ( ) : ct . addNewTop ( ) ;
if ( color ! = null ) pr . setColor ( color . getCTColor ( ) ) ;
else pr . unsetColor ( ) ;
2011-03-04 09:38:13 -05:00
int idx = _stylesSource . putBorder ( new XSSFCellBorder ( ct , _theme ) ) ;
2008-10-05 09:56:28 -04:00
2009-08-18 12:50:24 -04:00
_cellXf . setBorderId ( idx ) ;
_cellXf . setApplyBorder ( true ) ;
2008-10-05 09:56:28 -04:00
}
/ * *
* Set the type of vertical alignment for the cell
*
* @param align - align the type of alignment
2008-11-07 11:57:23 -05:00
* @see org . apache . poi . ss . usermodel . CellStyle # VERTICAL_TOP
* @see org . apache . poi . ss . usermodel . CellStyle # VERTICAL_CENTER
* @see org . apache . poi . ss . usermodel . CellStyle # VERTICAL_BOTTOM
* @see org . apache . poi . ss . usermodel . CellStyle # VERTICAL_JUSTIFY
* @see org . apache . poi . ss . usermodel . VerticalAlignment
2008-10-05 09:56:28 -04:00
* /
2015-08-20 10:28:39 -04:00
@Override
2008-09-15 06:39:37 -04:00
public void setVerticalAlignment ( short align ) {
getCellAlignment ( ) . setVertical ( VerticalAlignment . values ( ) [ align ] ) ;
}
2008-10-05 09:56:28 -04:00
/ * *
* Set the type of vertical alignment for the cell
*
* @param align - the type of alignment
* /
2008-09-15 06:39:37 -04:00
public void setVerticalAlignment ( VerticalAlignment align ) {
getCellAlignment ( ) . setVertical ( align ) ;
}
2008-10-05 09:56:28 -04:00
/ * *
2008-10-29 15:12:47 -04:00
* Set whether the text should be wrapped .
* < p >
* Setting this flag to < code > true < / code > make all content visible
* whithin a cell by displaying it on multiple lines
* < / p >
2008-10-05 09:56:28 -04:00
*
* @param wrapped a boolean value indicating if the text in a cell should be line - wrapped within the cell .
* /
2015-08-20 10:28:39 -04:00
@Override
2008-09-15 06:39:37 -04:00
public void setWrapText ( boolean wrapped ) {
getCellAlignment ( ) . setWrapText ( wrapped ) ;
}
2008-10-05 09:56:28 -04:00
/ * *
* Gets border color
*
* @param side the border side
* @return the used color
* /
2008-09-15 06:39:37 -04:00
public XSSFColor getBorderColor ( BorderSide side ) {
2008-10-05 09:56:28 -04:00
switch ( side ) {
case BOTTOM :
2008-10-29 15:12:47 -04:00
return getBottomBorderXSSFColor ( ) ;
2008-10-05 09:56:28 -04:00
case RIGHT :
2008-10-29 15:12:47 -04:00
return getRightBorderXSSFColor ( ) ;
2008-10-05 09:56:28 -04:00
case TOP :
2008-10-29 15:12:47 -04:00
return getTopBorderXSSFColor ( ) ;
2008-10-05 09:56:28 -04:00
case LEFT :
2008-10-29 15:12:47 -04:00
return getLeftBorderXSSFColor ( ) ;
2008-10-05 09:56:28 -04:00
default :
throw new IllegalArgumentException ( " Unknown border: " + side ) ;
2008-09-15 06:39:37 -04:00
}
}
2008-10-05 09:56:28 -04:00
/ * *
* Set the color to use for the selected border
*
* @param side - where to apply the color definition
* @param color - the color to use
* /
public void setBorderColor ( BorderSide side , XSSFColor color ) {
switch ( side ) {
case BOTTOM :
setBottomBorderColor ( color ) ;
break ;
case RIGHT :
setRightBorderColor ( color ) ;
break ;
case TOP :
setTopBorderColor ( color ) ;
break ;
case LEFT :
setLeftBorderColor ( color ) ;
break ;
2008-09-15 06:39:37 -04:00
}
}
2015-08-20 10:28:39 -04:00
@Override
2013-11-07 17:28:06 -05:00
public void setShrinkToFit ( boolean shrinkToFit ) {
getCellAlignment ( ) . setShrinkToFit ( shrinkToFit ) ;
}
2008-09-15 06:39:37 -04:00
private int getFontId ( ) {
2009-08-18 12:50:24 -04:00
if ( _cellXf . isSetFontId ( ) ) {
return ( int ) _cellXf . getFontId ( ) ;
2008-09-15 06:39:37 -04:00
}
2009-08-18 12:50:24 -04:00
return ( int ) _cellStyleXf . getFontId ( ) ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* get the cellAlignment object to use for manage alignment
* @return XSSFCellAlignment - cell alignment
* /
protected XSSFCellAlignment getCellAlignment ( ) {
2009-08-18 12:50:24 -04:00
if ( this . _cellAlignment = = null ) {
this . _cellAlignment = new XSSFCellAlignment ( getCTCellAlignment ( ) ) ;
2008-09-15 06:39:37 -04:00
}
2009-08-18 12:50:24 -04:00
return this . _cellAlignment ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Return the CTCellAlignment instance for alignment
*
* @return CTCellAlignment
* /
2008-09-15 06:39:37 -04:00
private CTCellAlignment getCTCellAlignment ( ) {
2009-08-18 12:50:24 -04:00
if ( _cellXf . getAlignment ( ) = = null ) {
_cellXf . setAlignment ( CTCellAlignment . Factory . newInstance ( ) ) ;
2008-09-15 06:39:37 -04:00
}
2009-08-18 12:50:24 -04:00
return _cellXf . getAlignment ( ) ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Returns a hash code value for the object . The hash is derived from the underlying CTXf bean .
*
* @return the hash code value for this style
* /
2015-08-20 10:28:39 -04:00
@Override
2008-10-05 09:56:28 -04:00
public int hashCode ( ) {
2009-08-18 12:50:24 -04:00
return _cellXf . toString ( ) . hashCode ( ) ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Checks is the supplied style is equal to this style
*
* @param o the style to check
* @return true if the supplied style is equal to this style
* /
2015-08-20 10:28:39 -04:00
@Override
2008-10-05 09:56:28 -04:00
public boolean equals ( Object o ) {
if ( o = = null | | ! ( o instanceof XSSFCellStyle ) ) return false ;
2008-09-15 06:39:37 -04:00
2008-10-05 09:56:28 -04:00
XSSFCellStyle cf = ( XSSFCellStyle ) o ;
2009-08-18 12:50:24 -04:00
return _cellXf . toString ( ) . equals ( cf . getCoreXf ( ) . toString ( ) ) ;
2008-09-15 06:39:37 -04:00
}
2008-10-05 09:56:28 -04:00
/ * *
* Make a copy of this style . The underlying CTXf bean is cloned ,
* the references to fills and borders remain .
*
* @return a copy of this style
* /
2015-08-20 10:28:39 -04:00
@Override
2008-10-05 09:56:28 -04:00
public Object clone ( ) {
2009-08-18 12:50:24 -04:00
CTXf xf = ( CTXf ) _cellXf . copy ( ) ;
2008-09-15 06:39:37 -04:00
2009-08-18 12:50:24 -04:00
int xfSize = _stylesSource . _getStyleXfsSize ( ) ;
int indexXf = _stylesSource . putCellXf ( xf ) ;
2010-05-19 07:55:17 -04:00
return new XSSFCellStyle ( indexXf - 1 , xfSize - 1 , _stylesSource , _theme ) ;
2008-09-15 06:39:37 -04:00
}
2008-03-13 07:50:50 -04:00
}