support for setting color of sheet tab in XSSF
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1295079 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5baa7440aa
commit
e9d31e7b3e
@ -41,15 +41,7 @@ import org.apache.poi.openxml4j.opc.PackageRelationship;
|
|||||||
import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
|
import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
|
||||||
import org.apache.poi.ss.SpreadsheetVersion;
|
import org.apache.poi.ss.SpreadsheetVersion;
|
||||||
import org.apache.poi.ss.formula.FormulaShifter;
|
import org.apache.poi.ss.formula.FormulaShifter;
|
||||||
import org.apache.poi.ss.usermodel.Cell;
|
import org.apache.poi.ss.usermodel.*;
|
||||||
import org.apache.poi.ss.usermodel.CellRange;
|
|
||||||
import org.apache.poi.ss.usermodel.CellStyle;
|
|
||||||
import org.apache.poi.ss.usermodel.DataValidation;
|
|
||||||
import org.apache.poi.ss.usermodel.DataValidationHelper;
|
|
||||||
import org.apache.poi.ss.usermodel.Footer;
|
|
||||||
import org.apache.poi.ss.usermodel.Header;
|
|
||||||
import org.apache.poi.ss.usermodel.Row;
|
|
||||||
import org.apache.poi.ss.usermodel.Sheet;
|
|
||||||
import org.apache.poi.ss.util.CellRangeAddress;
|
import org.apache.poi.ss.util.CellRangeAddress;
|
||||||
import org.apache.poi.ss.util.CellRangeAddressList;
|
import org.apache.poi.ss.util.CellRangeAddressList;
|
||||||
import org.apache.poi.ss.util.CellReference;
|
import org.apache.poi.ss.util.CellReference;
|
||||||
@ -65,45 +57,7 @@ import org.apache.poi.xssf.usermodel.helpers.XSSFRowShifter;
|
|||||||
import org.apache.xmlbeans.XmlException;
|
import org.apache.xmlbeans.XmlException;
|
||||||
import org.apache.xmlbeans.XmlOptions;
|
import org.apache.xmlbeans.XmlOptions;
|
||||||
import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId;
|
import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTAutoFilter;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBreak;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellFormula;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCommentList;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDataValidation;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDataValidations;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDrawing;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHyperlink;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTLegacyDrawing;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTMergeCell;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTMergeCells;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTOutlinePr;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageBreak;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageMargins;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageSetUpPr;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPane;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPrintOptions;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRow;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSelection;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetCalcPr;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetFormatPr;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetPr;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetProtection;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetView;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetViews;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTablePart;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableParts;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellFormulaType;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPane;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPaneState;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STUnsignedShortHex;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.WorksheetDocument;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* High level representation of a SpreadsheetML worksheet.
|
* High level representation of a SpreadsheetML worksheet.
|
||||||
@ -3218,4 +3172,17 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
public XSSFSheetConditionalFormatting getSheetConditionalFormatting(){
|
public XSSFSheetConditionalFormatting getSheetConditionalFormatting(){
|
||||||
return new XSSFSheetConditionalFormatting(this);
|
return new XSSFSheetConditionalFormatting(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set background color of the sheet tab
|
||||||
|
*
|
||||||
|
* @param colorIndex the indexed color to set, must be a constant from {@link IndexedColors}
|
||||||
|
*/
|
||||||
|
public void setTabColor(int colorIndex){
|
||||||
|
CTSheetPr pr = worksheet.getSheetPr();
|
||||||
|
if(pr == null) pr = worksheet.addNewSheetPr();
|
||||||
|
CTColor color = CTColor.Factory.newInstance();
|
||||||
|
color.setIndexed(colorIndex);
|
||||||
|
pr.setTabColor(color);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -432,4 +432,13 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
|
|||||||
changeSheetNameWithSharedFormulas("shared_formulas.xlsx");
|
changeSheetNameWithSharedFormulas("shared_formulas.xlsx");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testSetTabColor() {
|
||||||
|
XSSFWorkbook wb = new XSSFWorkbook();
|
||||||
|
XSSFSheet sh = wb.createSheet();
|
||||||
|
assertTrue(sh.getCTWorksheet().getSheetPr() == null || !sh.getCTWorksheet().getSheetPr().isSetTabColor());
|
||||||
|
sh.setTabColor(IndexedColors.RED.index);
|
||||||
|
assertTrue(sh.getCTWorksheet().getSheetPr().isSetTabColor());
|
||||||
|
assertEquals(IndexedColors.RED.index,
|
||||||
|
sh.getCTWorksheet().getSheetPr().getTabColor().getIndexed());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user