Try setting your column widths after the indPerson loop.

If that fails then please tell us more about the program that takes Excel 
files, it might be good to know what technology was used.

Regards,
Dave

On Nov 24, 2010, at 1:25 PM, Paal Larsen wrote:

> 
> I have two programs (not made by me), one which gives text files as output 
> and one that takes excel files as input. Using POI I take the data I want 
> from the text files and put it in excel files. When I open the excel file in 
> Excel 2007 everything looks ok. However I get an error message when trying to 
> import the made excel file through the other program. It's not an error in 
> the program, manually made files  works fine. (The error message says "Import 
> fail: No data in file." But this text is probably just poorly made exception 
> handling.)
> 
> Also if I open the excel file made with POI, write something random in a 
> random cell, save the file, and then delete the content of that cell and save 
> it again, the program imports the file without problems. 
> 
> I also noticed that although none of the cells are changed at all the file 
> size increases by 57% when I edit and save it like mentioned above. Since I 
> can open the file in excel I'm guessing there is no bugs in my code? But if 
> no bugs I don't understand what the problem is. Is there another way to make 
> the file or save the data in it which fixes this problem? Below is one of the 
> methods that makes an excel file:
> 
> 
> 
> private void makeFile(Persons persons) {
>  int maxTests = HelperClass.maxTests(persons,testName);
>  Workbook wb = new XSSFWorkbook();
>  CreationHelper createHelper = wb.getCreationHelper();
>  Sheet sheet = wb.createSheet();
>  Row row = sheet.createRow(0);
>  //Make the headers     
>  sheet.setColumnWidth(0, 6000);
>  row.createCell(0).setCellValue(
>       createHelper.createRichTextString("Resultat Treisman Formes"));
>  sheet.setColumnWidth(1, 4000);
>  row.createCell(1).setCellValue(
>       createHelper.createRichTextString("Kodenummer"));
>  sheet.setColumnWidth(2, 4000);
>  row.createCell(2).setCellValue(
>       createHelper.createRichTextString("Vakter"));
>  for(int i=0;i<maxTests;i++){
>       sheet.setColumnWidth(3+i*numInfo, 3000);
>   row.createCell(3+numInfo*i).setCellValue(
>        createHelper.createRichTextString("Dato"));
>   sheet.setColumnWidth(4+i*numInfo, 3000);
>   row.createCell(4+numInfo*i).setCellValue(
>        createHelper.createRichTextString("Ant riktig"));
>       sheet.setColumnWidth(5+i*numInfo, 3000);
>   row.createCell(5+numInfo*i).setCellValue(
>        createHelper.createRichTextString("Ant feil"));
>      }
> 
>  Person[] personArray = persons.getPersons();
>  //add tests from all persons     
>  for(int indPerson=0;indPerson<personArray.length;indPerson++){
>   Row tempRow = sheet.createRow(indPerson+1);
> 
>   //first and third column empty
> 
>       //add name
>   tempRow.createCell(1).setCellValue(
>        createHelper.createRichTextString(
>        personArray[indPerson].getName()));
>   Test[] sortedTests = personArray[indPerson].getTests(testName); 
>   //for each test 
>   if(sortedTests!=null) {
>    for(int indTest=0;indTest<sortedTests.length;indTest++){
> 
>         //add date
>         Cell cell = tempRow.createCell(3+numInfo*indTest);
> 
>         cell.setCellValue(
>          createHelper.createRichTextString(
>      sortedTests[indTest].getDate()));
> 
>         //add all values in a test
>         Hashtable<String,String[]> info = sortedTests[indTest].getInfo();
>         String[] values = info.get(HelperClass.resTreismanF);
> 
>      if(values!=null) {
>           for(int i=0;i<values.length;i++){
>            tempRow.createCell(4+numInfo*indTest+i).setCellValue( 
>            Double.parseDouble(values[i]));
>            }
>         }
>    }
>   }
>  }    
>  //Write the output to a file and close the connection.
>  FileOutputStream fileOut = null;
>  try {
>   fileOut = new FileOutputStream(outputName);
>   wb.write(fileOut);
>   fileOut.close();
>  } catch (FileNotFoundException fnfe) {
>   //...deleted
>  }
>  } catch (IOException iie) {
>   //...deleted
>  }
> }                                       


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@poi.apache.org
For additional commands, e-mail: user-h...@poi.apache.org

Reply via email to