PageRenderTime 163ms CodeModel.GetById 12ms RepoModel.GetById 7ms app.codeStats 0ms

/components/forks/poi/src/loci/poi/hssf/usermodel/HSSFName.java

http://github.com/openmicroscopy/bioformats
Java | 163 lines | 53 code | 34 blank | 76 comment | 5 complexity | 196154e641f5a4ffb8ae5561ac1278ec MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, Apache-2.0, BSD-2-Clause, MPL-2.0-no-copyleft-exception
  1. /*
  2. * #%L
  3. * Fork of Apache Jakarta POI.
  4. * %%
  5. * Copyright (C) 2008 - 2013 Open Microscopy Environment:
  6. * - Board of Regents of the University of Wisconsin-Madison
  7. * - Glencoe Software, Inc.
  8. * - University of Dundee
  9. * %%
  10. * Licensed under the Apache License, Version 2.0 (the "License");
  11. * you may not use this file except in compliance with the License.
  12. * You may obtain a copy of the License at
  13. *
  14. * http://www.apache.org/licenses/LICENSE-2.0
  15. *
  16. * Unless required by applicable law or agreed to in writing, software
  17. * distributed under the License is distributed on an "AS IS" BASIS,
  18. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. * See the License for the specific language governing permissions and
  20. * limitations under the License.
  21. * #L%
  22. */
  23. /* ====================================================================
  24. Licensed to the Apache Software Foundation (ASF) under one or more
  25. contributor license agreements. See the NOTICE file distributed with
  26. this work for additional information regarding copyright ownership.
  27. The ASF licenses this file to You under the Apache License, Version 2.0
  28. (the "License"); you may not use this file except in compliance with
  29. the License. You may obtain a copy of the License at
  30. http://www.apache.org/licenses/LICENSE-2.0
  31. Unless required by applicable law or agreed to in writing, software
  32. distributed under the License is distributed on an "AS IS" BASIS,
  33. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  34. See the License for the specific language governing permissions and
  35. limitations under the License.
  36. ==================================================================== */
  37. package loci.poi.hssf.usermodel;
  38. import loci.poi.hssf.model.Workbook;
  39. import loci.poi.hssf.record.BoundSheetRecord;
  40. import loci.poi.hssf.record.NameRecord;
  41. import loci.poi.hssf.util.RangeAddress;
  42. /**
  43. * Title: High Level Represantion of Named Range <P>
  44. * REFERENCE: <P>
  45. * @author Libin Roman (Vista Portal LDT. Developer)
  46. */
  47. public class HSSFName {
  48. private Workbook book;
  49. private NameRecord name;
  50. /** Creates new HSSFName - called by HSSFWorkbook to create a sheet from
  51. * scratch.
  52. *
  53. * @see loci.poi.hssf.usermodel.HSSFWorkbook#createName()
  54. * @param name the Name Record
  55. * @param book lowlevel Workbook object associated with the sheet.
  56. */
  57. protected HSSFName(Workbook book, NameRecord name) {
  58. this.book = book;
  59. this.name = name;
  60. }
  61. /** Get the sheets name which this named range is referenced to
  62. * @return sheet name, which this named range refered to
  63. */
  64. public String getSheetName() {
  65. String result ;
  66. short indexToExternSheet = name.getExternSheetNumber();
  67. result = book.findSheetNameFromExternSheet(indexToExternSheet);
  68. return result;
  69. }
  70. /**
  71. * gets the name of the named range
  72. * @return named range name
  73. */
  74. public String getNameName(){
  75. String result = name.getNameText();
  76. return result;
  77. }
  78. /**
  79. * sets the name of the named range
  80. * @param nameName named range name to set
  81. */
  82. public void setNameName(String nameName){
  83. name.setNameText(nameName);
  84. name.setNameTextLength((byte)nameName.length());
  85. //Check to ensure no other names have the same case-insensitive name
  86. for ( int i = book.getNumNames()-1; i >=0; i-- )
  87. {
  88. NameRecord rec = book.getNameRecord(i);
  89. if (rec != name) {
  90. if (rec.getNameText().equalsIgnoreCase(getNameName()))
  91. throw new IllegalArgumentException("The workbook already contains this name (case-insensitive)");
  92. }
  93. }
  94. }
  95. /**
  96. * gets the reference of the named range
  97. * @return reference of the named range
  98. */
  99. public String getReference() {
  100. String result;
  101. result = name.getAreaReference(book);
  102. return result;
  103. }
  104. /**
  105. * sets the sheet name which this named range referenced to
  106. * @param sheetName the sheet name of the reference
  107. */
  108. private void setSheetName(String sheetName){
  109. int sheetNumber = book.getSheetIndex(sheetName);
  110. short externSheetNumber = book.checkExternSheet(sheetNumber);
  111. name.setExternSheetNumber(externSheetNumber);
  112. // name.setIndexToSheet(externSheetNumber);
  113. }
  114. /**
  115. * sets the reference of this named range
  116. * @param ref the reference to set
  117. */
  118. public void setReference(String ref){
  119. RangeAddress ra = new RangeAddress(ref);
  120. String sheetName = ra.getSheetName();
  121. if (ra.hasSheetName()) {
  122. setSheetName(sheetName);
  123. }
  124. //allow the poi utilities to parse it out
  125. name.setAreaReference(ref);
  126. }
  127. }