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.

XSSFTableStyle.java 3.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 java.util.EnumMap;
  17. import java.util.Map;
  18. import org.apache.poi.ss.usermodel.DifferentialStyleProvider;
  19. import org.apache.poi.ss.usermodel.TableStyle;
  20. import org.apache.poi.ss.usermodel.TableStyleType;
  21. import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDxf;
  22. import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDxfs;
  23. import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableStyle;
  24. import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableStyleElement;
  25. /**
  26. * {@link TableStyle} implementation for styles defined in the OOXML styles.xml.
  27. * Also used for built-in styles via dummy XML generated from presetTableStyles.xml.
  28. */
  29. public class XSSFTableStyle implements TableStyle {
  30. private final String name;
  31. private final int index;
  32. private final Map<TableStyleType, DifferentialStyleProvider> elementMap = new EnumMap<TableStyleType, DifferentialStyleProvider>(TableStyleType.class);
  33. /**
  34. * @param index style definition index or built-in ordinal depending on use
  35. * @param dxfs
  36. * @param tableStyle
  37. * @param colorMap indexed color map - default or custom
  38. * @see TableStyle#getIndex()
  39. */
  40. public XSSFTableStyle(int index, CTDxfs dxfs, CTTableStyle tableStyle, IndexedColorMap colorMap) {
  41. this.name = tableStyle.getName();
  42. this.index = index;
  43. for (CTTableStyleElement element : tableStyle.getTableStyleElementList()) {
  44. TableStyleType type = TableStyleType.valueOf(element.getType().toString());
  45. DifferentialStyleProvider dstyle = null;
  46. if (element.isSetDxfId()) {
  47. int idx = (int) element.getDxfId();
  48. CTDxf dxf;
  49. if (idx >= 0 && idx < dxfs.getCount()) {
  50. dxf = dxfs.getDxfArray(idx);
  51. } else {
  52. dxf = null;
  53. }
  54. int stripeSize = 0;
  55. if (element.isSetSize()) stripeSize = (int) element.getSize();
  56. if (dxf != null) dstyle = new XSSFDxfStyleProvider(dxf, stripeSize, colorMap);
  57. }
  58. elementMap.put(type, dstyle);
  59. }
  60. }
  61. public String getName() {
  62. return name;
  63. }
  64. public int getIndex() {
  65. return index;
  66. }
  67. /**
  68. * Always false for these, these are user defined styles
  69. */
  70. public boolean isBuiltin() {
  71. return false;
  72. }
  73. public DifferentialStyleProvider getStyle(TableStyleType type) {
  74. return elementMap.get(type);
  75. }
  76. }