Logo Search packages:      
Sourcecode: jexcelapi version File versions  Download package

void jxl::write::biff::WritableSheetImpl::removeColumn ( int  col  )  [inline]

Removes a column from this spreadsheet. If the column is out of range of the columns in the sheet, then no action is taken

Parameters:
col the column to remove

Implements jxl::write::WritableSheet.

Definition at line 836 of file WritableSheetImpl.java.

References autosizedColumns, columnBreaks, columnFormats, jxl::write::biff::WritableWorkbookImpl::columnRemoved(), conditionalFormats, dataValidation, jxl::write::biff::ColumnInfoRecord::decrementColumn(), jxl::write::biff::CellValue::getCellFeatures(), jxl::write::biff::ColumnInfoRecord::getColumn(), jxl::write::biff::HyperlinkRecord::getColumn(), jxl::biff::BaseCellFeatures::getDVParser(), jxl::WorkbookSettings::getFormulaAdjust(), jxl::write::biff::HyperlinkRecord::getLastColumn(), hyperlinks, mergedCells, numColumns, numRows, jxl::biff::ConditionalFormat::removeColumn(), jxl::write::biff::MergedCells::removeColumn(), jxl::biff::DVParser::removeColumn(), jxl::biff::DataValidation::removeColumn(), jxl::write::biff::HyperlinkRecord::removeColumn(), jxl::write::biff::RowRecord::removeColumn(), rows, validatedCells, workbook, and workbookSettings.

  {
    if (col < 0 || col >= numColumns)
    {
      return;
    }

    // Iterate through all the row records removing the column
    for (int i = 0 ; i < numRows ; i++)
    {
      if (rows[i] != null)
      {
        rows[i].removeColumn(col);
      }
    }

    // Adjust any hyperlinks
    HyperlinkRecord hr = null;
    Iterator i = hyperlinks.iterator();
    while (i.hasNext())
    {
      hr = (HyperlinkRecord) i.next();

      if (hr.getColumn()      == col &&
          hr.getLastColumn()  == col)
      {
        // The row with the hyperlink on has been removed, so get
        // rid of it from the list
        i.remove();
      }
      else
      {
        hr.removeColumn(col);
      }
    }

    // Adjust any data validations
    if (dataValidation != null)
    {
      dataValidation.removeColumn(col);
    }

    if (validatedCells != null && validatedCells.size() > 0)
    {
      for (Iterator vci = validatedCells.iterator(); vci.hasNext();)
      {
        CellValue cv = (CellValue) vci.next();
        CellFeatures cf = cv.getCellFeatures();
        if (cf.getDVParser() != null)
        {
          cf.getDVParser().removeColumn(col);
        }
      }
    }

    // Adjust any merged cells
    mergedCells.removeColumn(col);

    // Adjust any page breaks
    ArrayList newColumnBreaks = new ArrayList();
    Iterator ri = columnBreaks.iterator();
    while (ri.hasNext())
    {
      int val = ( (Integer) ri.next()).intValue();

      if (val != col)
      {
        if (val > col)
        {
          val--;
        }
        
        newColumnBreaks.add(new Integer(val));
      }
    }

    columnBreaks = newColumnBreaks;


    // Iterate through the column views, decrementing the column number
    i = columnFormats.iterator();
    ColumnInfoRecord removeColumn = null;
    while (i.hasNext())
    {
      ColumnInfoRecord cir = (ColumnInfoRecord) i.next();

      if (cir.getColumn() == col)
      {
        removeColumn = cir;
      }
      else if (cir.getColumn() > col)
      {
        cir.decrementColumn();
      }
    }

    if (removeColumn != null)
    {
      columnFormats.remove(removeColumn);
    }

    // Iterate through the autosized columns, decrementing the column number
    if (autosizedColumns.size() > 0)
    {
      TreeSet newAutosized = new TreeSet();
      i = autosizedColumns.iterator();
      while (i.hasNext())
      {
        Integer colnumber = (Integer) i.next();

        if (colnumber.intValue() == col)
        {
          // do nothing
        }
        else if (colnumber.intValue() > col)
        {
          newAutosized.add(new Integer(colnumber.intValue() - 1));
        }
        else
        {
          newAutosized.add(colnumber);
        }
      }
      autosizedColumns = newAutosized;
    }

    // Adjust any conditional formats
    for (Iterator cfit = conditionalFormats.iterator(); cfit.hasNext() ;)
    {
      ConditionalFormat cf = (ConditionalFormat) cfit.next();
      cf.removeColumn(col);
    }

    // Handle interested cell references on the main workbook
    if (workbookSettings.getFormulaAdjust())
    {
      workbook.columnRemoved(this, col);
    }

    numColumns--;
  }


Generated by  Doxygen 1.6.0   Back to index