Package org.apache.poi.hssf.record

Examples of org.apache.poi.hssf.record.ColumnInfoRecord


  }


  public void setColumn(int targetColumnIx, Short xfIndex, Integer width,
          Integer level, Boolean hidden, Boolean collapsed) {
    ColumnInfoRecord ci = null;
    int k  = 0;

    for (k = 0; k < records.size(); k++) {
      ColumnInfoRecord tci = (ColumnInfoRecord) records.get(k);
      if (tci.containsColumn(targetColumnIx)) {
        ci = tci;
        break;
      }
      if (tci.getFirstColumn() > targetColumnIx) {
        // call column infos after k are for later columns
        break; // exit now so k will be the correct insert pos
      }
    }

    if (ci == null) {
      // okay so there ISN'T a column info record that covers this column so lets create one!
      ColumnInfoRecord nci = new ColumnInfoRecord();

      nci.setFirstColumn(targetColumnIx);
      nci.setLastColumn(targetColumnIx);
      setColumnInfoFields( nci, xfIndex, width, level, hidden, collapsed );
      insertColumn(k, nci);
      attemptMergeColInfoRecords(k);
      return;
    }

    boolean styleChanged = xfIndex != null && ci.getXFIndex() != xfIndex.shortValue();
    boolean widthChanged = width != null && ci.getColumnWidth() != width.shortValue();
    boolean levelChanged = level != null && ci.getOutlineLevel() != level.intValue();
    boolean hiddenChanged = hidden != null && ci.getHidden() != hidden.booleanValue();
    boolean collapsedChanged = collapsed != null && ci.getCollapsed() != collapsed.booleanValue();

    boolean columnChanged = styleChanged || widthChanged || levelChanged || hiddenChanged || collapsedChanged;
    if (!columnChanged) {
      // do nothing...nothing changed.
      return;
    }

    if (ci.getFirstColumn() == targetColumnIx && ci.getLastColumn() == targetColumnIx) {
      // ColumnInfo ci for a single column, the target column
      setColumnInfoFields(ci, xfIndex, width, level, hidden, collapsed);
      attemptMergeColInfoRecords(k);
      return;
    }

    if (ci.getFirstColumn() == targetColumnIx || ci.getLastColumn() == targetColumnIx) {
      // The target column is at either end of the multi-column ColumnInfo ci
      // we'll just divide the info and create a new one
      if (ci.getFirstColumn() == targetColumnIx) {
        ci.setFirstColumn(targetColumnIx + 1);
      } else {
        ci.setLastColumn(targetColumnIx - 1);
        k++; // adjust insert pos to insert after
      }
      ColumnInfoRecord nci = copyColInfo(ci);

      nci.setFirstColumn(targetColumnIx);
      nci.setLastColumn(targetColumnIx);
      setColumnInfoFields( nci, xfIndex, width, level, hidden, collapsed );

      insertColumn(k, nci);
      attemptMergeColInfoRecords(k);
    } else {
      //split to 3 records
      ColumnInfoRecord ciStart = ci;
      ColumnInfoRecord ciMid = copyColInfo(ci);
      ColumnInfoRecord ciEnd = copyColInfo(ci);
      int lastcolumn = ci.getLastColumn();
     
      ciStart.setLastColumn(targetColumnIx - 1);

      ciMid.setFirstColumn(targetColumnIx);
      ciMid.setLastColumn(targetColumnIx);
      setColumnInfoFields(ciMid, xfIndex, width, level, hidden, collapsed);
      insertColumn(++k, ciMid);
     
      ciEnd.setFirstColumn(targetColumnIx+1);
      ciEnd.setLastColumn(lastcolumn);
      insertColumn(++k, ciEnd);
      // no need to attemptMergeColInfoRecords because we
      // know both on each side are different
    }
  }
View Full Code Here


    if (fromColInfoIdx < 0) {
      throw new IllegalArgumentException( "fromIdx parameter out of range: " + fromColInfoIdx );
    }

    for (int k = fromColInfoIdx; k < records.size(); k++) {
      ColumnInfoRecord ci = getColInfo(k);
      if (ci.containsColumn(columnIx)) {
        return k;
      }
      if (ci.getFirstColumn() > columnIx) {
        break;
      }
    }
    return -1;
  }
View Full Code Here

    int nRecords = records.size();
    if (colInfoIx < 0 || colInfoIx >= nRecords) {
      throw new IllegalArgumentException("colInfoIx " + colInfoIx
          + " is out of range (0.." + (nRecords-1) + ")");
    }
    ColumnInfoRecord currentCol = getColInfo(colInfoIx);
    int nextIx = colInfoIx+1;
    if (nextIx < nRecords) {
      if (mergeColInfoRecords(currentCol, getColInfo(nextIx))) {
          records.remove(nextIx);
      }
View Full Code Here

   * @return <code>null</code> if no column info found for the specified column
   */
  public ColumnInfoRecord findColumnInfo(int columnIndex) {
    int nInfos = records.size();
    for(int i=0; i< nInfos; i++) {
      ColumnInfoRecord ci = getColInfo(i);
      if (ci.containsColumn(columnIndex)) {
        return ci;
      }
    }
    return null;
  }
View Full Code Here

  }
  public int getMaxOutlineLevel() {
    int result = 0;
    int count=records.size();
    for (int i=0; i<count; i++) {
      ColumnInfoRecord columnInfoRecord = getColInfo(i);
      result = Math.max(columnInfoRecord.getOutlineLevel(), result);
    }
    return result;
  }
View Full Code Here

     * @return index of ExtendedFormatRecord associated with
     * ColumnInfoRecord that includes the column index or the
     * index of the default ExtendedFormatRecord (0xF)
     */
    public short getXFIndexForColAt(short columnIndex) {
        ColumnInfoRecord ci = _columnInfos.findColumnInfo(columnIndex);
        if (ci != null) {
            return (short)ci.getXFIndex();
        }
        return 0xF;
    }
View Full Code Here

     * @see org.apache.poi.hssf.record.ColumnInfoRecord
     * @see #setColumnHidden(int, boolean)
     * @return whether the column is hidden or not.
     */
    public boolean isColumnHidden(int columnIndex) {
        ColumnInfoRecord cir = _columnInfos.findColumnInfo(columnIndex);
        if (cir == null) {
            return false;
        }
        return cir.getHidden();
    }
View Full Code Here

     * @see #setColumnWidth(int, int)
     * @return column width in units of 1/256th of a character width
     */
    public int getColumnWidth(int columnIndex) {

        ColumnInfoRecord ci = _columnInfos.findColumnInfo(columnIndex);
        if (ci != null) {
            return ci.getColumnWidth();
        }
        //default column width is measured in characters
        //multiply
        return (256*defaultcolwidth.getColWidth());
    }
View Full Code Here

*/
public final class TestSheetAdditional extends TestCase {
 
  public void testGetCellWidth() {
    Sheet sheet = Sheet.createSheet();
    ColumnInfoRecord nci = ( ColumnInfoRecord ) sheet.createColInfo();

    // Prepare test model
    nci.setFirstColumn((short)5);
    nci.setLastColumn((short)10);
    nci.setColumnWidth((short)100);
   
   
    sheet.columns.insertColumn(nci);

    assertEquals((short)100,sheet.getColumnWidth((short)5));
View Full Code Here

     * @see #setColumnWidth(int, int)
     * @return column width in units of 1/256th of a character width
     */
    public int getColumnWidth(int columnIndex) {

        ColumnInfoRecord ci = _columnInfos.findColumnInfo(columnIndex);
        if (ci != null) {
            return ci.getColumnWidth();
        }
        //default column width is measured in characters
        //multiply
        return (256*defaultcolwidth.getColWidth());
    }
View Full Code Here

TOP

Related Classes of org.apache.poi.hssf.record.ColumnInfoRecord

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.