poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Amol Deshmukh <adeshm...@hobsons-us.com>
Subject RE: Regarding HSSF Formatting issues
Date Thu, 03 Mar 2005 15:01:28 GMT
Since I dont have your entire code, here is something that worked for me:
import java.io.FileOutputStream;
import org.apache.poi.hssf.usermodel.*;
public class TestPOI65 {
    public static void main(String[] args) throws Exception {
            FileOutputStream fos = new FileOutputStream(
                args.length > 0 ? args[0] : "c:/temp/killme.xls");
            HSSFWorkbook wb     = new HSSFWorkbook();
            HSSFSheet s      = wb.createSheet("Sheet1");
            HSSFCellStyle style = wb.createCellStyle();
            HSSFFont font = wb.createFont();
            font.setColor(HSSFFont.COLOR_NORMAL);
            font.setItalic(false);
            font.setFontName("Times New Roman");
            style.setFont(font);
            style.setAlignment(HSSFCellStyle.ALIGN_JUSTIFY);
            style.setWrapText(true);        for (int i=0, iSize=1000;
i<iSize; i++) {
                HSSFRow r = s.createRow(i);
                HSSFCell c = r.createCell((short) 0);
                c.setCellValue(new Integer(i).toString());
                c.setCellStyle(style);
                c = r.createCell((short) 1);
                c.setCellValue(new Integer(i*i*i).toString());
                c.setCellStyle(style);
            }
            wb.write(fos);
            fos.close();
            System.out.println("-- done --");
        }
    }


hth,
~ amol

> -----Original Message-----
> From: Suchitra Sundararajan [mailto:Suchitra_S01@infosys.com]
> Sent: Thursday, March 03, 2005 9:44 AM
> To: POI Users List
> Subject: RE: Regarding HSSF Formatting issues
> 
> 
> Hi,
> 
> Thanks a lot for the suggestions. I was earlier (before u guys mailed
> out) creating a new cell style for every row. I changed this to create
> one instance of the cell style and just keep the setCellStyle method
> within the loop but I am still encountering the same problem.
> 
> I have attached the piece of code below. Kindly have a look at it and
> tell me if I am missing out anything.
> 
>  
> 
> HSSFFont font=hsf.createFont();
> 
>                   HSSFCellStyle cellStyle= hsf.createCellStyle();
> 
>                   font.setColor(HSSFFont.COLOR_NORMAL);
> 
>                   font.setItalic(false);
> 
>                   font.setFontName("Times New Roman");
> 
>                   cellStyle.setFont(font);
> 
>                   cellStyle.setAlignment(cellStyle.ALIGN_JUSTIFY);
> 
>                   cellStyle.setWrapText(true);
> 
>  
> 
>                   while(rs.next())
> 
>                   {
> 
>                         int iBatchCount=0;
> 
>  
> 
>                         HSSFRow row = sheet.createRow((short)RowNum);
> 
>  
> 
>                         for(int i=1;i<=rsmd.getColumnCount();i++)
> 
>                         {
> 
>  
> 
>                               HSSFCell cell =
> row.createCell((short)(i-1));
> 
>                               cell.setCellStyle(cellStyle);
> 
>                               cell.setCellValue(rs.getString(i));
> 
>                         }
> 
>                         RowNum++;
> 
>                         iBatchCount++;
> 
>                         System.out.println("Row num is " + RowNum);
> 
>                         if(iBatchCount==1000)
> 
>                         {
> 
>                               hsf.write(fout);
> 
>                               iBatchCount=0;
> 
>  
> 
>                         }
> 
>                   }
> 
>                   hsf.write(fout);
> 
>  
> 
> Thanks and Regards,
> 
> Suchitra.
> 
>  
> 
> -----Original Message-----
> From: Frans.Flippo@INGBank.com [mailto:Frans.Flippo@INGBank.com] 
> Sent: Thursday, March 03, 2005 8:05 PM
> To: poi-user@jakarta.apache.org
> Subject: RE: Regarding HSSF Formatting issues
> 
>  
> 
>  
> 
> Are you creating a new HSSFStyle for each cell or using a 
> single shared
> 
> style for all cells?
> 
>  
> 
> Regards,
> 
> Frans
> 
>  
> 
>  
> 
> > -----Original Message-----
> 
> > From: Suchitra Sundararajan [mailto:Suchitra_S01@infosys.com]
> 
> > Sent: Thursday, March 03, 2005 3:24 PM
> 
> > To: POI Users List
> 
> > Subject: Regarding HSSF Formatting issues
> 
> > 
> 
> > 
> 
> > Hi,
> 
> > 
> 
> > I have used the HSSF class to write the results of my select 
> 
> > query into
> 
> > an excel sheet. I noticed that even if there were just 2 columns and
> 
> > about 1000 rows, there are some formatting issues. My data 
> is supposed
> 
> > to be in TimesNewRoman size 10 but beyond some rows, in this 
> 
> > case around
> 
> > 506 itself the format changes to Arial 10 and it reports Some text
> 
> > formatting might have changed because the maximum number of 
> fonts has
> 
> > been exceeded. I have attached the screen shot of the 
> error. The data
> 
> > seems to be fine but the format has changed
> 
> > Also once this error has been encountered, the next time i run the
> 
> > program without closing the java file (i was running it 
> from Textpad)
> 
> > even if the selected rows are only 10 the same formatting 
> error comes
> 
> > up.
> 
> > Also when the number of rows are very huge, about 10000 or 
> so it gives
> 
> > me a run time exception of out of memory exception. I thought 
> 
> > initially
> 
> > this was because I was writing to the file at the end of 
> all the rows.
> 
> > So I started writing for every row into the sheet but that made the
> 
> > whole process too slow. It was taking several minutes. So I started
> 
> > writing to the excel sheets in batches of 1000 but even 
> that threw an
> 
> > Out of bound exception. Is this a reported bug in the feature? Am I
> 
> > missing out some very important thing here? Is there some 
> clearing of
> 
> > the workbook object that I should do?
> 
> > 
> 
> > Thanks and Regards,
> 
> > Suchitra
> 
> > 
> 
> > 
> 
> > 
> ---------------------------------------------------------------------
> 
> > To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
> 
> > Mailing List:     http://jakarta.apache.org/site/mail2.html#poi
> 
> > The Apache Jakarta Poi Project:  http://jakarta.apache.org/poi/
> 
> > 
> 
>  
> 
>  
> 
> -----------------------------------------------------------------
> 
> ATTENTION:
> 
> The information in this electronic mail message is private and
> 
> confidential, and only intended for the addressee. Should you
> 
> receive this message by mistake, you are hereby notified that
> 
> any disclosure, reproduction, distribution or use of this
> 
> message is strictly prohibited. Please inform the sender by
> 
> reply transmission and delete the message without copying or
> 
> opening it.
> 
>  
> 
> Messages and attachments are scanned for all viruses known.
> 
> If this message contains password-protected attachments, the
> 
> files have NOT been scanned for viruses by the ING mail domain.
> 
> Always scan attachments before opening them.
> 
> -----------------------------------------------------------------
> 
>  
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
Mailing List:     http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta Poi Project:  http://jakarta.apache.org/poi/


Mime
View raw message