Package jxl.write

Examples of jxl.write.WritableCellFormat


   
    nc = new Number(0,3, 12);
    ws.addCell(nc);

    ws.setColumnView(2, 20);
    WritableCellFormat wcf = new WritableCellFormat();
    wcf.setAlignment(Alignment.RIGHT);
    wcf.setWrap(true);
    CellView cv = new CellView();
    cv.setSize(25 * 256);
    cv.setFormat(wcf);
    ws.setColumnView(3, cv);

    // Add in the formulas
    Formula f = null;
    Label l = null;

    f = new Formula(2,0, "A1+A2");
    ws.addCell(f);
    l = new Label(3, 0, "a1+a2");
    ws.addCell(l);

    f = new Formula(2,1, "A2 * 3");
    ws.addCell(f);
    l = new Label(3,1, "A2 * 3");
    ws.addCell(l);

    f = new Formula(2,2, "A2+A1/2.5");
    ws.addCell(f);
    l = new Label(3,2, "A2+A1/2.5");
    ws.addCell(l);

    f = new Formula(2,3, "3+(a1+a2)/2.5");
    ws.addCell(f);
    l = new Label(3,3, "3+(a1+a2)/2.5");
    ws.addCell(l);

    f = new Formula(2,4, "(a1+a2)/2.5");
    ws.addCell(f);
    l = new Label(3,4, "(a1+a2)/2.5");
    ws.addCell(l);

    f = new Formula(2,5, "15+((a1+a2)/2.5)*17");
    ws.addCell(f);
    l = new Label(3,5, "15+((a1+a2)/2.5)*17");
    ws.addCell(l);

    f = new Formula(2, 6, "SUM(a1:a4)");
    ws.addCell(f);
    l = new Label(3, 6, "SUM(a1:a4)");
    ws.addCell(l);

    f = new Formula(2, 7, "SUM(a1:a4)/4");
    ws.addCell(f);
    l = new Label(3, 7, "SUM(a1:a4)/4");
    ws.addCell(l);

    f = new Formula(2, 8, "AVERAGE(A1:A4)");
    ws.addCell(f);
    l = new Label(3, 8, "AVERAGE(a1:a4)");
    ws.addCell(l);

    f = new Formula(2, 9, "MIN(5,4,1,2,3)");
    ws.addCell(f);
    l = new Label(3, 9, "MIN(5,4,1,2,3)");
    ws.addCell(l);

    f = new Formula(2, 10, "ROUND(3.14159265, 3)");
    ws.addCell(f);
    l = new Label(3, 10, "ROUND(3.14159265, 3)");
    ws.addCell(l);

    f = new Formula(2, 11, "MAX(SUM(A1:A2), A1*A2, POWER(A1, 2))");
    ws.addCell(f);
    l = new Label(3, 11, "MAX(SUM(A1:A2), A1*A2, POWER(A1, 2))");
    ws.addCell(l);

    f = new Formula(2,12, "IF(A2>A1, \"A2 bigger\", \"A1 bigger\")");
    ws.addCell(f);
    l = new Label(3,12, "IF(A2>A1, \"A2 bigger\", \"A1 bigger\")");
    ws.addCell(l);

    f = new Formula(2,13, "IF(A2<=A1, \"A2 smaller\", \"A1 smaller\")");
    ws.addCell(f);
    l = new Label(3,13, "IF(A2<=A1, \"A2 smaller\", \"A1 smaller\")");
    ws.addCell(l);

    f = new Formula(2,14, "IF(A3<=10, \"<= 10\")");
    ws.addCell(f);
    l = new Label(3,14, "IF(A3<=10, \"<= 10\")");
    ws.addCell(l);

    f = new Formula(2, 15, "SUM(1,2,3,4,5)");
    ws.addCell(f);
    l = new Label(3, 15, "SUM(1,2,3,4,5)");
    ws.addCell(l);

    f = new Formula(2, 16, "HYPERLINK(\"http://www.andykhan.com/jexcelapi\", \"JExcelApi Home Page\")");
    ws.addCell(f);
    l = new Label(3, 16, "HYPERLINK(\"http://www.andykhan.com/jexcelapi\", \"JExcelApi Home Page\")");
    ws.addCell(l);

    f = new Formula(2, 17, "3*4+5");
    ws.addCell(f);
    l = new Label(3, 17, "3*4+5");
    ws.addCell(l);

    f = new Formula(2, 18, "\"Plain text formula\"");
    ws.addCell(f);
    l = new Label(3, 18, "Plain text formula");
    ws.addCell(l);

    f = new Formula(2, 19, "SUM(a1,a2,-a3,a4)");
    ws.addCell(f);
    l = new Label(3, 19, "SUM(a1,a2,-a3,a4)");
    ws.addCell(l);

    f = new Formula(2, 20, "2*-(a1+a2)");
    ws.addCell(f);
    l = new Label(3, 20, "2*-(a1+a2)");
    ws.addCell(l);

    f = new Formula(2, 21, "'Number Formats'!B1/2");
    ws.addCell(f);
    l = new Label(3, 21, "'Number Formats'!B1/2");
    ws.addCell(l);

    f = new Formula(2, 22, "IF(F22=0, 0, F21/F22)");
    ws.addCell(f);
    l = new Label(3, 22, "IF(F22=0, 0, F21/F22)");
    ws.addCell(l);

    f = new Formula(2, 23, "RAND()");
    ws.addCell(f);
    l = new Label(3, 23, "RAND()");
    ws.addCell(l);

    StringBuffer buf = new StringBuffer();
    buf.append("'");
    buf.append(workbook.getSheet(0).getName());
    buf.append("'!");
    buf.append(CellReferenceHelper.getCellReference(9, 18));
    buf.append("*25");
    f = new Formula(2, 24, buf.toString());
    ws.addCell(f);
    l = new Label(3, 24, buf.toString());
    ws.addCell(l);

    wcf = new WritableCellFormat(DateFormats.DEFAULT);
    f = new Formula(2, 25, "NOW()", wcf);
    ws.addCell(f);
    l = new Label(3, 25, "NOW()");
    ws.addCell(l);

View Full Code Here


        String f = formula.toString();
        wCell = new jxl.write.Formula(col, row, f.substring(1,
            f.length()));
      } else {
        Object result = zkCell.getResult();
        WritableCellFormat wcf = exportCellFormat(result, zkCell.getFormat());
        if (result instanceof Date) {
          wCell = new jxl.write.DateTime(col, row, (Date) result, wcf);
        } else if (result instanceof Double) {
          wCell = new jxl.write.Number(col, row, ((Double) result)
              .doubleValue(), wcf);
View Full Code Here

    return wCell;
  }

  /* export cell format */
  private WritableCellFormat exportCellFormat(Object data, Format zkFormat) throws WriteException {
    WritableCellFormat cf = null;
    if (zkFormat != null) {
      try {
        // WritableCellFormat
        if (data instanceof Date) {
          jxl.write.DateFormat customDateFormat = new jxl.write.DateFormat(
              zkFormat.getFormatCodes());
          cf = new WritableCellFormat(exportCellFont(zkFormat),
              customDateFormat);
        } else if(data instanceof Double){
          jxl.write.NumberFormat customNumFormat = new jxl.write.NumberFormat(
              zkFormat.getFormatCodes());
          cf = new WritableCellFormat(exportCellFont(zkFormat),
              customNumFormat);
        } else {
          cf = new WritableCellFormat(exportCellFont(zkFormat));
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
View Full Code Here

      WritableWorkbook workbook = null;
      WorkbookSettings ws = new WorkbookSettings();
      ws.setLocale(new Locale("en", "EN"));
      workbook = Workbook.createWorkbook(new File(_url), ws);
      WritableSheet s = workbook.createSheet("test", 0);
      WritableCellFormat cf1 = new WritableCellFormat(
          jxl.write.DateFormats.FORMAT2);

      jxl.write.DateTime dt = new jxl.write.DateTime(0, 1, new Date(),
          cf1);
View Full Code Here

    {
      WritableWorkbook wb = Workbook.createWorkbook(output);
      WritableSheet sheet = wb.createSheet("Foglio 1", 0);
     
      WritableFont wfBold = new WritableFont(WritableFont.COURIER, 8, WritableFont.BOLD);
      WritableCellFormat cfBold = new WritableCellFormat(wfBold);
     
      WritableFont wfNormal = new WritableFont(WritableFont.COURIER, 8, WritableFont.NO_BOLD);
      WritableCellFormat cfNormal = new WritableCellFormat(wfNormal);
      WritableCellFormat cfRight = new WritableCellFormat(wfNormal);
      cfRight.setAlignment(Alignment.RIGHT);
     
      WritableCellFormat cfRightBold = new WritableCellFormat(wfBold);
      cfRightBold.setAlignment(Alignment.RIGHT);
     
      DisplayFormat df = new NumberFormat("###,##0.00");
      WritableCellFormat cfNumber = new WritableCellFormat(wfNormal, df);
      cfNumber.setAlignment(Alignment.RIGHT);
     
      WritableCellFormat cfNumberBold = new WritableCellFormat(wfBold, df);
      cfNumberBold.setAlignment(Alignment.RIGHT);
     
      DisplayFormat df_ = new NumberFormat("########0");
      WritableCellFormat cfIntNumber = new WritableCellFormat(wfNormal, df_);
      cfIntNumber.setAlignment(Alignment.RIGHT);
     
      WritableCellFormat cfIntRightBold = new WritableCellFormat(wfBold, df_);
      cfIntRightBold.setAlignment(Alignment.RIGHT);
     
      WritableCellFormat cfIntRight = new WritableCellFormat(wfNormal, df_);
      cfIntRight.setAlignment(Alignment.RIGHT);
     
      Label cellValue;
      Number cellNumber;
      int col = 0;
      cellValue = new Label(col, 2, "", cfBold);
View Full Code Here

    * @return The cell format
    * @throws WriteException if the creation failed
    */
   public WritableCellFormat createCellFormat(UICell uiCell) throws WriteException
   {
      WritableCellFormat cellFormat = null;
      CellStyle cellStyle = new CellStyle(parser.getCascadedStyleMap(uiCell));

      CellType cellType = cellStyle.forceType != null ? CellType.valueOf(cellStyle.forceType) : uiCell.getDataType();
      switch (cellType)
      {
      case text:
         // Creates a basic text format
         cellFormat = new WritableCellFormat(NumberFormats.TEXT);
         break;
      case number:
         /*
          * If there is no mask, creates a default number format cell If there
          * is a mask, tries to match it against a constant name If the constant
          * can't be created, creates a custom number format from the mask
          */

         if (cellStyle.formatMask == null)
         {
            cellFormat = new WritableCellFormat(NumberFormats.DEFAULT);
         }
         else
         {
            DisplayFormat displayFormat = JXLFactory.createNumberFormat(cellStyle.formatMask);
            if (displayFormat != null)
            {
               cellFormat = new WritableCellFormat(displayFormat);
            }
            else
            {
               try
               {
                  cellFormat = new WritableCellFormat(new NumberFormat(cellStyle.formatMask));
               }
               catch (IllegalArgumentException e)
               {
                  throw new ExcelWorkbookException(Interpolator.instance().interpolate("Could not create number format for mask {0}", cellStyle.formatMask), e);
               }
            }
         }
         break;
      case date:
         /*
          * If there is no mask, creates a default date format cell If there is
          * a mask, tries to match it against a constant name If the constant
          * can't be created, creates a custom date format from the mask
          */

         if (cellStyle.formatMask == null)
         {
            cellFormat = new WritableCellFormat(DateFormats.DEFAULT);
         }
         else
         {
            DisplayFormat displayFormat = JXLFactory.createDateFormat(cellStyle.formatMask);
            if (displayFormat != null)
            {
               cellFormat = new WritableCellFormat(displayFormat);
            }
            else
            {
               try
               {
                  cellFormat = new WritableCellFormat(new DateFormat(cellStyle.formatMask));
               }
               catch (IllegalArgumentException e)
               {
                  throw new ExcelWorkbookException(Interpolator.instance().interpolate("Could not create date format for mask {0}", cellStyle.formatMask), e);
               }
            }
         }
         break;
      case formula:
         cellFormat = new WritableCellFormat();
         break;
      case bool:
         cellFormat = new WritableCellFormat();
         break;
      default:
         cellFormat = new WritableCellFormat();
         break;
      }

      if (cellStyle.alignment != null)
      {
         cellFormat.setAlignment(JXLFactory.createAlignment(cellStyle.alignment));
      }

      if (cellStyle.indentation != null)
      {
         cellFormat.setIndentation(cellStyle.indentation);
      }

      if (cellStyle.locked != null)
      {
         cellFormat.setLocked(cellStyle.locked);
      }

      if (cellStyle.orientation != null)
      {
         cellFormat.setOrientation(JXLFactory.createOrientation(cellStyle.orientation));
      }

      if (cellStyle.shrinkToFit != null)
      {
         cellFormat.setShrinkToFit(cellStyle.shrinkToFit);
      }

      if (cellStyle.verticalAlignment != null)
      {
         cellFormat.setVerticalAlignment(JXLFactory.createVerticalAlignment(cellStyle.verticalAlignment));
      }

      if (cellStyle.wrap != null)
      {
         cellFormat.setWrap(cellStyle.wrap);
      }

      if (cellStyle.font.isUsed())
      {
         cellFormat.setFont(JXLFactory.createFont(cellStyle.font));
      }

      if (cellStyle.leftBorder.isUsed())
      {
         cellFormat.setBorder(JXLFactory.createBorder("left"), JXLFactory.createLineStyle(cellStyle.leftBorder.lineStyle), JXLFactory.createColor(cellStyle.leftBorder.color));
      }
      if (cellStyle.topBorder.isUsed())
      {
         cellFormat.setBorder(JXLFactory.createBorder("top"), JXLFactory.createLineStyle(cellStyle.topBorder.lineStyle), JXLFactory.createColor(cellStyle.topBorder.color));
      }
      if (cellStyle.rightBorder.isUsed())
      {
         cellFormat.setBorder(JXLFactory.createBorder("right"), JXLFactory.createLineStyle(cellStyle.rightBorder.lineStyle), JXLFactory.createColor(cellStyle.rightBorder.color));
      }
      if (cellStyle.bottomBorder.isUsed())
      {
         cellFormat.setBorder(JXLFactory.createBorder("bottom"), JXLFactory.createLineStyle(cellStyle.bottomBorder.lineStyle), JXLFactory.createColor(cellStyle.bottomBorder.color));
      }
      if (cellStyle.background.isUsed())
      {
         cellFormat.setBackground(JXLFactory.createColor(cellStyle.background.color), JXLFactory.createPattern(cellStyle.background.pattern));
      }
      return cellFormat;
   }
View Full Code Here

   {
      if (log.isTraceEnabled())
      {
         log.trace("Getting cell format for #0", uiCell.getId());
      }
      WritableCellFormat cellFormat = cellInfoCache.getCachedCellFormat(uiCell.getId());
      if (cellFormat == null)
      {
         try
         {
            cellFormat = createCellFormat(uiCell);
View Full Code Here

      WritableFont blackFnt =
          new WritableFont(WritableFont.createFont("Arial"), 12, WritableFont.NO_BOLD);
      blackFnt.setColour(Colour.BLACK);
      // 第1行先放空白資料,並設定欄寬--->還沒設定
      //DecisionTable起始先告區(黑底白字)
      WritableCellFormat headCellFmt = new WritableCellFormat();
      //自動換行
      headCellFmt.setWrap(false);
      //水平靠左
      headCellFmt.setAlignment(Alignment.LEFT);
      //垂直置中
      headCellFmt.setVerticalAlignment(VerticalAlignment.TOP);
      //設字形
      headCellFmt.setFont(boldWhiteFnt);
      //設欄位框(細)線
//      headCellFmt.setBorder(Border.ALL,BorderLineStyle.THIN, Colour.BLACK);
      //設定顏色
      headCellFmt.setBackground(Colour.GRAY_80);
     
      //DecisionTable內容橘底黑字
      WritableCellFormat setCellFmt = new WritableCellFormat();
      //自動換行
      setCellFmt.setWrap(true);
      //水平靠左
      setCellFmt.setAlignment(Alignment.LEFT);
      //垂直置中
      setCellFmt.setVerticalAlignment(VerticalAlignment.TOP);
      //設字形
      setCellFmt.setFont(myFont);
      //設欄位框(細)線
      setCellFmt.setBorder(Border.ALL,BorderLineStyle.THIN, Colour.BLACK);
      //設定顏色(粉橘色)
      setCellFmt.setBackground(Colour.TAN);
     
      //DecisionTable內容白底黑字
      WritableCellFormat bodyCellFmt = new WritableCellFormat();
      //自動換行
      bodyCellFmt.setWrap(false);
      //水平靠左
      bodyCellFmt.setAlignment(Alignment.LEFT);
      //垂直置中
      bodyCellFmt.setVerticalAlignment(VerticalAlignment.TOP);
      //設字形
      bodyCellFmt.setFont(myFont);
      //設欄位框(細)線
      bodyCellFmt.setBorder(Border.ALL,BorderLineStyle.THIN, Colour.BLACK);
      //設定顏色
//      bodyCellFmt.setBackground(Colour.BLACK);
     

      //DecisionTable內容藍底黑字
      WritableCellFormat blueCellFmt = new WritableCellFormat();
      //自動換行
      blueCellFmt.setWrap(false);
      //水平靠左
      blueCellFmt.setAlignment(Alignment.LEFT);
      //垂直置中
      blueCellFmt.setVerticalAlignment(VerticalAlignment.TOP);
      //設字形
      blueCellFmt.setFont(myFont);
      //設欄位框(細)線
      blueCellFmt.setBorder(Border.ALL,BorderLineStyle.THIN, Colour.BLACK);
      blueCellFmt.setBackground(Colour.LIGHT_TURQUOISE);

      //DecisionTable內容黃底黑字
      WritableCellFormat yellowCellFmt = new WritableCellFormat();
      //自動換行
      yellowCellFmt.setWrap(false);
      //水平靠左
      yellowCellFmt.setAlignment(Alignment.LEFT);
      //垂直置中
      yellowCellFmt.setVerticalAlignment(VerticalAlignment.TOP);
      //設字形
      yellowCellFmt.setFont(myFont);
      //設欄位框(細)線
      yellowCellFmt.setBorder(Border.ALL,BorderLineStyle.THIN, Colour.BLACK);
      yellowCellFmt.setBackground(Colour.YELLOW);

      //DecisionTable內容綠底黑字
      WritableCellFormat greenCellFmt = new WritableCellFormat();
      //自動換行
      greenCellFmt.setWrap(false);
      //水平靠左
      greenCellFmt.setAlignment(Alignment.LEFT);
      //垂直置中
      greenCellFmt.setVerticalAlignment(VerticalAlignment.TOP);
      //設字形
      greenCellFmt.setFont(myFont);
      //設欄位框(細)線
      greenCellFmt.setBorder(Border.ALL,BorderLineStyle.THIN, Colour.BLACK);
      greenCellFmt.setBackground(Colour.LIGHT_GREEN);
     
      //設列高
//      int row = 0;
//      sheet1.setRowView(row,450);
      //將第row行的欄寬設為100
View Full Code Here

    * @return The cell format
    * @throws WriteException if the creation failed
    */
   public WritableCellFormat createCellFormat(UICell uiCell, CellType cellType) throws WriteException
   {
      WritableCellFormat cellFormat = null;
      CellStyle cellStyle = new CellStyle(parser.getCascadedStyleMap(uiCell));

//      CellType cellType = cellStyle.forceType != null ? CellType.valueOf(cellStyle.forceType) : uiCell.getDataType();
      switch (cellType)
      {
      case text:
         // Creates a basic text format
         cellFormat = new WritableCellFormat(NumberFormats.TEXT);
         break;
      case number:
         /*
          * If there is no mask, creates a default number format cell If there
          * is a mask, tries to match it against a constant name If the constant
          * can't be created, creates a custom number format from the mask
          */

         if (cellStyle.formatMask == null)
         {
            cellFormat = new WritableCellFormat(NumberFormats.DEFAULT);
         }
         else
         {
            DisplayFormat displayFormat = JXLFactory.createNumberFormat(cellStyle.formatMask);
            if (displayFormat != null)
            {
               cellFormat = new WritableCellFormat(displayFormat);
            }
            else
            {
               try
               {
                  cellFormat = new WritableCellFormat(new NumberFormat(cellStyle.formatMask));
               }
               catch (IllegalArgumentException e)
               {
                  throw new ExcelWorkbookException(Interpolator.instance().interpolate("Could not create number format for mask {0}", cellStyle.formatMask), e);
               }
            }
         }
         break;
      case date:
         /*
          * If there is no mask, creates a default date format cell If there is
          * a mask, tries to match it against a constant name If the constant
          * can't be created, creates a custom date format from the mask
          */

         if (cellStyle.formatMask == null)
         {
            cellFormat = new WritableCellFormat(DateFormats.DEFAULT);
         }
         else
         {
            DisplayFormat displayFormat = JXLFactory.createDateFormat(cellStyle.formatMask);
            if (displayFormat != null)
            {
               cellFormat = new WritableCellFormat(displayFormat);
            }
            else
            {
               try
               {
                  cellFormat = new WritableCellFormat(new DateFormat(cellStyle.formatMask));
               }
               catch (IllegalArgumentException e)
               {
                  throw new ExcelWorkbookException(Interpolator.instance().interpolate("Could not create date format for mask {0}", cellStyle.formatMask), e);
               }
            }
         }
         break;
      case formula:
         DisplayFormat displayFormat = getGenericDisplayFormat(cellStyle.formatMask);
         cellFormat = displayFormat != null ? new WritableCellFormat(displayFormat) : new WritableCellFormat();
         break;
      case bool:
         cellFormat = new WritableCellFormat();
         break;
      default:
         cellFormat = new WritableCellFormat();
         break;
      }

      if (cellStyle.alignment != null)
      {
         cellFormat.setAlignment(JXLFactory.createAlignment(cellStyle.alignment));
      }

      if (cellStyle.indentation != null)
      {
         cellFormat.setIndentation(cellStyle.indentation);
      }

      if (cellStyle.locked != null)
      {
         cellFormat.setLocked(cellStyle.locked);
      }

      if (cellStyle.orientation != null)
      {
         cellFormat.setOrientation(JXLFactory.createOrientation(cellStyle.orientation));
      }

      if (cellStyle.shrinkToFit != null)
      {
         cellFormat.setShrinkToFit(cellStyle.shrinkToFit);
      }

      if (cellStyle.verticalAlignment != null)
      {
         cellFormat.setVerticalAlignment(JXLFactory.createVerticalAlignment(cellStyle.verticalAlignment));
      }

      if (cellStyle.wrap != null)
      {
         cellFormat.setWrap(cellStyle.wrap);
      }

      if (cellStyle.font.isUsed())
      {
         cellFormat.setFont(JXLFactory.createFont(cellStyle.font));
      }

      if (cellStyle.leftBorder.isUsed())
      {
         cellFormat.setBorder(JXLFactory.createBorder("left"), JXLFactory.createLineStyle(cellStyle.leftBorder.lineStyle), JXLFactory.createColor(cellStyle.leftBorder.color));
      }
      if (cellStyle.topBorder.isUsed())
      {
         cellFormat.setBorder(JXLFactory.createBorder("top"), JXLFactory.createLineStyle(cellStyle.topBorder.lineStyle), JXLFactory.createColor(cellStyle.topBorder.color));
      }
      if (cellStyle.rightBorder.isUsed())
      {
         cellFormat.setBorder(JXLFactory.createBorder("right"), JXLFactory.createLineStyle(cellStyle.rightBorder.lineStyle), JXLFactory.createColor(cellStyle.rightBorder.color));
      }
      if (cellStyle.bottomBorder.isUsed())
      {
         cellFormat.setBorder(JXLFactory.createBorder("bottom"), JXLFactory.createLineStyle(cellStyle.bottomBorder.lineStyle), JXLFactory.createColor(cellStyle.bottomBorder.color));
      }
      if (cellStyle.background.isUsed())
      {
         cellFormat.setBackground(JXLFactory.createColor(cellStyle.background.color), JXLFactory.createPattern(cellStyle.background.pattern));
      }
      return cellFormat;
   }
View Full Code Here

   {
      if (log.isTraceEnabled())
      {
         log.trace("Getting cell format for #0", uiCell.getId());
      }
      WritableCellFormat cellFormat = cellInfoCache.getCachedCellFormat(uiCell.getId());
      if (cellFormat == null)
      {
         try
         {
            cellFormat = createCellFormat(uiCell, cellType);
View Full Code Here

TOP

Related Classes of jxl.write.WritableCellFormat

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.