You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by mouss4rs <ou...@gmail.com> on 2012/03/01 10:41:40 UTC
Unexpected missing row when some rows already present
Hi every body,
When i run my program, I found this error:
Exception in thread "main" java.lang.RuntimeException: Unexpected missing
row when some rows already present
at
org.apache.poi.hssf.usermodel.HSSFSheet.setPropertiesFromSheet(HSSFSheet.java:174)
at org.apache.poi.hssf.usermodel.HSSFSheet.<init>(HSSFSheet.java:121)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:275)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:188)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:305)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:286)
at Extraction.main(Extraction.java:92)
The line impacted is in bold:
InputStream ist = new
FileInputStream("C:/Donnees/Aide_Manager/date_extract1.xls");
*HSSFWorkbook wbd = new HSSFWorkbook(ist);* HSSFSheet sheetd =
wbd.getSheetAt(0);
HSSFRow rowd = null;
HSSFCell celld = null;
Is it a bug ????
--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Unexpected-missing-row-when-some-rows-already-present-tp5527417p5527417.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: Unexpected missing row when some rows already present
Posted by mouss4rs <ou...@gmail.com>.
Thanks.
It's resolved with this:
//###################### ON RECUPERE TOUTES LES DATES DU FICHIER DE
SAUVEGARDE DES DATES D'EXTRACT
#################################################################
InputStream is1 = new
FileInputStream("C:/Donnees/Aide_Manager/dateTrouvee.xls");
//ce fichier permettra de récupérer les dates pour savoir si un extract à
déjà été utilisé.
HSSFWorkbook wb1 = new HSSFWorkbook(is1);
HSSFSheet sheet1 = wb1.getSheetAt(0);
HSSFRow row1 = null;
HSSFCell cell1 = null;
System.out.println("ON RECUPERE TOUTES LES DATES DU FICHIERS");
for (Iterator ro = sheet1.rowIterator(); ro.hasNext();){
row1 = (HSSFRow) ro.next();//pour chaque ligne du fichier
cell1 = row1.getCell(0);// à la colonne 0
//si on trouve une chaine
if(cell1.getCellType()==1){
RecupDate[i]=cell1.getStringCellValue();
System.out.println("Date: "+i+" "+RecupDate[i]);
}
i++;
}
dernLigneTrouvee=i;
System.out.println("dernLigneTrouvee: "+dernLigneTrouvee);
//####################### ON RECUPERE LA DATE DE L'EXTRACT
################################################################
//faire une vérification pour savoir:
//si la date du fichier n'est pas trouvée sur
InputStream is2 = new
FileInputStream("C:/Donnees/Aide_Manager/extract_25012012.xls");
//ce fichier permettra de récupérer les dates pour savoir si un extract à
déjà été utilisé.
HSSFWorkbook wb2 = new HSSFWorkbook(is2);
HSSFSheet sheet2 = wb2.getSheetAt(0);
HSSFRow row2 = null;
HSSFCell cell2 = null;
int j=0;
for (Iterator r = sheet2.rowIterator(); r.hasNext();){
row2 = (HSSFRow) r.next();
cell2 = row2.getCell(0);
if(row2.getRowNum() == 6){
dateTrouvee = row2.getCell(0).getStringCellValue().substring(3,13);//on
récupère la date
System.out.println("on récupère la date de l'extract: "+dateTrouvee);
}
}
//####################### COMPARAISON DES DATES
################################################################
for(int m=0; m<RecupDate.length;m++){
if(RecupDate[m]!=null){
if(dateTrouvee.equals(RecupDate[m])){
System.out.println("dateTrouvee: "+dateTrouvee);
System.out.println("RecupDate[i]: "+RecupDate[m]);
System.out.println("DATE TROUVEE: ON ECRIT PAS DANS LE FICHIER.");
date_stockee_trouvee=true;//true pour dire que la date est trouvée
}
}
}
//####################### On écrit
################################################################
InputStream is3 = new
FileInputStream("C:/Donnees/Aide_Manager/dateTrouvee.xls");
HSSFWorkbook wb3 = new HSSFWorkbook(is3);
HSSFSheet sheet3 = wb3.getSheetAt(0);
if(date_stockee_trouvee==false){//false pour dire que la date n'est pas
trouvée
HSSFRow row3 = sheet3.createRow(dernLigneTrouvee);
HSSFCell cell3 = row3.createCell(0);
System.out.println("---------------On ecrit la date si on la trouve
pas-------------------");
cell3 = row3.createCell(0);//on fixe la colonne
cell3.setCellValue(dateTrouvee);
System.out.println("La nouvelle date_extract '"+dateTrouvee+"' a été
stocké dans le fichier.");
//pour ecrire dans le même fichier
FileOutputStream fileOutd = new
FileOutputStream("C:/Donnees/Aide_Manager/dateTrouvee.xls");
wb3.write(fileOutd);
fileOutd.close();
}
--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Unexpected-missing-row-when-some-rows-already-present-tp5527417p5546608.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: Unexpected missing row when some rows already present
Posted by Mark Beardsley <ma...@tiscali.co.uk>.
POI will only return a row to you if it contains data in the source workbook.
If the row is empty then POI will not return it to you via the Iterator
mechanism. Is this what you are seeing or are you saying the POI is failing
to return to you a reference for a row which is populated with data?
--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Unexpected-missing-row-when-some-rows-already-present-tp5527417p5544757.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: Unexpected missing row when some rows already present
Posted by mouss4rs <ou...@gmail.com>.
Yes, it's poi-3.8 beta 5.
I always have this error:
Unexpected missing row when some rows already present.
for this line (*in bold*)
try {
is = new FileInputStream(fichierExtract);
//POIFSFileSystem fs = new POIFSFileSystem(new
FileInputStream("extract.xls")); //pour ouvrir les fichiers xls
*wb = new HSSFWorkbook(is);* sheet = wb.getSheetAt(0);
row = null;
cell = null;
int n = 0;
//int i = 0;//compte le nombre d'agent
for (Iterator rowIt = sheet.rowIterator(); rowIt.hasNext();){
row = (HSSFRow) rowIt.next();
Agent a = new Agent();
n++;// pour avoir le numéro de chaque ligne lue
if(row.getRowNum() == 6 && row.getCell(0) != null){//pour obtenir la
date de l'extract et déterminer sa semaine dans l'année.
date_extract = row.getCell(0).getStringCellValue().substring(3,13);//on
récupère la date
System.out.println("date_extract: "+date_extract);
//faire une vérification pour savoir:
//si la date du fichier n'est pas trouvée sur
istr = new
FileInputStream("C:/Donnees/Aide_Manager/date_extract1.xls");
//ce fichier permettra de récupérer les dates pour savoir si un extract
à déjà été utilisé.
wbd = new HSSFWorkbook(istr);
sheetd = wbd.getSheetAt(0);
rowd = null;
celld = null;
date_extract="24/01/2012";
boolean date_stockee_trouvee = false;
int dernLigneTrouvee = 0;
for (Iterator r = sheetd.rowIterator(); r.hasNext();){
rowd = (HSSFRow) r.next();
celld = rowd.getCell(0);
//System.out.println("lalalalalala");
if(celld != null ){
if(celld.getCellType()==0){
System.out.println("c'est un nombre: "+celld.getNumericCellValue());
}else{
System.out.println("c'est une chaine: "+celld.getStringCellValue());
if(celld.getStringCellValue().equals(date_extract)){// si on trouve
que la date_extract est = à la date trouvée dans le fichier
System.out.println("DATE TROUVEE Ds le fichier !");
System.out.println("CETTE EXTRACT A DEJA ETE UTILISEE !!");
System.out.println("MERCI D'UTILISER UN AUTRE EXTRACT CONCERNANT
UNE AUTRE DATE !");
date_stockee_trouvee=true;
}
}
dernLigneTrouvee = rowd.getCell(0).getRowIndex();
}
}
--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Unexpected-missing-row-when-some-rows-already-present-tp5527417p5543626.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: Unexpected missing row when some rows already present
Posted by Yegor Kozlov <ye...@dinom.ru>.
What version of POI are you using? Try the latest POI-3.8-beta5.
Yegor
On Thu, Mar 1, 2012 at 1:41 PM, mouss4rs <ou...@gmail.com> wrote:
> Hi every body,
>
> When i run my program, I found this error:
> Exception in thread "main" java.lang.RuntimeException: Unexpected missing
> row when some rows already present
> at
> org.apache.poi.hssf.usermodel.HSSFSheet.setPropertiesFromSheet(HSSFSheet.java:174)
> at org.apache.poi.hssf.usermodel.HSSFSheet.<init>(HSSFSheet.java:121)
> at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:275)
> at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:188)
> at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:305)
> at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:286)
> at Extraction.main(Extraction.java:92)
>
> The line impacted is in bold:
> InputStream ist = new
> FileInputStream("C:/Donnees/Aide_Manager/date_extract1.xls");
> *HSSFWorkbook wbd = new HSSFWorkbook(ist);* HSSFSheet sheetd =
> wbd.getSheetAt(0);
> HSSFRow rowd = null;
> HSSFCell celld = null;
>
> Is it a bug ????
>
> --
> View this message in context: http://apache-poi.1045710.n5.nabble.com/Unexpected-missing-row-when-some-rows-already-present-tp5527417p5527417.html
> Sent from the POI - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org