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.

XSSFDxfStyleProvider.java 3.1KB

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 org.apache.poi.ss.usermodel.BorderFormatting;
  17. import org.apache.poi.ss.usermodel.DifferentialStyleProvider;
  18. import org.apache.poi.ss.usermodel.ExcelNumberFormat;
  19. import org.apache.poi.ss.usermodel.FontFormatting;
  20. import org.apache.poi.ss.usermodel.PatternFormatting;
  21. import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDxf;
  22. import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTNumFmt;
  23. /**
  24. * Style based on a dxf record - e.g. table style element or conditional formatting rule
  25. */
  26. public class XSSFDxfStyleProvider implements DifferentialStyleProvider {
  27. private final IndexedColorMap colorMap;
  28. private final BorderFormatting border;
  29. private final FontFormatting font;
  30. private final ExcelNumberFormat number;
  31. private final PatternFormatting fill;
  32. private final int stripeSize;
  33. /**
  34. * @param stripeSize 0 for non-stripe styles, > 1 for stripes
  35. */
  36. public XSSFDxfStyleProvider(CTDxf dxf, int stripeSize, IndexedColorMap colorMap) {
  37. this.stripeSize = stripeSize;
  38. this.colorMap = colorMap;
  39. if (dxf == null) {
  40. border = null;
  41. font = null;
  42. number = null;
  43. fill = null;
  44. } else {
  45. border = dxf.isSetBorder() ? new XSSFBorderFormatting(dxf.getBorder(), colorMap) : null;
  46. font = dxf.isSetFont() ? new XSSFFontFormatting(dxf.getFont(), colorMap) : null;
  47. if (dxf.isSetNumFmt()) {
  48. CTNumFmt numFmt = dxf.getNumFmt();
  49. number = new ExcelNumberFormat((int) numFmt.getNumFmtId(), numFmt.getFormatCode());
  50. } else {
  51. number = null;
  52. }
  53. fill = dxf.isSetFill() ? new XSSFPatternFormatting(dxf.getFill(), colorMap) : null;
  54. }
  55. }
  56. @Override
  57. public BorderFormatting getBorderFormatting() {
  58. return border;
  59. }
  60. @Override
  61. public FontFormatting getFontFormatting() {
  62. return font;
  63. }
  64. @Override
  65. public ExcelNumberFormat getNumberFormat() {
  66. return number;
  67. }
  68. @Override
  69. public PatternFormatting getPatternFormatting() {
  70. return fill;
  71. }
  72. @Override
  73. public int getStripeSize() {
  74. return stripeSize;
  75. }
  76. }