Lines 49-61
Link Here
|
49 |
import org.apache.poi.ss.formula.FormulaShifter; |
49 |
import org.apache.poi.ss.formula.FormulaShifter; |
50 |
import org.apache.poi.ss.formula.FormulaType; |
50 |
import org.apache.poi.ss.formula.FormulaType; |
51 |
import org.apache.poi.ss.formula.SheetNameFormatter; |
51 |
import org.apache.poi.ss.formula.SheetNameFormatter; |
52 |
import org.apache.poi.ss.formula.ptg.Area3DPtg; |
|
|
53 |
import org.apache.poi.ss.formula.ptg.MemFuncPtg; |
54 |
import org.apache.poi.ss.formula.ptg.Ptg; |
55 |
import org.apache.poi.ss.formula.ptg.UnionPtg; |
56 |
import org.apache.poi.ss.formula.udf.AggregatingUDFFinder; |
52 |
import org.apache.poi.ss.formula.udf.AggregatingUDFFinder; |
57 |
import org.apache.poi.ss.formula.udf.UDFFinder; |
53 |
import org.apache.poi.ss.formula.udf.UDFFinder; |
58 |
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy; |
54 |
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy; |
|
|
55 |
import org.apache.poi.ss.util.CellRangeAddress; |
59 |
import org.apache.poi.ss.util.WorkbookUtil; |
56 |
import org.apache.poi.ss.util.WorkbookUtil; |
60 |
import org.apache.poi.util.POILogFactory; |
57 |
import org.apache.poi.util.POILogFactory; |
61 |
import org.apache.poi.util.POILogger; |
58 |
import org.apache.poi.util.POILogger; |
Lines 75-82
Link Here
|
75 |
*/ |
72 |
*/ |
76 |
public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.usermodel.Workbook { |
73 |
public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.usermodel.Workbook { |
77 |
private static final Pattern COMMA_PATTERN = Pattern.compile(","); |
74 |
private static final Pattern COMMA_PATTERN = Pattern.compile(","); |
78 |
private static final int MAX_ROW = 0xFFFF; |
|
|
79 |
private static final int MAX_COLUMN = (short)0x00FF; |
80 |
|
75 |
|
81 |
/** |
76 |
/** |
82 |
* The maximum number of cell styles in a .xls workbook. |
77 |
* The maximum number of cell styles in a .xls workbook. |
Lines 957-1036
Link Here
|
957 |
* @param endColumn 0 based end of repeating columns. |
952 |
* @param endColumn 0 based end of repeating columns. |
958 |
* @param startRow 0 based start of repeating rows. |
953 |
* @param startRow 0 based start of repeating rows. |
959 |
* @param endRow 0 based end of repeating rows. |
954 |
* @param endRow 0 based end of repeating rows. |
|
|
955 |
* |
956 |
* @deprecated use {@link HSSFSheet#setRepeatingRows(CellRangeAddress)} |
957 |
* or {@link HSSFSheet#setRepeatingColumns(CellRangeAddress)} |
960 |
*/ |
958 |
*/ |
961 |
public void setRepeatingRowsAndColumns(int sheetIndex, |
959 |
public void setRepeatingRowsAndColumns(int sheetIndex, |
962 |
int startColumn, int endColumn, |
960 |
int startColumn, int endColumn, |
963 |
int startRow, int endRow) |
961 |
int startRow, int endRow) { |
964 |
{ |
962 |
HSSFSheet sheet = getSheetAt(sheetIndex); |
965 |
// Check arguments |
|
|
966 |
if (startColumn == -1 && endColumn != -1) throw new IllegalArgumentException("Invalid column range specification"); |
967 |
if (startRow == -1 && endRow != -1) throw new IllegalArgumentException("Invalid row range specification"); |
968 |
if (startColumn < -1 || startColumn >= MAX_COLUMN) throw new IllegalArgumentException("Invalid column range specification"); |
969 |
if (endColumn < -1 || endColumn >= MAX_COLUMN) throw new IllegalArgumentException("Invalid column range specification"); |
970 |
if (startRow < -1 || startRow > MAX_ROW) throw new IllegalArgumentException("Invalid row range specification"); |
971 |
if (endRow < -1 || endRow > MAX_ROW) throw new IllegalArgumentException("Invalid row range specification"); |
972 |
if (startColumn > endColumn) throw new IllegalArgumentException("Invalid column range specification"); |
973 |
if (startRow > endRow) throw new IllegalArgumentException("Invalid row range specification"); |
974 |
|
963 |
|
975 |
HSSFSheet sheet = getSheetAt(sheetIndex); |
964 |
CellRangeAddress rows = null; |
976 |
short externSheetIndex = getWorkbook().checkExternSheet(sheetIndex); |
965 |
CellRangeAddress cols = null; |
977 |
|
966 |
|
978 |
boolean settingRowAndColumn = |
967 |
if (startRow != -1) { |
979 |
startColumn != -1 && endColumn != -1 && startRow != -1 && endRow != -1; |
968 |
rows = new CellRangeAddress(startRow, endRow, -1, -1); |
980 |
boolean removingRange = |
969 |
} |
981 |
startColumn == -1 && endColumn == -1 && startRow == -1 && endRow == -1; |
970 |
if (startColumn != -1) { |
|
|
971 |
cols = new CellRangeAddress(-1, -1, startColumn, endColumn); |
972 |
} |
982 |
|
973 |
|
983 |
int rowColHeaderNameIndex = findExistingBuiltinNameRecordIdx(sheetIndex, NameRecord.BUILTIN_PRINT_TITLE); |
974 |
sheet.setRepeatingRows(rows); |
984 |
if (removingRange) { |
975 |
sheet.setRepeatingColumns(cols); |
985 |
if (rowColHeaderNameIndex >= 0) { |
|
|
986 |
workbook.removeName(rowColHeaderNameIndex); |
987 |
} |
988 |
return; |
989 |
} |
990 |
boolean isNewRecord; |
991 |
NameRecord nameRecord; |
992 |
if (rowColHeaderNameIndex < 0) { |
993 |
//does a lot of the house keeping for builtin records, like setting lengths to zero etc |
994 |
nameRecord = workbook.createBuiltInName(NameRecord.BUILTIN_PRINT_TITLE, sheetIndex+1); |
995 |
isNewRecord = true; |
996 |
} else { |
997 |
nameRecord = workbook.getNameRecord(rowColHeaderNameIndex); |
998 |
isNewRecord = false; |
999 |
} |
1000 |
|
1001 |
List temp = new ArrayList(); |
1002 |
|
1003 |
if (settingRowAndColumn) { |
1004 |
final int exprsSize = 2 * 11 + 1; // 2 * Area3DPtg.SIZE + UnionPtg.SIZE |
1005 |
temp.add(new MemFuncPtg(exprsSize)); |
1006 |
} |
1007 |
if (startColumn >= 0) { |
1008 |
Area3DPtg colArea = new Area3DPtg(0, MAX_ROW, startColumn, endColumn, |
1009 |
false, false, false, false, externSheetIndex); |
1010 |
temp.add(colArea); |
1011 |
} |
1012 |
if (startRow >= 0) { |
1013 |
Area3DPtg rowArea = new Area3DPtg(startRow, endRow, 0, MAX_COLUMN, |
1014 |
false, false, false, false, externSheetIndex); |
1015 |
temp.add(rowArea); |
1016 |
} |
1017 |
if (settingRowAndColumn) { |
1018 |
temp.add(UnionPtg.instance); |
1019 |
} |
1020 |
Ptg[] ptgs = new Ptg[temp.size()]; |
1021 |
temp.toArray(ptgs); |
1022 |
nameRecord.setNameDefinition(ptgs); |
1023 |
|
1024 |
if (isNewRecord) |
1025 |
{ |
1026 |
HSSFName newName = new HSSFName(this, nameRecord, nameRecord.isBuiltInName() ? null : workbook.getNameCommentRecord(nameRecord)); |
1027 |
names.add(newName); |
1028 |
} |
1029 |
|
1030 |
HSSFPrintSetup printSetup = sheet.getPrintSetup(); |
1031 |
printSetup.setValidSettings(false); |
1032 |
|
1033 |
sheet.setActive(true); |
1034 |
} |
976 |
} |
1035 |
|
977 |
|
1036 |
|
978 |
|
Lines 1050-1055
Link Here
|
1050 |
return -1; |
992 |
return -1; |
1051 |
} |
993 |
} |
1052 |
|
994 |
|
|
|
995 |
|
996 |
HSSFName createBuiltInName(byte builtinCode, int sheetIndex) { |
997 |
NameRecord nameRecord = |
998 |
workbook.createBuiltInName(builtinCode, sheetIndex + 1); |
999 |
HSSFName newName = new HSSFName(this, nameRecord, null); |
1000 |
names.add(newName); |
1001 |
return newName; |
1002 |
} |
1003 |
|
1004 |
|
1005 |
HSSFName getBuiltInName(byte builtinCode, int sheetIndex) { |
1006 |
int index = findExistingBuiltinNameRecordIdx(sheetIndex, builtinCode); |
1007 |
if (index < 0) { |
1008 |
return null; |
1009 |
} else { |
1010 |
return names.get(index); |
1011 |
} |
1012 |
} |
1013 |
|
1014 |
|
1053 |
/** |
1015 |
/** |
1054 |
* create a new Font and add it to the workbook's font table |
1016 |
* create a new Font and add it to the workbook's font table |
1055 |
* @return new font object |
1017 |
* @return new font object |
Lines 1477-1482
Link Here
|
1477 |
} |
1439 |
} |
1478 |
|
1440 |
|
1479 |
|
1441 |
|
|
|
1442 |
/** |
1443 |
* As {@link #getNameIndex(String)} is not necessarily unique |
1444 |
* (name + sheet index is unique), this method is more accurate. |
1445 |
* |
1446 |
* @param name the name whose index in the list of names of this workbook |
1447 |
* should be looked up. |
1448 |
* @return an index value >= 0 if the name was found; -1, if the name was |
1449 |
* not found |
1450 |
*/ |
1451 |
int getNameIndex(HSSFName name) { |
1452 |
for (int k = 0; k < names.size(); k++) { |
1453 |
if (name == names.get(k)) { |
1454 |
return k; |
1455 |
} |
1456 |
} |
1457 |
return -1; |
1458 |
} |
1459 |
|
1460 |
|
1480 |
public void removeName(int index){ |
1461 |
public void removeName(int index){ |
1481 |
names.remove(index); |
1462 |
names.remove(index); |
1482 |
workbook.removeName(index); |
1463 |
workbook.removeName(index); |
Lines 1497-1506
Link Here
|
1497 |
|
1478 |
|
1498 |
public void removeName(String name) { |
1479 |
public void removeName(String name) { |
1499 |
int index = getNameIndex(name); |
1480 |
int index = getNameIndex(name); |
1500 |
|
|
|
1501 |
removeName(index); |
1481 |
removeName(index); |
1502 |
} |
1482 |
} |
1503 |
|
1483 |
|
|
|
1484 |
|
1485 |
/** |
1486 |
* As {@link #removeName(String)} is not necessarily unique |
1487 |
* (name + sheet index is unique), this method is more accurate. |
1488 |
* |
1489 |
* @param name the name to remove. |
1490 |
*/ |
1491 |
void removeName(HSSFName name) { |
1492 |
int index = getNameIndex(name); |
1493 |
removeName(index); |
1494 |
} |
1495 |
|
1504 |
public HSSFPalette getCustomPalette() |
1496 |
public HSSFPalette getCustomPalette() |
1505 |
{ |
1497 |
{ |
1506 |
return new HSSFPalette(workbook.getCustomPalette()); |
1498 |
return new HSSFPalette(workbook.getCustomPalette()); |