Package jxl.write

Examples of jxl.write.WritableSheet


   private boolean writeXLS(File file, boolean includeHeaders, int nbrSelCols, int[] selCols, int nbrSelRows, TableExportCsvController ctrl, int[] selRows)
      throws IOException, WriteException
   {
      WritableWorkbook workbook = Workbook.createWorkbook(file);
      WritableSheet sheet = workbook.createSheet("Squirrel SQL Export", 0);


      int curRow= 0;
      if (includeHeaders)
      {
         for (int colIdx = 0; colIdx < nbrSelCols; ++colIdx)
         {
            String columnName = _table.getColumnName(selCols[colIdx]);
            jxl.write.Label label = new jxl.write.Label(colIdx, curRow, columnName);
            sheet.addCell(label);
         }
         curRow++;
      }


      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]));
            }
            else
            {
               xlsCell = getXlsCell(null, colIdx, curRow, _table.getValueAt(selRows[rowIdx], selCols[colIdx]));
            }
            sheet.addCell(xlsCell);

         }
         curRow++;
      }
View Full Code Here


            os = new FileOutputStream(tmpfile);

            WritableWorkbook workbook = Workbook.createWorkbook(os);

            int r = 0;
            WritableSheet sheet = null;
            int sheetNumber = 0;

            int oldType = -1;
            for (StatSubscription statSub : statSubscriptions)
            {
                boolean changedType = false;
                if (oldType != statSub.getTypeDef())
                {
                    changedType = true;
                    r = 0;
                }
                oldType = statSub.getTypeDef();
                SummaryStatBean statdetails = getStatBean(context, service,
                        statSub);

                r++;
                if (statdetails == null)
                    continue;

                SummaryStatBean.StatDataBean statDataBean = statdetails
                        .getData().get(0);

                if (changedType)
                {
                    sheet = workbook.createSheet(I18nUtil.getMessage("it.cilea.hku.statistics.Subscribe.sheet." + statdetails.getType()),
                            sheetNumber);
                    WritableFont labelFont = new WritableFont(
                            WritableFont.ARIAL, 10, WritableFont.BOLD);
                    WritableCellFormat cfobj = new WritableCellFormat(labelFont);
                    sheet.addCell(new Label(
                            0,
                            0,
                            I18nUtil.getMessage("it.cilea.hku.statistics.Subscribe.type"),
                            cfobj));
                    sheet.addCell(new Label(
                            1,
                            0,
                            I18nUtil.getMessage("it.cilea.hku.statistics.Subscribe.name"),
                            cfobj));
                    sheet.addCell(new Label(
                            2,
                            0,
                            I18nUtil.getMessage("it.cilea.hku.statistics.Subscribe.url"),
                            cfobj));
                    sheet.addCell(new Label(
                            3,
                            0,
                            I18nUtil.getMessage("it.cilea.hku.statistics.Subscribe.totalView"),
                            cfobj));
                    sheet.addCell(new Label(4, 0, I18nUtil
                            .getMessage("it.cilea.hku.statistics.Subscribe."
                                    + sfreq + "View"), cfobj));

                    int headerCell = 4;
                    if (statDataBean.isShowSelectedObjectDownload())
                    {
                        sheet.addCell(new Label(
                                ++headerCell,
                                0,
                                I18nUtil.getMessage("it.cilea.hku.statistics.Subscribe.totalDownload"),
                                cfobj));
                        sheet.addCell(new Label(++headerCell, 0, I18nUtil
                                .getMessage("it.cilea.hku.statistics.Subscribe."
                                        + sfreq + "Download"), cfobj));
                    }
                    for (String topKey : statDataBean
                            .getPeriodAndTotalTopView().keySet())
                    {
                        if (!statDataBean.getPeriodAndTotalTopView()
                                .get(topKey).isEmpty())
                        {
                            sheet.addCell(new Label(
                                    ++headerCell,
                                    0,
                                    I18nUtil.getMessage("it.cilea.hku.statistics.Subscribe.total"
                                            + topKey + "View"), cfobj));
                            sheet.addCell(new Label(
                                    ++headerCell,
                                    0,
                                    I18nUtil.getMessage("it.cilea.hku.statistics.Subscribe."
                                            + sfreq + topKey + "View"), cfobj));
                        }
                    }
                    for (String topKey : statDataBean
                            .getPeriodAndTotalTopDownload().keySet())
                    {
                        if (!statDataBean.getPeriodAndTotalTopDownload()
                                .get(topKey).isEmpty())
                        {
                            sheet.addCell(new Label(
                                    ++headerCell,
                                    0,
                                    I18nUtil.getMessage("it.cilea.hku.statistics.Subscribe.total"
                                            + topKey + "Download"), cfobj));
                            sheet.addCell(new Label(
                                    ++headerCell,
                                    0,
                                    I18nUtil.getMessage("it.cilea.hku.statistics.Subscribe."
                                            + sfreq + topKey + "Download"), cfobj));
                        }
                    }
                    for (int i = 0; i < headerCell; i++)
                    {
                        final CellView view = sheet.getColumnView(i);
                        view.setAutosize(true);
                        sheet.setColumnView(i, view);
                    }
                    sheetNumber++;
                }
                sheet.addCell(new Label(0, r, I18nUtil
                        .getMessage("it.cilea.hku.statistics.Subscribe.type."
                                + statdetails.getType())));
                sheet.addCell(new Label(1, r, statdetails.getObjectName()));
                sheet.addCell(new Label(2, r, statdetails.getObjectURL()));
                if (statDataBean.getTotalSelectedView() == -1)
                {
                    sheet.addCell(new Label(3, r, I18nUtil
                            .getMessage("it.cilea.hku.statistics.Subscribe.na")));
                }
                else
                {
                    sheet.addCell(new Label(3, r, new Long(statDataBean
                            .getTotalSelectedView()).toString()));
                }

                if (statDataBean.getPeriodSelectedView() == -1)
                {
                    sheet.addCell(new Label(4, r, I18nUtil
                            .getMessage("it.cilea.hku.statistics.Subscribe.na")));
                }
                else
                {
                    sheet.addCell(new Label(4, r, new Long(statDataBean
                            .getPeriodSelectedView()).toString()));
                }

                int countTopCell = 4;
                if (statDataBean.isShowSelectedObjectDownload())
                {
                    if (statDataBean.getTotalSelectedDownload() == -1)
                    {
                        sheet.addCell(new Label(
                                ++countTopCell,
                                r,
                                I18nUtil.getMessage("it.cilea.hku.statistics.Subscribe.na")));
                    }
                    else
                    {
                        sheet.addCell(new Label(++countTopCell, r, new Long(
                                statDataBean.getTotalSelectedDownload())
                                .toString()));
                    }
                    if (statDataBean.getPeriodSelectedDownload() == -1)
                    {
                        sheet.addCell(new Label(
                                ++countTopCell,
                                r,
                                I18nUtil.getMessage("it.cilea.hku.statistics.Subscribe.na")));
                    }
                    else
                    {
                        sheet.addCell(new Label(++countTopCell, r, new Long(
                                statDataBean.getPeriodSelectedDownload())
                                .toString()));
                    }

                }
                for (String topKey : statDataBean.getPeriodAndTotalTopView()
                        .keySet())
                {
                    List<Long> tmpList = statDataBean
                            .getPeriodAndTotalTopView().get(topKey);
                    if (!tmpList.isEmpty())
                    {
                        if (tmpList.get(1) == null)
                        {
                            sheet.addCell(new Label(
                                    ++countTopCell,
                                    r,
                                    I18nUtil.getMessage("it.cilea.hku.statistics.Subscribe.na")));
                        }
                        else
                        {
                            sheet.addCell(new Label(++countTopCell, r,
                                    new Long(tmpList.get(1)).toString()));
                        }
                    }
                    if (!tmpList.isEmpty())
                    {
                        if (tmpList.get(0) == null)
                        {
                            sheet.addCell(new Label(
                                    ++countTopCell,
                                    r,
                                    I18nUtil.getMessage("it.cilea.hku.statistics.Subscribe.na")));
                        }
                        else
                        {
                            sheet.addCell(new Label(++countTopCell, r,
                                    new Long(tmpList.get(0)).toString()));
                        }
                    }
                }
                for (String topKey : statDataBean
                        .getPeriodAndTotalTopDownload().keySet())
                {
                    List<Long> tmpList = statDataBean
                            .getPeriodAndTotalTopDownload().get(topKey);
                    if (!tmpList.isEmpty())
                    {
                        if (tmpList.get(1) == null)
                        {
                            sheet.addCell(new Label(
                                    ++countTopCell,
                                    r,
                                    I18nUtil.getMessage("it.cilea.hku.statistics.Subscribe.na")));
                        }
                        else
                        {
                            sheet.addCell(new Label(++countTopCell, r,
                                    new Long(tmpList.get(1)).toString()));
                        }
                    }
                    if (!tmpList.isEmpty())
                    {
                        if (tmpList.get(0) == null)
                        {
                            sheet.addCell(new Label(
                                    ++countTopCell,
                                    r,
                                    I18nUtil.getMessage("it.cilea.hku.statistics.Subscribe.na")));
                        }
                        else
                        {
                            sheet.addCell(new Label(++countTopCell, r,
                                    new Long(tmpList.get(0)).toString()));
                        }
                    }
                }
View Full Code Here

            IllegalArgumentException, IllegalAccessException,
            InvocationTargetException
    {

        WritableWorkbook workbook = Workbook.createWorkbook(os);
        WritableSheet sheet = workbook.createSheet("Sheet", 0);

        // create initial caption (other caption could be write field together)
        int x = 0;
        sheet.addCell(new Label(x++, 0, "staffNo"));
        sheet.addCell(new Label(x++, 0, "rp"));
        sheet.addCell(new Label(x++, 0, "rp url"));

        // row index
        int i = 1;
        for (ResearcherPage rp : rps)
        {
            int y = 0;
            sheet.addCell(new Label(0, i, ""));
            Label label = (Label) sheet.getCell(0, i);
            label.setString(rp.getSourceID());
            y++;
            sheet.addCell(new Label(1, i, ""));
            label = (Label) sheet.getCell(1, i);
            label.setString(ResearcherPageUtils.getPersistentIdentifier(rp));
            y++;
            sheet.addCell(new Label(2, i, ""));
            label = (Label) sheet.getCell(2, i);
            label.setString(ConfigurationManager.getProperty("dspace.url")
                    + "/cris/" + rp.getPublicPath() + "/"
                    + ResearcherPageUtils.getPersistentIdentifier(rp));

            for (IContainable containable : metadata)
View Full Code Here

  public void writeExcel(Map<Point, String> toWrite, String filename, int rowBegin, int rowEnd, int colBegin,
      int colEnd) throws IOException, RowsExceededException, WriteException {
    OutputStream os = new FileOutputStream(filename);
    WritableWorkbook wwb = Workbook.createWorkbook(os);
    WritableSheet ws = wwb.createSheet("fuck sf", 0);
    int x, y;// д����У�������
    int i, j;
    for (i = rowBegin, x = 0; i < rowEnd; i++, x++) {
      for (j = colBegin, y = 0; j < colEnd; j++, y++) {
        String content = toWrite.get(new Point(j, i));
        if (!isInteger(content) && j == 0) {
          x--;
          break;
        }
        jxl.write.Label labelC = new jxl.write.Label(y, x, content);
        ws.addCell(labelC);
      }
    }
    wwb.write();
    wwb.close();
    os.close();
View Full Code Here

      try {
        workBook = Workbook.createWorkbook(outputStream);
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
      WritableSheet sheet = workBook.createSheet("Results", 0);
 
      // Generates Headers Cells
      WritableFont headerFont = new WritableFont(WritableFont.TAHOMA, 12, WritableFont.BOLD);
      WritableCellFormat headerCellFormat = new WritableCellFormat(headerFont);
     // headerCellFormat.setBackground(Colour.PALE_BLUE);
     
      int currentRow = 0;
      int currentColumn = 0;
     
      List<String> headers = getHeaders(selectedReport, reportedMethods);
     
      for(String header : headers)
      try {
        sheet.addCell(new Label(currentColumn++, currentRow, header, headerCellFormat));
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
   
 
      // Generates Data Cells
      WritableFont dataFont = new WritableFont(WritableFont.TAHOMA, 12);
      WritableCellFormat dataCellFormat = new WritableCellFormat(dataFont);
      WritableCellFormat dateCellFormat = new WritableCellFormat(dataFont, DateFormats.FORMAT2);
     
     
      for(Object row : getRows(selectedReport))
      {
        List<Object> rowData = renderRow(reportedMethods, row);
        if(rowData.size() != headers.size())
          throw new RuntimeException( String.format(
                      "Wrong number of columns returned when rendering row %s, against headers %s",
                      row.toString(), headers.toString()));
        currentRow++;
        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();
          
           else if (cellData instanceof Email)
             cellData = ((Email)cellData).getEmail();
          
           if (cellData instanceof Number)
           {
             cell = new jxl.write.Number(currentColumn, currentRow, ((Number)cellData).doubleValue(), dataCellFormat);
           } else if (cellData instanceof Date)
           {
             cell = new DateTime(currentColumn, currentRow, (Date)cellData, dateCellFormat);
           } else
           {
             if (!(cellData instanceof String) )
               cellData = cellData.toString();
           
             cell = new Label(currentColumn, currentRow, (String)cellData, dataCellFormat);
            
           }      
          
          
           try {
            sheet.addCell(cell);
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
         }
         currentColumn++;
View Full Code Here

   */
  public void writeXLS(String savaPath, String sheetName, int index,int rows, String[] contents) {
    WritableWorkbook workbook = null;
      try {
        workbook = Workbook.createWorkbook(new File(savaPath));    // 创建可写入的Excel工作薄
        WritableSheet ws = workbook.createSheet(sheetName, index)// 创建可写入的Excel工作表
        int cols = contents.length / rows;              // 根据行数得出列数,在数据库里比较容易得到行数
        for (int row = 0; row < rows; row++) {
          for (int col = 0; col < cols; col++) {
            Label label = new Label(col, row,contents[col + row * cols]);
            ws.addCell(label); // 添加Label对象,单元格内容
          }
        }
        workbook.write(); // 写入excel
        workbook.close(); // 关闭对象,释放资源
      } catch (FileNotFoundException e) {
View Full Code Here

   */
  public static void writeXLS(OutputStream os,int rows, List datas) {
    WritableWorkbook workbook = null;
    try {
      workbook = Workbook.createWorkbook(os);          // 创建可写入的Excel工作薄
      WritableSheet ws = workbook.createSheet("Sheet1", 0)// 创建可写入的Excel工作表
      int cols = datas.size() / rows;              // 根据行数得出列数,在数据库里比较容易得到行数
      for (int row = 0; row < rows; row++) {
        for (int col = 0; col < cols; col++) {
          Label label = new Label(col, row,(String) datas.get(col + row * cols));
          ws.addCell(label); // 添加Label对象,单元格内容
        }
      }
      workbook.write(); // 写入excel
      workbook.close(); // 关闭对象,释放资源
    } catch (IOException e) {
View Full Code Here

   */
  private void modify(WritableWorkbook w) throws WriteException
  {
    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);

    wc = sheet.getWritableCell(1, 3).copyTo(1,90);
    sheet.addCell(wc);

    label = new Label(0, 91, "Date from B17");
    sheet.addCell(label);

    wc = sheet.getWritableCell(1, 16).copyTo(1,91);
    sheet.addCell(wc);

    label = new Label(0, 92, "Boolean from E16");
    sheet.addCell(label);

    wc = sheet.getWritableCell(4, 15).copyTo(1,92);
    sheet.addCell(wc);

    label = new Label(0, 93, "URL from B40");
    sheet.addCell(label);

    wc = sheet.getWritableCell(1, 39).copyTo(1,93);
    sheet.addCell(wc);

    // Add some numbers for the formula copy
    for (int i = 0 ; i < 6; i++)
    {
      Number number = new Number(1,94+i, i + 1 + i/8.0);
      sheet.addCell(number);
    }

    label = new Label(0,100, "Formula from B27");
    sheet.addCell(label);

    wc = sheet.getWritableCell(1, 26).copyTo(1,100);
    sheet.addCell(wc);

    label = new Label(0,101, "A brand new formula");
    sheet.addCell(label);
   
    Formula formula = new Formula(1, 101, "SUM(B94:B96)");
    sheet.addCell(formula);

    label = new Label(0,102, "A copy of it");
    sheet.addCell(label);

    wc = sheet.getWritableCell(1,101).copyTo(1, 102);
    sheet.addCell(wc);

    // Remove the second image from the sheet
    WritableImage wi = sheet.getImage(1);
    sheet.removeImage(wi);

    wi = new WritableImage(1, 116, 2, 9,
                           new File("resources/littlemoretonhall.png"));
    sheet.addImage(wi);

    // Add a list data validations
    label = new Label(0, 151, "Added drop down validation");
    sheet.addCell(label);

    Blank b = new Blank(1, 151);
    wcf = new WritableCellFeatures();
    ArrayList al = new ArrayList();
    al.add("The Fellowship of the Ring");
    al.add("The Two Towers");
    al.add("The Return of the King");
    wcf.setDataValidationList(al);
    b.setCellFeatures(wcf);
    sheet.addCell(b);

    // Add a number data validation
    label = new Label(0, 152, "Added number validation 2.718 < x < 3.142");
    sheet.addCell(label);
    b = new Blank(1,152);
    wcf = new WritableCellFeatures();
    wcf.setNumberValidation(2.718, 3.142, wcf.BETWEEN);
    b.setCellFeatures(wcf);
    sheet.addCell(b);

    // Modify the text in the first cell with a comment
    cell = sheet.getWritableCell(0, 156);
    l = (Label) cell;
    l.setString("Label text modified");

    cell = sheet.getWritableCell(0, 157);
    wcf = cell.getWritableCellFeatures();
    wcf.setComment("modified comment text");

    cell = sheet.getWritableCell(0, 158);
    wcf = cell.getWritableCellFeatures();
    wcf.removeComment();
  }
View Full Code Here

    WorkbookSettings ws = new WorkbookSettings();
    ws.setLocale(new Locale("en", "EN"));
    workbook = Workbook.createWorkbook(new File(filename), ws);


    WritableSheet s2 = workbook.createSheet("Number Formats", 0);
    WritableSheet s3 = workbook.createSheet("Date Formats", 1);
    WritableSheet s1 = workbook.createSheet("Label Formats", 2);
    WritableSheet s4 = workbook.createSheet("Borders", 3);
    WritableSheet s5 = workbook.createSheet("Labels", 4);
    WritableSheet s6 = workbook.createSheet("Formulas", 5);
    WritableSheet s7 = workbook.createSheet("Images", 6);
    //    WritableSheet s8 = workbook.createSheet
    //      ("'Illegal chars in name !*%^?': which exceeds max name length",7);

    // Modify the colour palette to bright red for the lime colour
    workbook.setColourRGB(Colour.LIME, 0xff, 0, 0);
View Full Code Here

    }

    @Override
    public void writeAll() throws FileNotFoundException, IOException{
        WritableWorkbook workbook = Workbook.createWorkbook(outputFile);
        WritableSheet sheet = workbook.createSheet("results", 0);

        try {
            sheet.addCell(new Label(0, 0, "NUMBER OF PILE ELEMENTS"));
            sheet.addCell(new Label(0, 1, "PILE LENGTH (m)"));
            sheet.addCell(new Label(0, 2, "PILE EI (KN M²)"));
            sheet.addCell(new Label(0, 3, "DIAMETER OF PILE (m)"));
            sheet.addCell(new Label(0, 4, "NUMBER OF INCREMENTAL SOIL DISPLACEMENTS"));
           
            sheet.addCell(new jxl.write.Number(5, 0, data.getNumOfElements()));
            sheet.addCell(new jxl.write.Number(5, 1, data.getPileLength()));
            sheet.addCell(new jxl.write.Number(5, 2, data.getEI()));
            sheet.addCell(new jxl.write.Number(5, 3, data.getPileDiameter()));
            sheet.addCell(new jxl.write.Number(5, 4, data.getNumOfPiles()));

            sheet.addCell(new Label(0, 6, "DEPTH COORDINATES OF PILE NODES (M)"));
            int currentRow = 7;
            int elementCounter =0;
            for(int i=0;i<=(data.getNumOfElements()/5);i++){
                int col=0;
                for(int j=i*5;j<=(i*5)+4;j++){
                  if(elementCounter<=data.getNumOfElements()){
                      sheet.addCell(new jxl.write.Number(col,currentRow,data.getPileNodeCoordinate(j)));
                      col++;
                   }

                   elementCounter++;
             }
                   currentRow++;
            }
            sheet.addCell(new Label(0, currentRow+1, "MODULUS OF SUBGRADE REACTION OF SOIL (KN/M PER M)  AT EACH NODE"));
            currentRow+=2;
            elementCounter =0;
            for(int i=0;i<=(data.getNumOfElements()/5);i++){
                int col=0;
                for(int j=i*5;j<=(i*5)+4;j++){
                  if(elementCounter<=data.getNumOfElements()){
                      sheet.addCell(new jxl.write.Number(col,currentRow,data.getModOfSubgradeReaction(j)));
                      col++;
                   }

                   elementCounter++;
             }
                   currentRow++;
            }
            sheet.addCell(new Label(0, currentRow+1, "LATERAL SOIL MOVEMENTS AT VARIOUS DEPTHS (M)"));
            currentRow+=2;
            elementCounter =0;
            for(int i=0;i<=(data.getNumOfElements()/5);i++){
                int col=0;
                for(int j=i*5;j<=(i*5)+4;j++){
                  if(elementCounter<=data.getNumOfElements()){
                      sheet.addCell(new jxl.write.Number(col,currentRow,data.getLateralSoilMovement(j)));
                      col++;
                   }

                   elementCounter++;
             }
                   currentRow++;
            }

            sheet.addCell(new Label(0, currentRow+1, "LIMIT SOIL PRESSURE (KN/M²)"));
            currentRow+=2;
            elementCounter =0;
            for(int i=0;i<=(data.getNumOfElements()/5);i++){
                int col=0;
                for(int j=i*5;j<=(i*5)+4;j++){
                  if(elementCounter<=data.getNumOfElements()){
                      sheet.addCell(new jxl.write.Number(col,currentRow,data.getLimitSoilPressure(j)));
                      col++;
                   }

                   elementCounter++;
             }
                   currentRow++;
            }
            currentRow++;
            sheet.addCell(new Label(0,currentRow,"INCREMENT NO 1"));
            currentRow++;
            sheet.addCell(new Label(0,currentRow,"NUMBER OF ITERATIONS TO CONVERGE"));
            sheet.addCell(new jxl.write.Number(1, currentRow, result.getNumOfItrForConv()));
            currentRow+=2;
            sheet.addCell(new Label(0,currentRow,"NODE"));
            sheet.addCell(new Label(1,currentRow,"DEPTH (m)"));
            sheet.addCell(new Label(2,currentRow,"SOIL MOVEMENT (mm)"));
            sheet.addCell(new Label(3,currentRow,"SOIL PRESSURE (kPa)"));
            sheet.addCell(new Label(4,currentRow,"ABS LIMIT PRESSURE (kPa)"));
            currentRow++;
            for(int i=0;i<data.getNumOfElements()+1;i++){
                sheet.addCell(new jxl.write.Number(0, currentRow, i+1));
                sheet.addCell(new jxl.write.Number(1, currentRow, data.getPileNodeCoordinate(i)));
                sheet.addCell(new jxl.write.Number(2, currentRow, result.getSoilMovement(i)*1000));
                sheet.addCell(new jxl.write.Number(3, currentRow, result.getSoilPressure(i)));
                sheet.addCell(new jxl.write.Number(4, currentRow, result.getLimitPressure(i)));
                currentRow++;
            }
            currentRow+=2;
            sheet.addCell(new Label(0,currentRow,"NODE"));
            sheet.addCell(new Label(1,currentRow,"DEPTH (m)"));
            sheet.addCell(new Label(2,currentRow,"PILE DISPLACEMENT (mm)"));
            sheet.addCell(new Label(3,currentRow,"ROTATION (rad)"));
            sheet.addCell(new Label(4,currentRow,"BENDM (KNm)"));
            sheet.addCell(new Label(5,currentRow,"SHEAR FORCE (KN)"));
            currentRow++;
            for(int i=0;i<data.getNumOfElements()+1;i++){
                sheet.addCell(new jxl.write.Number(0, currentRow, i+1));
                sheet.addCell(new jxl.write.Number(1, currentRow, data.getPileNodeCoordinate(i)));
                sheet.addCell(new jxl.write.Number(2, currentRow, result.getDisplacement(i)*1000));
                sheet.addCell(new jxl.write.Number(3, currentRow, result.getRotation(i)));
                sheet.addCell(new jxl.write.Number(4, currentRow, result.getBendingMoment(i)));
                sheet.addCell(new jxl.write.Number(5, currentRow, result.getShearForce(i)));
                currentRow++;
            }

           
           
View Full Code Here

TOP

Related Classes of jxl.write.WritableSheet

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.