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.

XSSFTableColumn.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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.util.Internal;
  17. import org.apache.poi.xssf.usermodel.helpers.XSSFXmlColumnPr;
  18. import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableColumn;
  19. import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXmlColumnPr;
  20. /**
  21. * A table column of an {@link XSSFTable}. Use {@link XSSFTable#createColumn} to
  22. * create new table columns.
  23. *
  24. * @since 4.0.0
  25. */
  26. public class XSSFTableColumn {
  27. private final XSSFTable table;
  28. private final CTTableColumn ctTableColumn;
  29. private XSSFXmlColumnPr xmlColumnPr;
  30. /**
  31. * Create a new table column.
  32. *
  33. * @param table
  34. * the table which contains the column
  35. * @param ctTableColumn
  36. * the table column xmlbean to wrap
  37. * @since 4.0.0
  38. */
  39. @Internal
  40. protected XSSFTableColumn(XSSFTable table, CTTableColumn ctTableColumn) {
  41. this.table = table;
  42. this.ctTableColumn = ctTableColumn;
  43. }
  44. /**
  45. * Get the table which contains this column
  46. *
  47. * @return the table containing this column
  48. * @since 4.0.0
  49. */
  50. public XSSFTable getTable() {
  51. return table;
  52. }
  53. /**
  54. * Get the identifier of this column, which is is unique per table.
  55. *
  56. * @return the column id
  57. * @since 4.0.0
  58. */
  59. public long getId() {
  60. return ctTableColumn.getId();
  61. }
  62. /**
  63. * Set the identifier of this column, which must be unique per table.
  64. *
  65. * It is up to the caller to enforce the uniqueness of the id.
  66. *
  67. * @param columnId the column id
  68. * @since 4.0.0
  69. */
  70. public void setId(long columnId) {
  71. ctTableColumn.setId(columnId);
  72. }
  73. /**
  74. * Get the name of the column, which is is unique per table.
  75. *
  76. * @return the column name
  77. * @since 4.0.0
  78. */
  79. public String getName() {
  80. return ctTableColumn.getName();
  81. }
  82. /**
  83. * Get the name of the column, which is is unique per table.
  84. *
  85. * @param columnName the column name
  86. * @since 4.0.0
  87. */
  88. public void setName(String columnName) {
  89. ctTableColumn.setName(columnName);
  90. }
  91. /**
  92. * Get the XmlColumnPr (XML column properties) if this column has an XML
  93. * mapping.
  94. *
  95. * @return the XmlColumnPr or <code>null</code> if this column has no XML
  96. * mapping
  97. * @since 4.0.0
  98. */
  99. public XSSFXmlColumnPr getXmlColumnPr() {
  100. if (xmlColumnPr == null) {
  101. CTXmlColumnPr ctXmlColumnPr = ctTableColumn.getXmlColumnPr();
  102. if (ctXmlColumnPr != null) {
  103. xmlColumnPr = new XSSFXmlColumnPr(this, ctXmlColumnPr);
  104. }
  105. }
  106. return xmlColumnPr;
  107. }
  108. /**
  109. * Get the column's position in its table, staring with zero from left to
  110. * right.
  111. *
  112. * @return the column index
  113. * @since 4.0.0
  114. */
  115. public int getColumnIndex() {
  116. return table.findColumnIndex(getName());
  117. }
  118. }