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.

Table.java 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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.ss.usermodel;
  16. import java.util.regex.Pattern;
  17. import org.apache.poi.ss.util.CellReference;
  18. /**
  19. * XSSF Only!
  20. * High level abstraction of table in a workbook.
  21. */
  22. public interface Table {
  23. /**
  24. * Regular expression matching a Structured Reference (Table syntax) for XSSF table expressions.
  25. * Public for unit tests
  26. * @see <a href="https://support.office.com/en-us/article/Using-structured-references-with-Excel-tables-F5ED2452-2337-4F71-BED3-C8AE6D2B276E">
  27. * Excel Structured Reference Syntax
  28. * </a>
  29. */
  30. Pattern isStructuredReference = Pattern.compile("[a-zA-Z_\\\\][a-zA-Z0-9._]*\\[.*\\]");
  31. /**
  32. * Get the top-left column index relative to the sheet
  33. * @return table start column index on sheet
  34. */
  35. int getStartColIndex();
  36. /**
  37. * Get the top-left row index on the sheet
  38. * @return table start row index on sheet
  39. */
  40. int getStartRowIndex();
  41. /**
  42. * Get the bottom-right column index on the sheet
  43. * @return table end column index on sheet
  44. */
  45. int getEndColIndex();
  46. /**
  47. * Get the bottom-right row index
  48. * @return table end row index on sheet
  49. */
  50. int getEndRowIndex();
  51. /**
  52. * Get the name of the table.
  53. * @return table name
  54. */
  55. String getName();
  56. /**
  57. * @return name of the table style, if there is one. May be a built-in name or user-defined.
  58. * @since 3.17 beta 1
  59. */
  60. String getStyleName();
  61. /**
  62. * Returns the index of a given named column in the table (names are case insensitive in XSSF).
  63. * Note this list is lazily loaded and cached for performance.
  64. * Changes to the underlying table structure are not reflected in later calls
  65. * unless <code>XSSFTable.updateHeaders()</code> is called to reset the cache.
  66. * @param columnHeader the column header name to get the table column index of
  67. * @return column index corresponding to <code>columnHeader</code>
  68. */
  69. int findColumnIndex(String columnHeader);
  70. /**
  71. * Returns the sheet name that the table belongs to.
  72. * @return sheet name
  73. */
  74. String getSheetName();
  75. /**
  76. * Note: This is misleading. The OOXML spec indicates this is true if the totals row
  77. * has <b><i>ever</i></b> been shown, not whether or not it is currently displayed.
  78. * Use {@link #getTotalsRowCount()} > 0 to decide whether or not the totals row is visible.
  79. * @return true if a totals row has ever been shown for this table
  80. * @since 3.15 beta 2
  81. * @see #getTotalsRowCount()
  82. */
  83. boolean isHasTotalsRow();
  84. /**
  85. * @return 0 for no totals rows, 1 for totals row shown.
  86. * Values > 1 are not currently used by Excel up through 2016, and the OOXML spec
  87. * doesn't define how they would be implemented.
  88. * @since 3.17 beta 1
  89. */
  90. int getTotalsRowCount();
  91. /**
  92. * @return 0 for no header rows, 1 for table headers shown.
  93. * Values > 1 might be used by Excel for pivot tables?
  94. * @since 3.17 beta 1
  95. */
  96. int getHeaderRowCount();
  97. /**
  98. * @return TableStyleInfo for this instance
  99. * @since 3.17 beta 1
  100. */
  101. TableStyleInfo getStyle();
  102. /**
  103. * checks if the given cell is part of the table. Includes checking that they are on the same sheet.
  104. * @param cell
  105. * @return true if the table and cell are on the same sheet and the cell is within the table range.
  106. * @since 3.17 beta 1
  107. * @see #contains(CellReference) (prefered, faster execution and handles undefined cells)
  108. */
  109. default boolean contains(Cell cell) {
  110. if (cell == null) return false;
  111. return contains(new CellReference(cell.getSheet().getSheetName(), cell.getRowIndex(), cell.getColumnIndex(), true, true));
  112. }
  113. /**
  114. * checks if the given cell is part of the table. Includes checking that they are on the same sheet.
  115. * @param cell reference to a possibly undefined cell location
  116. * @return true if the table and cell are on the same sheet and the cell is within the table range.
  117. * @since 3.17 beta 1
  118. */
  119. boolean contains(CellReference cell);
  120. }