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.

XSSFCreationHelper.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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.common.usermodel.HyperlinkType;
  17. import org.apache.poi.ss.usermodel.CreationHelper;
  18. import org.apache.poi.ss.usermodel.Hyperlink;
  19. import org.apache.poi.util.Internal;
  20. import org.apache.poi.util.Removal;
  21. import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
  22. public class XSSFCreationHelper implements CreationHelper {
  23. private final XSSFWorkbook workbook;
  24. /**
  25. * Should only be called by {@link XSSFWorkbook#getCreationHelper()}
  26. *
  27. * @param wb the workbook to create objects for
  28. */
  29. @Internal
  30. public XSSFCreationHelper(XSSFWorkbook wb) {
  31. workbook = wb;
  32. }
  33. /**
  34. * Creates a new XSSFRichTextString for you.
  35. */
  36. @Override
  37. public XSSFRichTextString createRichTextString(String text) {
  38. XSSFRichTextString rt = new XSSFRichTextString(text);
  39. rt.setStylesTableReference(workbook.getStylesSource());
  40. return rt;
  41. }
  42. @Override
  43. public XSSFDataFormat createDataFormat() {
  44. return workbook.createDataFormat();
  45. }
  46. @Override
  47. public XSSFColor createExtendedColor() {
  48. return new XSSFColor(CTColor.Factory.newInstance(), workbook.getStylesSource().getIndexedColors());
  49. }
  50. /**
  51. * Create a new XSSFHyperlink.
  52. *
  53. * @param type - the type of hyperlink to create, see {@link HyperlinkType}
  54. * @deprecated POI 3.15 beta 3. Use {@link #createHyperlink(HyperlinkType)} instead.
  55. */
  56. @Deprecated
  57. @Removal(version="3.17")
  58. @Override
  59. public XSSFHyperlink createHyperlink(int type) {
  60. return new XSSFHyperlink(type);
  61. }
  62. /**
  63. * Create a new XSSFHyperlink.
  64. *
  65. * @param type - the type of hyperlink to create, see {@link Hyperlink}
  66. */
  67. @Override
  68. public XSSFHyperlink createHyperlink(HyperlinkType type) {
  69. return new XSSFHyperlink(type);
  70. }
  71. /**
  72. * Creates a XSSFFormulaEvaluator, the object that evaluates formula cells.
  73. *
  74. * @return a XSSFFormulaEvaluator instance
  75. */
  76. @Override
  77. public XSSFFormulaEvaluator createFormulaEvaluator() {
  78. return new XSSFFormulaEvaluator(workbook);
  79. }
  80. /**
  81. * Creates a XSSFClientAnchor. Use this object to position drawing object in
  82. * a sheet
  83. *
  84. * @return a XSSFClientAnchor instance
  85. * @see org.apache.poi.ss.usermodel.Drawing
  86. */
  87. @Override
  88. public XSSFClientAnchor createClientAnchor() {
  89. return new XSSFClientAnchor();
  90. }
  91. }