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.

TestXSSFChartSheet.java 3.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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.usermodel;
  16. import org.apache.poi.ss.util.CellAddress;
  17. import org.apache.poi.xssf.XSSFTestDataSamples;
  18. import org.junit.Test;
  19. import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTChartsheet;
  20. import static org.junit.Assert.*;
  21. public final class TestXSSFChartSheet {
  22. @Test
  23. public void testXSSFFactory() {
  24. XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("chart_sheet.xlsx");
  25. assertEquals(4, wb.getNumberOfSheets());
  26. //the third sheet is of type 'chartsheet'
  27. assertEquals("Chart1", wb.getSheetName(2));
  28. assertTrue(wb.getSheetAt(2) instanceof XSSFChartSheet);
  29. assertEquals("Chart1", wb.getSheetAt(2).getSheetName());
  30. final CTChartsheet ctChartsheet = ((XSSFChartSheet) wb.getSheetAt(2)).getCTChartsheet();
  31. assertNotNull(ctChartsheet);
  32. }
  33. @Test
  34. public void testGetAccessors() {
  35. XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("chart_sheet.xlsx");
  36. XSSFChartSheet sheet = (XSSFChartSheet)wb.getSheetAt(2);
  37. assertFalse("Row iterator for charts sheets should return zero rows",
  38. sheet.iterator().hasNext());
  39. //access to a arbitrary row
  40. assertNull(sheet.getRow(1));
  41. //some basic get* accessors
  42. assertEquals(0, sheet.getNumberOfComments());
  43. assertEquals(0, sheet.getNumHyperlinks());
  44. assertEquals(0, sheet.getNumMergedRegions());
  45. assertNull(sheet.getActiveCell());
  46. assertTrue(sheet.getAutobreaks());
  47. //noinspection deprecation
  48. assertNull(sheet.getCellComment(0, 0));
  49. assertNull(sheet.getCellComment(new CellAddress(0, 0)));
  50. assertEquals(0, sheet.getColumnBreaks().length);
  51. assertTrue(sheet.getRowSumsBelow());
  52. assertNotNull(sheet.createDrawingPatriarch());
  53. assertNotNull(sheet.getDrawingPatriarch());
  54. assertNotNull(sheet.getCTChartsheet());
  55. }
  56. @Test
  57. public void testGetCharts() throws Exception {
  58. XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("chart_sheet.xlsx");
  59. XSSFSheet ns = wb.getSheetAt(0);
  60. XSSFChartSheet cs = (XSSFChartSheet)wb.getSheetAt(2);
  61. assertEquals(0, ns.createDrawingPatriarch().getCharts().size());
  62. assertEquals(1, cs.createDrawingPatriarch().getCharts().size());
  63. XSSFChart chart = cs.createDrawingPatriarch().getCharts().get(0);
  64. assertNull(chart.getTitleText());
  65. }
  66. }