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.

XSSFFirstHeader.java 3.1KB

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