Package jxl

Examples of jxl.Workbook


    public ByteArrayOutputStream createUserActivity(String patternFilePath, List<UserActivity> acitivities) {
        WorkbookSettings wb = new WorkbookSettings();
        wb.setLocale(new Locale("en", "US"));
        ByteArrayOutputStream boas = new ByteArrayOutputStream();
        Workbook wr = null;
        Map<String, UserUser> m = new HashMap<String, UserUser>();
        try {
            wr = Workbook.getWorkbook(new File(patternFilePath), wb);
            WritableWorkbook ww = Workbook.createWorkbook(boas, wr);
            WritableSheet ws = ww.getSheet(0);
View Full Code Here


  @Override
  public ArrayList<MovimentoContabile> leggiFile() throws Exception {

    ArrayList<MovimentoContabile> listaMovimenti= new ArrayList<MovimentoContabile>();

    Workbook workbook = Workbook.getWorkbook(fileToUpload);
    try {
      Sheet sheet = workbook.getSheet(0);

      for (int currentRow = RIGHE_INTESTAZIONE; currentRow < sheet.getRows(); currentRow++) {

        societaVeicolo = sheet.getCell(0, currentRow);
        if (isEmpty(societaVeicolo))
          throw new UnvalidCellException(currentRow+1, 1);
       
        dataRegistrazione = sheet.getCell(1, currentRow);
        if (!(dataRegistrazione instanceof DateCell))
          throw new UnvalidCellException(currentRow+1, 2);
       
        dataCompetenza = sheet.getCell(2, currentRow);
        if (!(dataCompetenza instanceof DateCell))
          throw new UnvalidCellException(currentRow+1, 3);
       
        tipoMovimento = sheet.getCell(3, currentRow);
        if (isEmpty(tipoMovimento))
          throw new UnvalidCellException(currentRow+1, 4);

        causale = sheet.getCell(4, currentRow);
        if (isEmpty(causale))
          throw new UnvalidCellException(currentRow+1, 5);

        progressivoCausale = sheet.getCell(5, currentRow);
        if (!(progressivoCausale instanceof NumberCell))
          throw new UnvalidCellException(currentRow+1, 6);
       
        gruppo = sheet.getCell(6, currentRow);
        if (!(gruppo instanceof NumberCell))
          throw new UnvalidCellException(currentRow+1, 7);
       
        mastro = sheet.getCell(7, currentRow);
        if (!(mastro instanceof NumberCell))
          throw new UnvalidCellException(currentRow+1, 8);
       
        conto = sheet.getCell(8, currentRow);
        if (!(conto instanceof NumberCell))
          throw new UnvalidCellException(currentRow+1, 9);
       
        dare = sheet.getCell(9, currentRow);
        if (!(dare instanceof NumberCell))
          throw new UnvalidCellException(currentRow+1, 10);
       
        avere = sheet.getCell(10, currentRow);
        if (!(avere instanceof NumberCell))
          throw new UnvalidCellException(currentRow+1, 11);
       
        descrizione = sheet.getCell(11, currentRow);
       
        dataValuta = sheet.getCell(12, currentRow);
        if (!isEmpty(dataValuta) && !(dataValuta instanceof DateCell))
          throw new UnvalidCellException(currentRow+1, 13);
       
        finanziamento = sheet.getCell(13, currentRow);
        if (!isEmpty(finanziamento) && !(finanziamento instanceof NumberCell))
          throw new UnvalidCellException(currentRow+1, 14);
       

        if (emptyRow()) {
          return listaMovimenti;
        }

        double value = 0.0;
        MovimentoContabile movimentoCorrente = new MovimentoContabile();
       
        movimentoCorrente.setCodiceSocietaVeicolo(societaVeicolo.getContents());
        movimentoCorrente.setDataRegistrazione(((DateCell) dataRegistrazione).getDate());
        movimentoCorrente.setDataCompetenza(((DateCell) dataCompetenza).getDate());
        movimentoCorrente.setTipoMovimento(tipoMovimento.getContents());
        movimentoCorrente.setCodiceCausale(causale.getContents());
        value = ((NumberCell) progressivoCausale).getValue();
        movimentoCorrente.setProgressivoCausaleOperazione((int) value);
       
        movimentoCorrente.setPianoDeiConti(new PianoDeiConti());
        value = ((NumberCell) gruppo).getValue();
        movimentoCorrente.getPianoDeiConti().setCodiceGruppo((long) value);
        value = ((NumberCell) mastro).getValue();
        movimentoCorrente.getPianoDeiConti().setCodiceMastro((long) value);
        value = ((NumberCell) conto).getValue();
        movimentoCorrente.getPianoDeiConti().setCodiceConto((long) value);

        value = ((NumberCell) dare).getValue();
        movimentoCorrente.setImportoDare((double) value);
        value = ((NumberCell) avere).getValue();
        movimentoCorrente.setImportoAvere((double) value);

        if (!isEmpty(descrizione))
          movimentoCorrente.setDescrizioneMovimento(descrizione.getContents());
       
        if (!isEmpty(dataValuta))
          movimentoCorrente.setDataValuta(((DateCell) dataValuta).getDate());
       
        if (!isEmpty(finanziamento)) {
          value = ((NumberCell) finanziamento).getValue();
          movimentoCorrente.setCodiceFinanziamento((int) value);
        }
       
        listaMovimenti.add(movimentoCorrente);
      }
    } finally {
      workbook.close();
    }

    return listaMovimenti;
  }
View Full Code Here

     
    try
    {
      xlsFilePath = ClassLoader.getSystemResource(xlsFile).getFile();
     
      Workbook workbook = Workbook.getWorkbook(new File( xlsFilePath ) );
     
      Sheet sheet = workbook.getSheet(sheetName);
       
        int startRow, startCol, endRow, endCol, ci, cj;
       
        Cell tableStart = sheet.findCell(tableName);
        startRow = tableStart.getRow();
View Full Code Here

   * @throws Exception : g�n�re une exception au cas o�, l'importation �choue
   */
    public Collection<T> importe(InputStream fluxFichier, String nomDeLaFeuille, IXlsDecodeur<T> decodeur) throws Exception {
       
      Vector<T> objetsImportes = new Vector<T>();
        Workbook classeur = null;
       
        try {
         
            classeur = Workbook.getWorkbook(fluxFichier);
           
            Sheet feuille = classeur.getSheet(nomDeLaFeuille);
           
            final int nombreDeLignes = feuille.getRows();
           
            int[] colonnesALire = decodeur.colonnesALire();
           
            for (int numeroDeLigne = 0; numeroDeLigne < nombreDeLignes; numeroDeLigne ++) {
                Map<Integer,String> ligne = new HashMap<Integer,String>();
               
                for (int numeroDeColonne : colonnesALire) {
                   
                  String valeurDeLaCellule = feuille.getCell(numeroDeColonne,numeroDeLigne).getContents();
                    ligne.put(numeroDeColonne,valeurDeLaCellule);
                }
               
                objetsImportes.add(decodeur.decode(ligne));
            }

        }
        finally {
            if (classeur != null) {
                classeur.close();
            }
        }
        return objetsImportes;
    }
View Full Code Here

    }

    public void parseFile(InputStream inStream) {
        try {
            WorkbookSettings ws = new WorkbookSettings();
            Workbook workbook = Workbook.getWorkbook( inStream, ws);

            if ( _useFirstSheet ) {
                Sheet sheet = workbook.getSheet( 0 );
                processSheet( sheet,
                              _listeners.get( DEFAULT_RULESHEET_NAME ) );
            } else {
                for ( String sheetName : _listeners.keySet() ) {
                    Sheet sheet = workbook.getSheet( sheetName );
                    processSheet( sheet,
                                  _listeners.get( sheetName ) );

                }
            }
View Full Code Here

   */
  public static List readExcelFileSheetsByName(int sheet_count,
      int row_count, int column_count, String excel_file_name) {
    try {

      Workbook book = Workbook.getWorkbook(new File(excel_file_name));
      sl = new ArrayList();
      for (int s = 0; s < sheet_count; s++) {
        Sheet sheet = book.getSheet(s);
        al = new ArrayList();
        Cell cellKey;
        Cell cellValue;
        for (int i = 0; i < column_count; i++) {
          List columndatas = new ArrayList();
          cellKey = sheet.getCell(i, i);
          for (int k = 0; k < row_count; k++) {
            cellValue = sheet.getCell(i, k);
            // System.out.println("��:" + (k + 1) + "�е�" + (i + 1) +
            // "��ֵ��:"+ cellValue.getContents());
            columndatas.add(cellValue.getContents());
          }// end for k
          al.add(columndatas);// ��һ�����ݷ�װ���ܵ�list��
        }// end for i
        book.close();
      }// end if s
      sl.add(al);// ��һ����������Ϣ�ӵ��ܹ�������
    } catch (Exception e) {
      System.out.println(e);
    }
View Full Code Here

   *            excel_file_name
   */
  public static List readExcelFileASheetByName(int row_count,
      int column_count, String excel_file_name) {
    try {
      Workbook book = Workbook.getWorkbook(new File(excel_file_name));
      Sheet sheet = book.getSheet(0);
      al = new ArrayList();
      Cell cellKey;
      Cell cellValue;
      for (int i = 0; i < column_count; i++) {
        List columndatas = new ArrayList();
        cellKey = sheet.getCell(i, i);
        for (int k = 0; k < row_count; k++) {
          cellValue = sheet.getCell(i, k);
          // System.out.println("��:" + (k + 1) + "�е�" + (i + 1) +
          // "��ֵ��:"+ cellValue.getContents());
          columndatas.add(cellValue.getContents());
        }// end for k
        al.add(columndatas);// ��һ�����ݷ�װ���ܵ�list��
      }// end for i
      book.close();
      System.out.println("��ѯEXCEL�ļ�����!");
    } catch (Exception e) {
      System.out.println(e);
    }
    return al;
View Full Code Here

   *            excel_file_name
   * @return list
   */
  public static List readExcelFileASheetByName(String excel_file_name) {
    try {
      Workbook book = Workbook.getWorkbook(new File(excel_file_name));
      Sheet sheet = book.getSheet(0);
      al = new ArrayList();
      Cell cellKey;
      Cell cellValue;
      for (int i = 0; i < column_count; i++) {
        List columndatas = new ArrayList();
        cellKey = sheet.getCell(i, i);
        for (int k = 0; k < row_count; k++) {
          cellValue = sheet.getCell(i, k);
          // System.out.println("��:" + (k + 1) + "�е�" + (i + 1) +
          // "��ֵ��:"+ cellValue.getContents());
          columndatas.add(cellValue.getContents());
        }// end for k
        al.add(columndatas);// ��һ�����ݷ�װ���ܵ�list��
      }// end for i
      book.close();
      System.out.println("��ѯEXCEL�ļ�����!");
    } catch (Exception e) {
      System.out.println(e);
    }
    return al;
View Full Code Here

    response.setContentType(getContentType());
    OutputStream out = response.getOutputStream();

    WritableWorkbook workbook;
    if (this.url != null) {
      Workbook template = getTemplateSource(this.url, request);
      workbook = Workbook.createWorkbook(out, template);
    }
    else {
      logger.debug("Creating Excel Workbook from scratch");
      workbook = Workbook.createWorkbook(out);
View Full Code Here

      }
    };

    excelView.render(new HashMap<String, Object>(), request, response);

    Workbook wb = Workbook.getWorkbook(new ByteArrayInputStream(response.getContentAsByteArray()));
    assertEquals("Test Sheet", wb.getSheet(0).getName());
    Sheet sheet = wb.getSheet("Test Sheet");
    Cell cell = sheet.getCell(2, 4);
    assertEquals("Test Value", cell.getContents());
  }
View Full Code Here

TOP

Related Classes of jxl.Workbook

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.