PageRenderTime 51ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/SpudSoft BIRT Excel Emitters Tests/src/uk/co/spudsoft/birt/emitters/excel/tests/BackgroundFormatsTests.java

https://bitbucket.org/xunchangguo/spudsoft-birt-excel-emitters
Java | 132 lines | 78 code | 23 blank | 31 comment | 0 complexity | 840c05775a8d427138df853ac1c235e7 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-3.0
  1. /*************************************************************
  2. * (C) Copyright 2011, 2012 James Talbut.
  3. * jim-emitters@spudsoft.co.uk
  4. *
  5. * This file is part of The SpudSoft BIRT Excel Emitters.
  6. * The SpudSoft BIRT Excel Emitters are free software: you can
  7. * redistribute them and/or modify them under the terms of the
  8. * GNU Lesser General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * The SpudSoft BIRT Excel Emitters are distributed in the hope
  13. * that they will be useful, but WITHOUT ANY WARRANTY;
  14. * without even the implied warranty of MERCHANTABILITY or
  15. * FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public License
  19. * along with the SpudSoft BIRT Excel Emitters.
  20. * If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. *************************************************************/
  23. package uk.co.spudsoft.birt.emitters.excel.tests;
  24. import static org.junit.Assert.assertEquals;
  25. import static org.junit.Assert.assertNotNull;
  26. import java.io.IOException;
  27. import java.io.InputStream;
  28. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  29. import org.apache.poi.hssf.util.HSSFColor;
  30. import org.apache.poi.ss.usermodel.DataFormatter;
  31. import org.apache.poi.ss.usermodel.Sheet;
  32. import org.apache.poi.xssf.usermodel.XSSFColor;
  33. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  34. import org.eclipse.birt.core.exception.BirtException;
  35. import org.junit.Test;
  36. public class BackgroundFormatsTests extends ReportRunner {
  37. @Test
  38. public void testRunReportXlsx() throws BirtException, IOException {
  39. InputStream inputStream = runAndRenderReport("BackgroundColours.rptdesign", "xlsx");
  40. assertNotNull(inputStream);
  41. try {
  42. XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
  43. assertNotNull(workbook);
  44. assertEquals( 1, workbook.getNumberOfSheets() );
  45. assertEquals( "Background Colours Report", workbook.getSheetAt(0).getSheetName());
  46. Sheet sheet = workbook.getSheetAt(0);
  47. assertEquals( 3, this.firstNullRow(sheet));
  48. DataFormatter formatter = new DataFormatter();
  49. assertEquals( "1", formatter.formatCellValue(sheet.getRow(1).getCell(1)));
  50. assertEquals( "2019-10-11 13:18:46", formatter.formatCellValue(sheet.getRow(1).getCell(2)));
  51. assertEquals( "3.1415926536", formatter.formatCellValue(sheet.getRow(1).getCell(3)));
  52. assertEquals( "3.1415926536", formatter.formatCellValue(sheet.getRow(1).getCell(4)));
  53. assertEquals( "false", formatter.formatCellValue(sheet.getRow(1).getCell(5)));
  54. assertEquals( "FF000000", ((XSSFColor)sheet.getRow(0).getCell(0).getCellStyle().getFillForegroundColorColor()).getARGBHex());
  55. assertEquals( "FF000000", ((XSSFColor)sheet.getRow(0).getCell(1).getCellStyle().getFillForegroundColorColor()).getARGBHex());
  56. assertEquals( "FF000000", ((XSSFColor)sheet.getRow(0).getCell(2).getCellStyle().getFillForegroundColorColor()).getARGBHex());
  57. assertEquals( "FF000000", ((XSSFColor)sheet.getRow(0).getCell(3).getCellStyle().getFillForegroundColorColor()).getARGBHex());
  58. assertEquals( "FF000000", ((XSSFColor)sheet.getRow(0).getCell(4).getCellStyle().getFillForegroundColorColor()).getARGBHex());
  59. assertEquals( "FF000000", ((XSSFColor)sheet.getRow(0).getCell(5).getCellStyle().getFillForegroundColorColor()).getARGBHex());
  60. assertEquals( "FF000000", ((XSSFColor)sheet.getRow(0).getCell(6).getCellStyle().getFillForegroundColorColor()).getARGBHex());
  61. /*
  62. assertEquals( null, ((XSSFColor)sheet.getRow(0).getCell(0).getCellStyle().getFillForegroundColorColor()));
  63. assertEquals( null, ((XSSFColor)sheet.getRow(0).getCell(1).getCellStyle().getFillForegroundColorColor()));
  64. assertEquals( null, ((XSSFColor)sheet.getRow(0).getCell(2).getCellStyle().getFillForegroundColorColor()));
  65. assertEquals( null, ((XSSFColor)sheet.getRow(0).getCell(3).getCellStyle().getFillForegroundColorColor()));
  66. assertEquals( null, ((XSSFColor)sheet.getRow(0).getCell(4).getCellStyle().getFillForegroundColorColor()));
  67. assertEquals( null, ((XSSFColor)sheet.getRow(0).getCell(5).getCellStyle().getFillForegroundColorColor()));
  68. assertEquals( null, ((XSSFColor)sheet.getRow(0).getCell(6).getCellStyle().getFillForegroundColorColor()));
  69. */
  70. assertEquals( "FFFF0000", ((XSSFColor)sheet.getRow(1).getCell(1).getCellStyle().getFillForegroundColorColor()).getARGBHex());
  71. assertEquals( "FFFFA500", ((XSSFColor)sheet.getRow(1).getCell(2).getCellStyle().getFillForegroundColorColor()).getARGBHex());
  72. assertEquals( "FFFFFF00", ((XSSFColor)sheet.getRow(1).getCell(3).getCellStyle().getFillForegroundColorColor()).getARGBHex());
  73. assertEquals( "FF008000", ((XSSFColor)sheet.getRow(1).getCell(4).getCellStyle().getFillForegroundColorColor()).getARGBHex());
  74. assertEquals( "FF0000FF", ((XSSFColor)sheet.getRow(1).getCell(5).getCellStyle().getFillForegroundColorColor()).getARGBHex());
  75. assertEquals( "FF800080", ((XSSFColor)sheet.getRow(1).getCell(6).getCellStyle().getFillForegroundColorColor()).getARGBHex());
  76. assertEquals( "FF000000", ((XSSFColor)sheet.getRow(1).getCell(7).getCellStyle().getFillForegroundColorColor()).getARGBHex());
  77. } finally {
  78. inputStream.close();
  79. }
  80. }
  81. @Test
  82. public void testRunReportXls() throws BirtException, IOException {
  83. InputStream inputStream = runAndRenderReport("BackgroundColours.rptdesign", "xls");
  84. assertNotNull(inputStream);
  85. try {
  86. HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
  87. assertNotNull(workbook);
  88. assertEquals( 1, workbook.getNumberOfSheets() );
  89. assertEquals( "Background Colours Report", workbook.getSheetAt(0).getSheetName());
  90. Sheet sheet = workbook.getSheetAt(0);
  91. assertEquals( 3, this.firstNullRow(sheet));
  92. DataFormatter formatter = new DataFormatter();
  93. assertEquals( "1", formatter.formatCellValue(sheet.getRow(1).getCell(1)));
  94. assertEquals( "2019-10-11 13:18:46", formatter.formatCellValue(sheet.getRow(1).getCell(2)));
  95. assertEquals( "3.1415926536", formatter.formatCellValue(sheet.getRow(1).getCell(3)));
  96. assertEquals( "3.1415926536", formatter.formatCellValue(sheet.getRow(1).getCell(4)));
  97. assertEquals( "false", formatter.formatCellValue(sheet.getRow(1).getCell(5)));
  98. assertEquals( "FFFF:0:0", ((HSSFColor)sheet.getRow(1).getCell(1).getCellStyle().getFillForegroundColorColor()).getHexString());
  99. assertEquals( "FFFF:A5A5:0", ((HSSFColor)sheet.getRow(1).getCell(2).getCellStyle().getFillForegroundColorColor()).getHexString());
  100. assertEquals( "FFFF:FFFF:0", ((HSSFColor)sheet.getRow(1).getCell(3).getCellStyle().getFillForegroundColorColor()).getHexString());
  101. assertEquals( "0:8080:0", ((HSSFColor)sheet.getRow(1).getCell(4).getCellStyle().getFillForegroundColorColor()).getHexString());
  102. assertEquals( "0:0:FFFF", ((HSSFColor)sheet.getRow(1).getCell(5).getCellStyle().getFillForegroundColorColor()).getHexString());
  103. assertEquals( "8080:0:8080", ((HSSFColor)sheet.getRow(1).getCell(6).getCellStyle().getFillForegroundColorColor()).getHexString());
  104. assertEquals( "0:0:0", ((HSSFColor)sheet.getRow(1).getCell(7).getCellStyle().getFillForegroundColorColor()).getHexString());
  105. } finally {
  106. inputStream.close();
  107. }
  108. }
  109. }