1 16 17 package org.apache.poi.hssf.usermodel; 18 19 import org.apache.poi.hssf.model.Workbook; 20 import org.apache.poi.hssf.record.NameRecord; 21 import org.apache.poi.hssf.util.RangeAddress; 22 23 28 29 public class HSSFName { 30 private Workbook book; 31 private NameRecord name; 32 33 40 41 protected HSSFName(Workbook book, NameRecord name) { 42 this.book = book; 43 this.name = name; 44 } 45 46 49 50 public String getSheetName() { 51 String result ; 52 short indexToExternSheet = name.getExternSheetNumber(); 53 54 result = book.findSheetNameFromExternSheet(indexToExternSheet); 55 56 return result; 57 } 58 59 63 64 public String getNameName(){ 65 String result = name.getNameText(); 66 67 return result; 68 } 69 70 74 75 public void setNameName(String nameName){ 76 name.setNameText(nameName); 77 name.setNameTextLength((byte)nameName.length()); 78 } 79 80 84 85 public String getReference() { 86 String result; 87 result = name.getAreaReference(book); 88 89 return result; 90 } 91 92 93 94 98 99 private void setSheetName(String sheetName){ 100 int sheetNumber = book.getSheetIndex(sheetName); 101 102 short externSheetNumber = book.checkExternSheet(sheetNumber); 103 name.setExternSheetNumber(externSheetNumber); 104 106 } 107 108 109 113 114 public void setReference(String ref){ 115 116 RangeAddress ra = new RangeAddress(ref); 117 118 String sheetName = ra.getSheetName(); 119 120 if (ra.hasSheetName()) { 121 setSheetName(sheetName); 122 } 123 124 name.setAreaReference(ref); 126 127 } 128 129 } 130 | Popular Tags |