mirror of https://github.com/apache/poi.git
Add unit-test which verifies that fill and alignment styles are applied and read back in correctly.
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1676276 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6df5df0919
commit
c97ea4f79a
|
@ -23,16 +23,20 @@ import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
|
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
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.CellStyle;
|
||||||
|
import org.apache.poi.ss.usermodel.DataFormat;
|
||||||
import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
||||||
import org.apache.poi.ss.usermodel.IndexedColors;
|
import org.apache.poi.ss.usermodel.IndexedColors;
|
||||||
import org.apache.poi.ss.usermodel.Row;
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
import org.apache.poi.ss.usermodel.Sheet;
|
import org.apache.poi.ss.usermodel.Sheet;
|
||||||
import org.apache.poi.ss.usermodel.VerticalAlignment;
|
import org.apache.poi.ss.usermodel.VerticalAlignment;
|
||||||
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
import org.apache.poi.xssf.XSSFTestDataSamples;
|
import org.apache.poi.xssf.XSSFTestDataSamples;
|
||||||
import org.apache.poi.xssf.model.StylesTable;
|
import org.apache.poi.xssf.model.StylesTable;
|
||||||
import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder;
|
import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder;
|
||||||
import org.apache.poi.xssf.usermodel.extensions.XSSFCellFill;
|
import org.apache.poi.xssf.usermodel.extensions.XSSFCellFill;
|
||||||
|
import org.junit.Test;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
|
||||||
|
|
||||||
public class TestXSSFCellStyle extends TestCase {
|
public class TestXSSFCellStyle extends TestCase {
|
||||||
|
@ -891,4 +895,50 @@ public class TestXSSFCellStyle extends TestCase {
|
||||||
assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wb));
|
assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wb));
|
||||||
assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wbOrig));
|
assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wbOrig));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetColor() throws IOException {
|
||||||
|
Workbook wb = new XSSFWorkbook();
|
||||||
|
Sheet sheet = wb.createSheet();
|
||||||
|
Row row = sheet.createRow(0);
|
||||||
|
|
||||||
|
//CreationHelper ch = wb.getCreationHelper();
|
||||||
|
DataFormat format = wb.createDataFormat();
|
||||||
|
Cell cell = row.createCell(1);
|
||||||
|
cell.setCellValue("somevalue");
|
||||||
|
CellStyle cellStyle = wb.createCellStyle();
|
||||||
|
|
||||||
|
|
||||||
|
cellStyle.setDataFormat(format.getFormat("###0"));
|
||||||
|
|
||||||
|
cellStyle.setFillBackgroundColor(IndexedColors.DARK_BLUE.getIndex());
|
||||||
|
cellStyle.setFillForegroundColor(IndexedColors.DARK_BLUE.getIndex());
|
||||||
|
cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
|
||||||
|
|
||||||
|
cellStyle.setAlignment(CellStyle.ALIGN_RIGHT);
|
||||||
|
cellStyle.setVerticalAlignment(CellStyle.VERTICAL_TOP);
|
||||||
|
|
||||||
|
cell.setCellStyle(cellStyle);
|
||||||
|
|
||||||
|
/*OutputStream stream = new FileOutputStream("C:\\temp\\CellColor.xlsx");
|
||||||
|
try {
|
||||||
|
wb.write(stream);
|
||||||
|
} finally {
|
||||||
|
stream.close();
|
||||||
|
}*/
|
||||||
|
|
||||||
|
Workbook wbBack = XSSFTestDataSamples.writeOutAndReadBack(wb);
|
||||||
|
Cell cellBack = wbBack.getSheetAt(0).getRow(0).getCell(1);
|
||||||
|
assertNotNull(cellBack);
|
||||||
|
CellStyle styleBack = cellBack.getCellStyle();
|
||||||
|
assertEquals(IndexedColors.DARK_BLUE.getIndex(), styleBack.getFillBackgroundColor());
|
||||||
|
assertEquals(IndexedColors.DARK_BLUE.getIndex(), styleBack.getFillForegroundColor());
|
||||||
|
assertEquals(CellStyle.ALIGN_RIGHT, styleBack.getAlignment());
|
||||||
|
assertEquals(CellStyle.VERTICAL_TOP, styleBack.getVerticalAlignment());
|
||||||
|
assertEquals(CellStyle.SOLID_FOREGROUND, styleBack.getFillPattern());
|
||||||
|
|
||||||
|
wbBack.close();
|
||||||
|
|
||||||
|
wb.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue