You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TestThemesTable.java 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.xssf.model;
  16. import static org.junit.Assert.assertEquals;
  17. import java.io.FileOutputStream;
  18. import org.apache.commons.codec.binary.Hex;
  19. import org.apache.poi.ss.usermodel.CellStyle;
  20. import org.apache.poi.ss.usermodel.Row;
  21. import org.apache.poi.xssf.XSSFTestDataSamples;
  22. import org.apache.poi.xssf.usermodel.XSSFCellStyle;
  23. import org.apache.poi.xssf.usermodel.XSSFColor;
  24. import org.apache.poi.xssf.usermodel.XSSFFont;
  25. import org.apache.poi.xssf.usermodel.XSSFRow;
  26. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  27. import org.junit.Test;
  28. public class TestThemesTable {
  29. private String testFile = "Themes.xlsx";
  30. @Test
  31. public void testThemesTableColors() throws Exception {
  32. XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook(testFile);
  33. String rgbExpected[] = {
  34. "ffffff", // Lt1
  35. "000000", // Dk1
  36. "eeece1", // Lt2
  37. "1f497d", // DK2
  38. "4f81bd", // Accent1
  39. "c0504d", // Accent2
  40. "9bbb59", // Accent3
  41. "8064a2", // Accent4
  42. "4bacc6", // Accent5
  43. "f79646", // Accent6
  44. "0000ff", // Hlink
  45. "800080" // FolHlink
  46. };
  47. boolean createFile = false;
  48. int i=0;
  49. for (Row row : workbook.getSheetAt(0)) {
  50. XSSFFont font = ((XSSFRow)row).getCell(0).getCellStyle().getFont();
  51. XSSFColor color = font.getXSSFColor();
  52. assertEquals("Failed color theme "+i, rgbExpected[i], Hex.encodeHexString(color.getRgb()));
  53. long themeIdx = font.getCTFont().getColorArray(0).getTheme();
  54. assertEquals("Failed color theme "+i, i, themeIdx);
  55. if (createFile) {
  56. XSSFCellStyle cs = (XSSFCellStyle)row.getSheet().getWorkbook().createCellStyle();
  57. cs.setFillForegroundColor(color);
  58. cs.setFillPattern(CellStyle.SOLID_FOREGROUND);
  59. row.createCell(1).setCellStyle(cs);
  60. }
  61. i++;
  62. }
  63. if (createFile) {
  64. FileOutputStream fos = new FileOutputStream("foobaa.xlsx");
  65. workbook.write(fos);
  66. fos.close();
  67. }
  68. }
  69. }