Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * ====================================================================
  3. * Licensed to the Apache Software Foundation (ASF) under one or more
  4. * contributor license agreements. See the NOTICE file distributed with
  5. * this work for additional information regarding copyright ownership.
  6. * The ASF licenses this file to You under the Apache License, Version 2.0
  7. * (the "License"); you may not use this file except in compliance with
  8. * the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. * ====================================================================
  18. */
  19. package org.apache.poi.hslf.usermodel;
  20. import static org.junit.Assert.*;
  21. import java.util.List;
  22. import org.apache.poi.POIDataSamples;
  23. import org.junit.Test;
  24. /**
  25. * Test that checks numbered list functionality.
  26. *
  27. * @author Alex Nikiforov [mailto:anikif@gmail.com]
  28. */
  29. public class TestTable {
  30. private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
  31. @Test
  32. public void testTable() throws Exception {
  33. HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("54111.ppt"));
  34. assertTrue("No Exceptions while reading file", true);
  35. List<HSLFSlide> slides = ppt.getSlides();
  36. assertEquals(1, slides.size());
  37. checkSlide(slides.get(0));
  38. }
  39. private void checkSlide(final HSLFSlide s) {
  40. List<List<HSLFTextParagraph>> textRuns = s.getTextParagraphs();
  41. assertEquals(2, textRuns.size());
  42. HSLFTextRun textRun = textRuns.get(0).get(0).getTextRuns().get(0);
  43. assertEquals("Table sample", textRun.getRawText().trim());
  44. assertEquals(1, textRuns.get(0).get(0).getTextRuns().size());
  45. assertFalse(textRun.getTextParagraph().isBullet());
  46. assertEquals("Dummy text", HSLFTextParagraph.getRawText(textRuns.get(1)));
  47. List<HSLFShape> shapes = s.getShapes();
  48. assertNotNull(shapes);
  49. assertEquals(3, shapes.size());
  50. assertTrue(shapes.get(2) instanceof HSLFTable);
  51. final HSLFTable table = (HSLFTable) shapes.get(2);
  52. assertEquals(4, table.getNumberOfColumns());
  53. assertEquals(6, table.getNumberOfRows());
  54. for (int x = 0; x < 4; x ++) {
  55. assertEquals("TH Cell " + (x + 1), HSLFTextParagraph.getRawText(table.getCell(0, x).getTextParagraphs()));
  56. for (int y = 1; y < 6; y++) {
  57. assertEquals("Row " + y + ", Cell " + (x + 1), table.getCell(y, x).getText());
  58. }
  59. }
  60. }
  61. }