Package jxl.write

Examples of jxl.write.WritableCell


      for (int rowIdx = 0; rowIdx < nbrSelRows; ++rowIdx)
      {
         for (int colIdx = 0; colIdx < nbrSelCols; ++colIdx)
         {
            WritableCell xlsCell;
            if(ctrl.useGloablPrefsFormatting() && _table.getColumnModel().getColumn(colIdx) instanceof ExtTableColumn)
            {
               ExtTableColumn col = (ExtTableColumn) _table.getColumnModel().getColumn(colIdx);
               xlsCell = getXlsCell(col, colIdx, curRow, _table.getValueAt(selRows[rowIdx], selCols[colIdx]));
            }
View Full Code Here


      {
         return new jxl.write.Label(colIdx, curRow, getDataXLSAsString(cellObj));
      }


      WritableCell ret;
      ColumnDisplayDefinition colDef = col.getColumnDisplayDefinition();
      int colType = colDef.getSqlType();
      switch (colType)
      {
         case Types.BIT:
View Full Code Here

        currentColumn = 0;
        for(Object cellData : rowData)
        {
         if (cellData != null )
         {
           WritableCell cell = null;
         
           if (cellData instanceof NamedEntity)
             cellData = ((NamedEntity)cellData).getName();
           else if (cellData instanceof Text)
             cellData = ((Text)cellData).getValue();
View Full Code Here

  {
    logger.info("Modifying...");

    WritableSheet sheet = w.getSheet("modified");
   
    WritableCell cell = null;
    CellFormat cf = null;
    Label l = null;
    WritableCellFeatures wcf = null;

    // Change the format of cell B4 to be emboldened
    cell = sheet.getWritableCell(1,3);
    WritableFont bold = new WritableFont(WritableFont.ARIAL,
                                         WritableFont.DEFAULT_POINT_SIZE,
                                         WritableFont.BOLD);
    cf = new WritableCellFormat(bold);
    cell.setCellFormat(cf);

    // Change the format of cell B5 to be underlined
    cell = sheet.getWritableCell(1,4);
    WritableFont underline = new WritableFont(WritableFont.ARIAL,
                                              WritableFont.DEFAULT_POINT_SIZE,
                                              WritableFont.NO_BOLD,
                                              false,
                                              UnderlineStyle.SINGLE);
    cf = new WritableCellFormat(underline);
    cell.setCellFormat(cf);

    // Change the point size of cell B6 to be 10 point
    cell = sheet.getWritableCell(1,5);
    WritableFont tenpoint = new WritableFont(WritableFont.ARIAL, 10);
    cf = new WritableCellFormat(tenpoint);
    cell.setCellFormat(cf);

    // Change the contents of cell B7 to read "Label - mod"
    cell = sheet.getWritableCell(1,6);
    if (cell.getType() == CellType.LABEL)
    {
      Label lc = (Label) cell;
      lc.setString(lc.getString() + " - mod");
    }

    // Change cell B10 to display 7 dps
    cell = sheet.getWritableCell(1,9);
    NumberFormat sevendps = new NumberFormat("#.0000000");
    cf = new WritableCellFormat(sevendps);
    cell.setCellFormat(cf);

   
    // Change cell B11 to display in the format 1e4
    cell = sheet.getWritableCell(1,10);
    NumberFormat exp4 = new NumberFormat("0.####E0");
    cf = new WritableCellFormat(exp4);
    cell.setCellFormat(cf);
   
    // Change cell B12 to be normal display
    cell = sheet.getWritableCell(1,11);
    cell.setCellFormat(WritableWorkbook.NORMAL_STYLE);

    // Change the contents of cell B13 to 42
    cell = sheet.getWritableCell(1,12);
    if (cell.getType() == CellType.NUMBER)
    {
      Number n = (Number) cell;
      n.setValue(42);
    }

    // Add 0.1 to the contents of cell B14
    cell = sheet.getWritableCell(1,13);
    if (cell.getType() == CellType.NUMBER)
    {
      Number n = (Number) cell;
      n.setValue(n.getValue() + 0.1);
    }

    // Change the date format of cell B17 to be a custom format
    cell = sheet.getWritableCell(1,16);
    DateFormat df = new DateFormat("dd MMM yyyy HH:mm:ss");
    cf = new WritableCellFormat(df);
    cell.setCellFormat(cf);

    // Change the date format of cell B18 to be a standard format
    cell = sheet.getWritableCell(1,17);
    cf = new WritableCellFormat(DateFormats.FORMAT9);
    cell.setCellFormat(cf);

    // Change the date in cell B19 to be 18 Feb 1998, 11:23:28
    cell = sheet.getWritableCell(1,18);
    if (cell.getType() == CellType.DATE)
    {
      DateTime dt = (DateTime) cell;
      Calendar cal = Calendar.getInstance();
      cal.set(1998, 1, 18, 11, 23, 28);
      Date d = cal.getTime();
      dt.setDate(d);
    }

    // Change the value in B23 to be 6.8.  This should recalculate the
    // formula
    cell = sheet.getWritableCell(1,22);
    if (cell.getType() == CellType.NUMBER)
    {
      Number n = (Number) cell;
      n.setValue(6.8);
    }

    // Change the label in B30.  This will have the effect of making
    // the original string unreferenced
    cell = sheet.getWritableCell(1, 29);
    if (cell.getType() == CellType.LABEL)
    {
      l = (Label) cell;
      l.setString("Modified string contents");
    }
    // Insert a new row (number 35)
    sheet.insertRow(34);

    // Delete row 38 (39 after row has been inserted)
    sheet.removeRow(38);

    // Insert a new column (J)
    sheet.insertColumn(9);

    // Remove a column (L - M after column has been inserted)
    sheet.removeColumn(11);

    // Remove row 44 (contains a hyperlink), and then insert an empty
    // row just to keep the numbers consistent
    sheet.removeRow(43);
    sheet.insertRow(43);

    // Modify the hyperlinks
    WritableHyperlink hyperlinks[] = sheet.getWritableHyperlinks();

    for (int i = 0; i < hyperlinks.length; i++)
    {
      WritableHyperlink wh = hyperlinks[i];
      if (wh.getColumn() == 1 && wh.getRow() == 39)
      {
        try
        {
          // Change the hyperlink that begins in cell B40 to be a different API
          wh.setURL(new URL("http://www.andykhan.com/jexcelapi/index.html"));
        }
        catch (MalformedURLException e)
        {
          logger.warn(e.toString());
        }
      }
      else if (wh.getColumn() == 1 && wh.getRow() == 40)
      {
        wh.setFile(new File("../jexcelapi/docs/overview-summary.html"));
      }
      else if (wh.getColumn() == 1 && wh.getRow() == 41)
      {
        wh.setFile(new File("d:/home/jexcelapi/docs/jxl/package-summary.html"));
      }
      else if (wh.getColumn() == 1 && wh.getRow() == 44)
      {
        // Remove the hyperlink at B45
        sheet.removeHyperlink(wh);
      }
    }
   
    // Change the background of cell F31 from blue to red
    WritableCell c = sheet.getWritableCell(5,30);
    WritableCellFormat newFormat = new WritableCellFormat(c.getCellFormat());
    newFormat.setBackground(Colour.RED);
    c.setCellFormat(newFormat);

    // Modify the contents of the merged cell
    l = new Label(0, 49, "Modified merged cells");
    sheet.addCell(l);

    // Modify the chart data
    Number n = (Number) sheet.getWritableCell(0, 70);
    n.setValue(9);
   
    n = (Number) sheet.getWritableCell(0, 71);
    n.setValue(10);

    n = (Number) sheet.getWritableCell(0, 73);
    n.setValue(4);

    // Add in a cross sheet formula
    Formula f = new Formula(1, 80, "ROUND(COS(original!B10),2)");
    sheet.addCell(f);

    // Add in a formula from the named cells
    f = new Formula(1, 83, "value1+value2");
    sheet.addCell(f);

    // Add in a function formula using named cells
    f = new Formula(1, 84, "AVERAGE(value1,value1*4,value2)");
    sheet.addCell(f);

    // Copy sheet 1 to sheet 3
    //     w.copySheet(0, "copy", 2);

    // Use the cell deep copy feature
    Label label = new Label(0, 88, "Some copied cells", cf);
    sheet.addCell(label);

    label = new Label(0,89, "Number from B9");
    sheet.addCell(label);

    WritableCell wc = sheet.getWritableCell(1, 9).copyTo(1,89);
    sheet.addCell(wc);

    label = new Label(0, 90, "Label from B4 (modified format)");
    sheet.addCell(label);

View Full Code Here

       
      for(int row = 0; row < sheet.getRows(); row++){
        boolean newRowInserted=false;
       
        for(int col = 0; col < sheet.getColumns(); col++){           
          WritableCell cell = sheet.getWritableCell(col,row);
         
          if (cell.getType() == CellType.LABEL)
          {
            Label l = (Label) cell;       
            String expression = l.getString();
           
            if(expression.startsWith("<%=+")){
//System.out.println("expression:"+expression);
             
              if(!newRowInserted){
                newRowInserted = true;
                sheet.insertRow(row);
              }
              //l.setString(expression);
/*
                WritableCell existingCell = sheet.getWritableCell(col,row);
                Label ecl = (Label) existingCell;
                ecl.setString(               
                  EMailActivity.parseContent(expression, this, instance).toString()
                );*/
             
              jxl.format.CellFormat style = l.getCellFormat();
              WritableCell label = new Label(col,row, definition.evaluateContent(instance, expression).toString(), style);
              sheet.addCell(label);
             
            }else
            if(expression.indexOf("<%=") > -1 || expression.indexOf("<%=*") > -1){ //if the expression contains any value need to evaluate.
//System.out.println("expression:"+expression);
              l.setString(
                definition.evaluateContent( instance, expression).toString()
              );
//System.out.println("evaluated:"+l.getString());
            }else
            if(expression.startsWith("<%->")){
              l.setString("");
            }else
            if(expression.startsWith("<%<-")){
              WritableCell leftCell = sheet.getWritableCell(col-1,row);
              Label lcl = (Label) leftCell;         
              lcl.setString(
                definition.evaluateContent(instance, expression).toString()
              );
             
View Full Code Here

            Logger.getLogger(ArchivoExcelBaseConocimiento.class.getName()).log(Level.SEVERE, null, ex);
        }
        if (tipo == ArchivoExcelBaseConocimiento.REGLAS) {
            WritableSheet sheetReglas = libroTrabajoSalida.getSheet(this.hojaConfiguraciones);
            //recordar que primero son las columnas y luego filas
            WritableCell celdaFilas = sheetReglas.getWritableCell(1, 3);
            WritableCell celdaColumnas = sheetReglas.getWritableCell(2, 3);

            if (celdaFilas.getType() == CellType.NUMBER) {
                Number n = (Number) celdaFilas;
                n.setValue(numeroFilas);
            }
            if (celdaColumnas.getType() == CellType.NUMBER) {
                Number n = (Number) celdaColumnas;
                n.setValue(numeroColumnas);
            }
        } else if (tipo == ArchivoExcelBaseConocimiento.NOMBRESPUNTOS) {
            WritableSheet sheetReglas = libroTrabajoSalida.getSheet(this.hojaConfiguraciones);
            //recordar que primero son las columnas y luego filas
            WritableCell celdaFilas = sheetReglas.getWritableCell(1, 2);
            WritableCell celdaColumnas = sheetReglas.getWritableCell(2, 2);

            if (celdaFilas.getType() == CellType.NUMBER) {
                Number n = (Number) celdaFilas;
                n.setValue(numeroFilas);
            }
            if (celdaColumnas.getType() == CellType.NUMBER) {
                Number n = (Number) celdaColumnas;
                n.setValue(numeroColumnas);
            }
        } else if (tipo == ArchivoExcelBaseConocimiento.HEURISTICA) {
            WritableSheet sheetReglas = libroTrabajoSalida.getSheet(this.hojaConfiguraciones);
            //recordar que primero son las columnas y luego filas
            WritableCell celdaFilas = sheetReglas.getWritableCell(1, 1);
            WritableCell celdaColumnas = sheetReglas.getWritableCell(2, 1);

            if (celdaFilas.getType() == CellType.NUMBER) {
                Number n = (Number) celdaFilas;
                n.setValue(numeroFilas);
            }
            if (celdaColumnas.getType() == CellType.NUMBER) {
                Number n = (Number) celdaColumnas;
                n.setValue(numeroColumnas);
            }
        } else if (tipo == ArchivoExcelBaseConocimiento.COORDENADASPUNTOS) {
            WritableSheet sheetReglas = libroTrabajoSalida.getSheet(this.hojaConfiguraciones);
            //recordar que primero son las columnas y luego filas
            WritableCell celdaFilas = sheetReglas.getWritableCell(1, 0);
            WritableCell celdaColumnas = sheetReglas.getWritableCell(2, 0);

            if (celdaFilas.getType() == CellType.NUMBER) {
                Number n = (Number) celdaFilas;
                n.setValue(numeroFilas);
            }
            if (celdaColumnas.getType() == CellType.NUMBER) {
                Number n = (Number) celdaColumnas;
                n.setValue(numeroColumnas);
            }
        }
View Full Code Here

  /*
   * Process a particular cell-zkCell
   */
  private WritableCell exportCell(Cell zkCell, int row, int col) {
    WritableCell wCell = null;
    try {
      Formula formula = zkCell.getFormula();
      if (formula != null) {
        String f = formula.toString();
        wCell = new jxl.write.Formula(col, row, f.substring(1,
View Full Code Here

  private void saveCell( CellInstance _c, WritableWorkbook _xwb, WritableSheet _xs, int _row ) throws JXLException,
      SpreadsheetException
  {
    final int col = _c.getColumnIndex();
    final WritableCell xc = createCell( _c, _xwb, col, _row );
    styleCell( _c.getStyleName(), _xwb, _xs, xc );
    _xs.addCell( xc );
    styleColumn( _c.getStyleName(), _xwb, _xs, col );
  }
View Full Code Here

  private final Map<String, CellFormat> cellStyles = New.map();

  private void extractCellFormatsFrom( WritableWorkbook _xwb )
  {
    for (final String name : _xwb.getRangeNames()) {
      final WritableCell cell = _xwb.findCellByName( name );
      this.cellStyles.put( name, cell.getCellFormat() );
    }
  }
View Full Code Here

                : currentRowIndex;
        int useColumn = uiCell.getColumn() != null ? uiCell.getColumn()
                : currentColumnIndex;

        CellInfo cellInfo = jxlHelper.getCellInfo(uiCell);
        WritableCell cell = JXLHelper.createCell(useColumn, useRow, cellInfo
                .getCellType(), uiCell.getValue(), cellInfo.getCellFormat());
        if (cellInfo.getCellFeatures() != null) {
            cell.setCellFeatures(cellInfo.getCellFeatures());
        }
        try {
            worksheet.addCell(cell);
        } catch (WriteException e) {
            throw new ExcelWorkbookException("Could not add cell", e);
View Full Code Here

TOP

Related Classes of jxl.write.WritableCell

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.