poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lili2 <laetitia.laco...@gmail.com>
Subject Re: Empty column Problem in excel file
Date Fri, 21 Mar 2008 09:01:24 GMT

I found a solution to my problem. In case somebody has the same someday here
is what you can do:
(it was difficult because with a null cell you can't do anything so the
solution i found is to create a new cell instead when i found the null cell)
 int colToDelete = 0;
for(short i=0;i<=r.getLastCellNum();i++)
{
      HSSFCell c = r.getCell(i);
      if(c==null)
      {
           colToDelete = i;
      }
}
if(colToDelete!=0)
{
      for(short i=(short)colToDelete;i<r.getLastCellNum();i++)
      {
           HSSFCell c2 = r.createCell( (short) i);
           c2.setCellValue(r.getCell( (short) (i +
1)).getStringCellValue());
           c2.setCellStyle(headerStyle);
      }
      r.removeCell(r.getCell( (short)r.getLastCellNum()));
      for(short k=1;k<=sheetData.getLastRowNum();k++)
      {
            HSSFRow r2 = sheetData.getRow((short)k);
            for(short i=(short)colToDelete;i<r2.getLastCellNum();i++)
            {
                  HSSFCell c2 = r2.createCell( (short) i);
                  c2.setCellValue(r2.getCell( (short) (i +
1)).getStringCellValue());
                  c2.setCellStyle(bodyStyle);
            }
             r2.removeCell(r2.getCell( (short)r2.getLastCellNum()));
      }
      sheetData.autoSizeColumn((short)colToDelete);
}
Thank you for trying.


lili2 wrote:
> 
> I go further in my problem:
> I don't know why but there is always a cell null (the fourth beginning by
> the end)
> So I can't read it, and the worse I can't even delete it!!!
> Do you have an idea on the solution to my problem: how could I erase a
> cell that exists but that is null!
> Thank you
> 
> Nick Burch wrote:
>> 
>> On Wed, 19 Mar 2008, lili2 wrote:
>>> I create an excel file with POI et my data are well displayed (first 
>>> line: headers and the other lines are the body). I have an issue 
>>> concerning the fourth column - counting beginning at the end - is always 
>>> empty. For example, when I have 6 columns: the third is empty, when I 
>>> have 10 columns: the seventh is empty.
>> 
>> This does seem rather odd. Any chance you could write a small unit test 
>> that shows up the problem, then upload this to bugzilla? That way, we'll 
>> be able to take a look
>> 
>>> In the case nobody knows this problem could you please help to delete 
>>> this column? Does a function "remove the column where the first cell is 
>>> empty" exists?
>> 
>> There's nothing quite like that. You'd need to code it up yourself - test 
>> the first row, then loop over the rest or the rows zapping columns
>> 
>> Nick
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
>> For additional commands, e-mail: dev-help@poi.apache.org
>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Empty-column-Problem-in-excel-file-tp16143651p16194943.html
Sent from the POI - Dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Mime
View raw message