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.

XSSFFirstFooter.java 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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.Footer;
  17. import org.apache.poi.xssf.usermodel.extensions.XSSFHeaderFooter;
  18. import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
  19. /**
  20. * <p>
  21. * First page footer content. Corresponds to first printed page.
  22. * The first logical page in the sheet may not be printed, for example, if the print area is specified to
  23. * be a range such that it falls outside the first page's scope.
  24. * </p><p>
  25. * The first page footer is activated by the "Different First" Header/Footer property for the sheet.
  26. * If this property is not set, the first page footer is ignored.
  27. * </p><p>
  28. * Creating a first page header or footer sets this property by default, so all you need to do to
  29. * get an first page header or footer to display is to create one. Likewise, if both the first page
  30. * header and footer are usnset, then this property is unset, and the first page header and footer
  31. * are ignored.
  32. * </p>
  33. */
  34. public class XSSFFirstFooter extends XSSFHeaderFooter implements Footer{
  35. /**
  36. * Create an instance of XSSFFirstFooter from the supplied XML bean
  37. * @see XSSFSheet#getFirstFooter()
  38. */
  39. protected XSSFFirstFooter(CTHeaderFooter headerFooter) {
  40. super(headerFooter);
  41. headerFooter.setDifferentFirst(true);
  42. }
  43. /**
  44. * Get the content text representing the footer
  45. * @return text
  46. */
  47. @Override
  48. public String getText() {
  49. return getHeaderFooter().getFirstFooter();
  50. }
  51. /**
  52. * Set a text for the footer. If null unset the value. If unsetting this header results
  53. * in no First Header, or footer for the sheet, the 'differentFirst' property is unset as well.
  54. *
  55. * @see XSSFHeaderFooter to see how to create a string with Header/Footer Formatting Syntax
  56. * @param text - a string representing the footer.
  57. */
  58. @Override
  59. public void setText(String text) {
  60. if(text == null) {
  61. getHeaderFooter().unsetFirstFooter();
  62. if (!getHeaderFooter().isSetFirstHeader()) {
  63. getHeaderFooter().unsetDifferentFirst();
  64. }
  65. } else {
  66. getHeaderFooter().setFirstFooter(text);
  67. }
  68. }
  69. }