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.

XSSFXmlColumnPr.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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.helpers;
  16. import org.apache.poi.util.Internal;
  17. import org.apache.poi.util.Removal;
  18. import org.apache.poi.xssf.usermodel.XSSFTable;
  19. import org.apache.poi.xssf.usermodel.XSSFTableColumn;
  20. import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableColumn;
  21. import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXmlColumnPr;
  22. import org.openxmlformats.schemas.spreadsheetml.x2006.main.STXmlDataType.Enum;
  23. /**
  24. *
  25. * This class is a wrapper around the CTXmlColumnPr (Open Office XML Part 4:
  26. * chapter 3.5.1.7)
  27. *
  28. *
  29. * @author Roberto Manicardi
  30. */
  31. public class XSSFXmlColumnPr {
  32. private XSSFTable table;
  33. private XSSFTableColumn tableColumn;
  34. private CTXmlColumnPr ctXmlColumnPr;
  35. /**
  36. * Create a new XSSFXmlColumnPr (XML column properties) wrapper around a
  37. * CTXmlColumnPr.
  38. *
  39. * @param tableColumn
  40. * table column for which the XML column properties are set
  41. * @param ctXmlColumnPr
  42. * the XML column properties xmlbean to wrap
  43. */
  44. @Internal
  45. public XSSFXmlColumnPr(XSSFTableColumn tableColumn, CTXmlColumnPr ctXmlColumnPr) {
  46. this.table = tableColumn.getTable();
  47. this.tableColumn = tableColumn;
  48. this.ctXmlColumnPr = ctXmlColumnPr;
  49. }
  50. @Deprecated
  51. @Removal(version="4.2")
  52. public XSSFXmlColumnPr(XSSFTable table, CTTableColumn ctTableColum, CTXmlColumnPr ctXmlColumnPr) {
  53. this.table = table;
  54. this.tableColumn = table.getColumns().get(table.findColumnIndex(ctTableColum.getName()));
  55. this.ctXmlColumnPr = ctXmlColumnPr;
  56. }
  57. /**
  58. * Get the column for which these XML column properties are set.
  59. *
  60. * @return the table column
  61. * @since 4.0.0
  62. */
  63. public XSSFTableColumn getTableColumn() {
  64. return tableColumn;
  65. }
  66. public long getMapId() {
  67. return ctXmlColumnPr.getMapId();
  68. }
  69. public String getXPath() {
  70. return ctXmlColumnPr.getXpath();
  71. }
  72. /**
  73. * (see Open Office XML Part 4: chapter 3.5.1.3)
  74. *
  75. * @deprecated Use {@link XSSFTableColumn#getId()} instead.
  76. *
  77. * @return An integer representing the unique identifier of this column.
  78. */
  79. @Deprecated
  80. @Removal(version="4.2")
  81. public long getId() {
  82. return tableColumn.getId();
  83. }
  84. /**
  85. * If the XPath is, for example, /Node1/Node2/Node3 and /Node1/Node2 is the common XPath for the table, the local XPath is /Node3
  86. *
  87. * @return the local XPath
  88. */
  89. public String getLocalXPath() {
  90. StringBuilder localXPath = new StringBuilder();
  91. int numberOfCommonXPathAxis = table.getCommonXpath().split("/").length-1;
  92. String[] xPathTokens = ctXmlColumnPr.getXpath().split("/");
  93. for (int i = numberOfCommonXPathAxis; i < xPathTokens.length; i++) {
  94. localXPath.append("/" + xPathTokens[i]);
  95. }
  96. return localXPath.toString();
  97. }
  98. public Enum getXmlDataType() {
  99. return ctXmlColumnPr.getXmlDataType();
  100. }
  101. }