bug 58996: Don't try to unset fill color if it is not set to avoid invalid access inside the Xml structures
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1729964 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
118b728156
commit
b6de146895
@ -1075,7 +1075,7 @@ public void setBorderTop(short border) {
|
||||
CTFill ct = getCTFill();
|
||||
CTPatternFill ptrn = ct.getPatternFill();
|
||||
if(color == null) {
|
||||
if(ptrn != null) ptrn.unsetBgColor();
|
||||
if(ptrn != null && ptrn.isSetBgColor()) ptrn.unsetBgColor();
|
||||
} else {
|
||||
if(ptrn == null) ptrn = ct.addNewPatternFill();
|
||||
ptrn.setBgColor(color.getCTColor());
|
||||
@ -1129,7 +1129,7 @@ public void setBorderTop(short border) {
|
||||
|
||||
CTPatternFill ptrn = ct.getPatternFill();
|
||||
if(color == null) {
|
||||
if(ptrn != null) ptrn.unsetFgColor();
|
||||
if(ptrn != null && ptrn.isSetFgColor()) ptrn.unsetFgColor();
|
||||
} else {
|
||||
if(ptrn == null) ptrn = ct.addNewPatternFill();
|
||||
ptrn.setFgColor(color.getCTColor());
|
||||
@ -1211,8 +1211,8 @@ public void setBorderTop(short border) {
|
||||
* @see #setFillForegroundColor(short)
|
||||
* @param fp fill pattern (set to {@link org.apache.poi.ss.usermodel.CellStyle#SOLID_FOREGROUND} to fill w/foreground color)
|
||||
*/
|
||||
@Override
|
||||
public void setFillPattern(short fp) {
|
||||
@Override
|
||||
public void setFillPattern(short fp) {
|
||||
CTFill ct = getCTFill();
|
||||
CTPatternFill ptrn = ct.isSetPatternFill() ? ct.getPatternFill() : ct.addNewPatternFill();
|
||||
if(fp == NO_FILL && ptrn.isSetPatternType()) ptrn.unsetPatternType();
|
||||
|
@ -29,15 +29,7 @@ import java.io.IOException;
|
||||
|
||||
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.CellStyle;
|
||||
import org.apache.poi.ss.usermodel.DataFormat;
|
||||
import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
||||
import org.apache.poi.ss.usermodel.IndexedColors;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.VerticalAlignment;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.xssf.XSSFTestDataSamples;
|
||||
import org.apache.poi.xssf.model.StylesTable;
|
||||
import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder;
|
||||
@ -1086,4 +1078,31 @@ public class TestXSSFCellStyle {
|
||||
cellStyle.setRotation((short)-90);
|
||||
assertEquals(180, cellStyle.getRotation());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug58996_UsedToWorkIn3_11_ButNotIn3_13() throws IOException {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
|
||||
XSSFCellStyle cellStyle = workbook.createCellStyle();
|
||||
cellStyle.setFillForegroundColor(null);
|
||||
assertNull(cellStyle.getFillForegroundColorColor());
|
||||
|
||||
cellStyle.setFillBackgroundColor(null);
|
||||
assertNull(cellStyle.getFillBackgroundColorColor());
|
||||
|
||||
cellStyle.setFillPattern(FillPatternType.NO_FILL);
|
||||
assertEquals(FillPatternType.NO_FILL, cellStyle.getFillPatternEnum());
|
||||
|
||||
cellStyle.setBottomBorderColor(null);
|
||||
assertNull(cellStyle.getBottomBorderXSSFColor());
|
||||
|
||||
cellStyle.setTopBorderColor(null);
|
||||
assertNull(cellStyle.getTopBorderXSSFColor());
|
||||
|
||||
cellStyle.setLeftBorderColor(null);
|
||||
assertNull(cellStyle.getLeftBorderXSSFColor());
|
||||
|
||||
cellStyle.setRightBorderColor(null);
|
||||
assertNull(cellStyle.getRightBorderXSSFColor());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user