Visualizzazione dei risultati da 1 a 6 su 6
  1. #1

    lettura dati da file xsl in java

    Ciao a tutti sto facendo un programma in java che "dovrebbe" preso in input un valore corrispondente al nome della colonna di un file excel restituirmi tutti i valori per quella colonna
    per esempio: se immetto "nome" lui mi restituirà tutti i valori sotto ,la colonna nome nel file excel! capito?? spero di essere stata chiara...il fattyo è che mi sono fermata ad un punto piuttosto imbarazzante perchè a me sinceranmente non sembra che ci possano essere troppo problemi con il codice che ho scritto .. invece non entra nell'if(in cui ora ho messo solo una stampa...ma non fa neppure quella) ... ho pensato che la condizione dell'if può non essere giusta perchè magari la lettura del valore dalla cella del file non restituisce una stringa ... non so a me sembra banale ma non funziona ...helppppppp

    il codice è grossomodo questo:

    codice:
    import jxl.*;
    import java.io.*;
    import java.util.Scanner;
    
    public class Main {
      public static void main (String[] args) throws Exception {
        //apro il file
        String dato = "";
        Workbook workbook = Workbook.getWorkbook(new File("C:/Documents and Settings/Administrator/Desktop/TEST.xls"));
        //prendo il primo foglio
        Sheet sheet = workbook.getSheet(0);
        String query_nome_colonna = "";
        String query_campo = "";
        Scanner input = new Scanner(System.in);   
        System.out.println("Di quale dato desideri avere l'informazione??? ");
        dato = input.next();
        System.out.println("Hai inserito: "+dato);
        boolean flag2 = true;
        int riga = 1;
        int colonna = 1;
        int valore_colonna = 1;
        Cell currentCell;
        NumberCell cell2 = null;
        int max_num_column  = 27;//incrementa le colonne
        int min_num_row = 11;
        while (sheet.getCell(colonna, riga).getRow() < min_num_row) { 
           String nome_colonna = sheet.getCell(valore_colonna,0).getContents();
           System.out.println("valore nome colonna"+nome_colonna);
           System.out.println("dato"+dato);
               if(dato.equals(nome_colonna)){
                   System.out.println("ENTRO NELL'IF");
               }//end if
          valore_colonna++;// incremento il valore dei nomi delle colonne
        }
      }
    
    }

    p.s. la cosa strana è che quando stampo i valori di datio e nome colonna questi siono esattamente gli stessi!O.O

  2. #2
    Moderatore di Programmazione L'avatar di LeleFT
    Registrato dal
    Jun 2003
    Messaggi
    17,320

    Moderazione

    Java ha un forum dedicato.

    PS: Prendi visione del Regolamento interno. Ci sono diverse norme da seguire quando si apre una discussione e quando si posta del codice.

    Sistemo io e sposto la discussione nel forum corretto.


    Ciao.
    "Perchè spendere anche solo 5 dollari per un S.O., quando posso averne uno gratis e spendere quei 5 dollari per 5 bottiglie di birra?" [Jon "maddog" Hall]
    Fatti non foste a viver come bruti, ma per seguir virtute e canoscenza

  3. #3
    grazie mille non avevo idea!!!!!!!!

  4. #4
    ok risolto il problema era che la stringa della cella excel conteneva uno spazio...ora però ho un'altro problema..non c'è un modo di prelevare la stringa dal file excel senza spazi?

  5. #5
    metodo trim() di String.

    Dalla documentazione:

    public String trim()
    Returns a copy of the string, with leading and trailing whitespace omitted.
    If this String object represents an empty character sequence, or the first and last characters of character sequence represented by this String object both have codes greater than '\u0020' (the space character), then a reference to this String object is returned.

    Otherwise, if there is no character with a code greater than '\u0020' in the string, then a new String object representing an empty string is created and returned.

    Otherwise, let k be the index of the first character in the string whose code is greater than '\u0020', and let m be the index of the last character in the string whose code is greater than '\u0020'. A new String object is created, representing the substring of this string that begins with the character at index k and ends with the character at index m-that is, the result of this.substring(k, m+1).

    This method may be used to trim whitespace (as defined above) from the beginning and end of a string.

    Returns:
    A copy of this string with leading and trailing white space removed, or this string if it has no leading or trailing white space.

    Se non sei molto anglofono, significa che restituisce la stringa privata di tutti gli spazi in testa e in coda.
    Ciao.

  6. #6
    GRAZIE MILLEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE PROPRIO QUELLO CHE CERCAVO ORA VEDIAMO SE RIESCO A FARLO FUNZIONARE

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.