📄 sheet.java
字号:
// System.arraycopy(rec, 0, data, offset + pos, rec.length); Record record = (( Record ) records.get(k)); //uncomment to test record sizes// byte[] data2 = new byte[record.getRecordSize()];// record.serialize(0, data2 ); // rec.length;// if (LittleEndian.getUShort(data2, 2) != record.getRecordSize() - 4// && record instanceof RowRecordsAggregate == false && record instanceof ValueRecordsAggregate == false)// throw new RuntimeException("Blah!!!"); pos += record.serialize(pos + offset, data ); // rec.length; } log.log(log.DEBUG, "Sheet.serialize returning "); return pos; } /** * Create a row record. (does not add it to the records contained in this sheet) * * @param row number * @return RowRecord created for the passed in row number * @see org.apache.poi.hssf.record.RowRecord */ public RowRecord createRow(int row) { log.log(log.DEBUG, "create row number " + row); RowRecord rowrec = new RowRecord(); //rowrec.setRowNumber(( short ) row); rowrec.setRowNumber(row); rowrec.setHeight(( short ) 0xff); rowrec.setOptimize(( short ) 0x0); rowrec.setOptionFlags(( short ) 0x0); rowrec.setXFIndex(( short ) 0x0); return rowrec; } /** * Create a LABELSST Record (does not add it to the records contained in this sheet) * * @param row the row the LabelSST is a member of * @param col the column the LabelSST defines * @param index the index of the string within the SST (use workbook addSSTString method) * @return LabelSSTRecord newly created containing your SST Index, row,col. * @see org.apache.poi.hssf.record.SSTRecord */ //public LabelSSTRecord createLabelSST(short row, short col, int index) public LabelSSTRecord createLabelSST(int row, short col, int index) { log.logFormatted(log.DEBUG, "create labelsst row,col,index %,%,%", new int[] { row, col, index }); LabelSSTRecord rec = new LabelSSTRecord(); rec.setRow(row); rec.setColumn(col); rec.setSSTIndex(index); rec.setXFIndex(( short ) 0x0f); return rec; } /** * Create a NUMBER Record (does not add it to the records contained in this sheet) * * @param row the row the NumberRecord is a member of * @param col the column the NumberRecord defines * @param value for the number record * * @return NumberRecord for that row, col containing that value as added to the sheet */ //public NumberRecord createNumber(short row, short col, double value) public NumberRecord createNumber(int row, short col, double value) { log.logFormatted(log.DEBUG, "create number row,col,value %,%,%", new double[] { row, col, value }); NumberRecord rec = new NumberRecord(); //rec.setRow(( short ) row); rec.setRow(row); rec.setColumn(col); rec.setValue(value); rec.setXFIndex(( short ) 0x0f); return rec; } /** * create a BLANK record (does not add it to the records contained in this sheet) * * @param row - the row the BlankRecord is a member of * @param col - the column the BlankRecord is a member of */ //public BlankRecord createBlank(short row, short col) public BlankRecord createBlank(int row, short col) { //log.logFormatted(log.DEBUG, "create blank row,col %,%", new short[] log.logFormatted(log.DEBUG, "create blank row,col %,%", new int[] { row, col }); BlankRecord rec = new BlankRecord(); //rec.setRow(( short ) row); rec.setRow(row); rec.setColumn(col); rec.setXFIndex(( short ) 0x0f); return rec; } /** * Attempts to parse the formula into PTGs and create a formula record * DOES NOT WORK YET * * @param row - the row for the formula record * @param col - the column of the formula record * @param formula - a String representing the formula. To be parsed to PTGs * @return bogus/useless formula record */ //public FormulaRecord createFormula(short row, short col, String formula) public FormulaRecord createFormula(int row, short col, String formula) { log.logFormatted(log.DEBUG, "create formula row,col,formula %,%,%", //new short[] new int[] { row, col }, formula); FormulaRecord rec = new FormulaRecord(); rec.setRow(row); rec.setColumn(col); rec.setOptions(( short ) 2); rec.setValue(0); rec.setXFIndex(( short ) 0x0f); FormulaParser fp = new FormulaParser(formula,null); //fix - do we need this method? fp.parse(); Ptg[] ptg = fp.getRPNPtg(); int size = 0; for (int k = 0; k < ptg.length; k++) { size += ptg[ k ].getSize(); rec.pushExpressionToken(ptg[ k ]); } rec.setExpressionLength(( short ) size); return rec; } /** * Adds a value record to the sheet's contained binary records * (i.e. LabelSSTRecord or NumberRecord). * <P> * This method is "loc" sensitive. Meaning you need to set LOC to where you * want it to start searching. If you don't know do this: setLoc(getDimsLoc). * When adding several rows you can just start at the last one by leaving loc * at what this sets it to. * * @param row the row to add the cell value to * @param col the cell value record itself. */ //public void addValueRecord(short row, CellValueRecordInterface col) public void addValueRecord(int row, CellValueRecordInterface col) { checkCells(); log.logFormatted(log.DEBUG, "add value record row,loc %,%", new int[] { row, loc }); DimensionsRecord d = ( DimensionsRecord ) records.get(getDimsLoc()); if (col.getColumn() > d.getLastCol()) { d.setLastCol(( short ) (col.getColumn() + 1)); } if (col.getColumn() < d.getFirstCol()) { d.setFirstCol(col.getColumn()); } cells.insertCell(col); /* * for (int k = loc; k < records.size(); k++) * { * Record rec = ( Record ) records.get(k); * * if (rec.getSid() == RowRecord.sid) * { * RowRecord rowrec = ( RowRecord ) rec; * * if (rowrec.getRowNumber() == col.getRow()) * { * records.add(k + 1, col); * loc = k; * if (rowrec.getLastCol() <= col.getColumn()) * { * rowrec.setLastCol((( short ) (col.getColumn() + 1))); * } * break; * } * } * } */ } /** * remove a value record from the records array. * * This method is not loc sensitive, it resets loc to = dimsloc so no worries. * * @param row - the row of the value record you wish to remove * @param col - a record supporting the CellValueRecordInterface. * @see org.apache.poi.hssf.record.CellValueRecordInterface */ //public void removeValueRecord(short row, CellValueRecordInterface col) public void removeValueRecord(int row, CellValueRecordInterface col) { checkCells(); log.logFormatted(log.DEBUG, "remove value record row,dimsloc %,%", new int[]{row, dimsloc} ); loc = dimsloc; cells.removeCell(col); /* * for (int k = loc; k < records.size(); k++) * { * Record rec = ( Record ) records.get(k); * * // checkDimsLoc(rec,k); * if (rec.isValue()) * { * CellValueRecordInterface cell = * ( CellValueRecordInterface ) rec; * * if ((cell.getRow() == col.getRow()) * && (cell.getColumn() == col.getColumn())) * { * records.remove(k); * break; * } * } * } */ } /** * replace a value record from the records array. * * This method is not loc sensitive, it resets loc to = dimsloc so no worries. * * @param newval - a record supporting the CellValueRecordInterface. this will replace * the cell value with the same row and column. If there isn't one, one will * be added. */ public void replaceValueRecord(CellValueRecordInterface newval) { checkCells(); setLoc(dimsloc); log.log(log.DEBUG, "replaceValueRecord "); cells.insertCell(newval); /* * CellValueRecordInterface oldval = getNextValueRecord(); * * while (oldval != null) * { * if (oldval.isEqual(newval)) * { * records.set(( short ) (getLoc() - 1), newval); * return; * } * oldval = getNextValueRecord(); * } * addValueRecord(newval.getRow(), newval); * setLoc(dimsloc); */ } /** * Adds a row record to the sheet * * <P> * This method is "loc" sensitive. Meaning you need to set LOC to where you * want it to start searching. If you don't know do this: setLoc(getDimsLoc). * When adding several rows you can just start at the last one by leaving loc * at what this sets it to. * * @param row the row record to be added * @see #setLoc(int) */ public void addRow(RowRecord row) { checkRows(); log.log(log.DEBUG, "addRow "); DimensionsRecord d = ( DimensionsRecord ) records.get(getDimsLoc()); if (row.getRowNumber() > d.getLastRow()) { d.setLastRow(row.getRowNumber() + 1); } if (row.getRowNumber() < d.getFirstRow()) { d.setFirstRow(row.getRowNumber()); } //IndexRecord index = null; //If the row exists remove it, so that any cells attached to the row are removed RowRecord existingRow = rows.getRow(row.getRowNumber()); if (existingRow != null) rows.removeRow(existingRow); rows.insertRow(row); /* * for (int k = loc; k < records.size(); k++) * { * Record rec = ( Record ) records.get(k); * * if (rec.getSid() == IndexRecord.sid) * { * index = ( IndexRecord ) rec; * } * if (rec.getSid() == RowRecord.sid) * { * RowRecord rowrec = ( RowRecord ) rec; * * if (rowrec.getRowNumber() > row.getRowNumber()) * { * records.add(k, row); * loc = k; * break; * } * } * if (rec.getSid() == WindowTwoRecord.sid) * { * records.add(k, row); * loc = k; * break; * } * } * if (index != null) * { * if (index.getLastRowAdd1() <= row.getRowNumber()) * { * index.setLastRowAdd1(row.getRowNumber() + 1); * } * } */ log.log(log.DEBUG, "exit addRow"); } /** * Removes a row record * * This method is not loc sensitive, it resets loc to = dimsloc so no worries. * * @param row the row record to remove */ public void removeRow(RowRecord row) { checkRows(); // IndexRecord index = null; setLoc(getDimsLoc()); rows.removeRow(row); /* * for (int k = loc; k < records.size(); k++) * { * Record rec = ( Record ) records.get(k); * * // checkDimsLoc(rec,k); * if (rec.getSid() == RowRecord.sid) * { * RowRecord rowrec = ( RowRecord ) rec;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -