You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Peter Busfy <pe...@itera.com.INVALID> on 2022/09/09 12:34:28 UTC

font problem or wrong usage

Hello POI guys,

I started using POI recently. And I ran to one interesting issue with fonts.
I have one dedicated class where I store all styles which I use in my project.
Here in this class, I also hold font. So far, I just need only one font in whole project.
So, I initialized this one font, only once, and stored it as a class variable.
And then I used this font in all style's initializations.
Surprisingly it stared causes quite unpredictable behavior. In some sheets it works with any problems, but in some other issues occurred.
For example, I have a table with several rows. And I wanted to have every second row with a different background color. So, I used a different style for each row. But sometimes it was reflected and sometimes not. And it behaves unpredictable (in some cases it works without any issues, on others not).

What I did to prevent this problem, I initialized for every style his own font, and the problem is gone now. It works smoothly.
Is this known behavior or did I just use font wrongly ?


Peter Bušfy

Digital Service consultant


ITERA

Make a difference
---------------------
itera.com <http://www.itera.com>




Re: font problem or wrong usage

Posted by Nick Burch <ap...@gagravarr.org>.
On Fri, 9 Sep 2022, Peter Busfy wrote:
> This class (StyleCreator) where I hold all styles, are created per 
> workbook. And all styles are in this StyleCreator class initialized only 
> once.

Hmm, that's the most obvious cause excluded

For a workbook where one sheet is happy and one sheet isn't:
* Take a copy of the file
* Open the copy in Excel, fix the first few rows manually, and save
* Unzip both the original and copy
* In the POI generated file, compare the sheet XML for the "works" sheet
   with the "broken" sheet, especially around style attributes
* Then compare the "broken" sheet XML with the "Excel fixed", for the same
   bits

Hopefully one of those will give a hint about what's going wrong

Nick

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


Re: font problem or wrong usage

Posted by Peter Busfy <pe...@itera.com.INVALID>.
This class (StyleCreator) where I hold all styles, are created per workbook. And all styles are in this StyleCreator class initialized only once.


Peter Bušfy

Digital Service consultant


ITERA

Make a difference
---------------------
itera.com <http://www.itera.com>



________________________________
From: Nick Burch <ap...@gagravarr.org>
Sent: Friday, September 9, 2022 2:46 PM
To: Peter Busfy <pe...@itera.com.INVALID>
Cc: user@poi.apache.org <us...@poi.apache.org>
Subject: Re: font problem or wrong usage

On Fri, 9 Sep 2022, Peter Busfy wrote:
> I started using POI recently. And I ran to one interesting issue with
> fonts. I have one dedicated class where I store all styles which I use
> in my project. Here in this class, I also hold font. So far, I just need
> only one font in whole project. So, I initialized this one font, only
> once, and stored it as a class variable. And then I used this font in
> all style's initializations.

Are you caching the styles too? Styles are per-workbook.

> Surprisingly it stared causes quite unpredictable behavior. In some
> sheets it works with any problems, but in some other issues occurred.

If you're creating a fresh style every time, you're probably just running
out of styles and Excel is ignoring all the ones past its max.

Re-use styles across cells and sheets and you won't run out, then Excel
will pay attention to all of them

Nick

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


Re: font problem or wrong usage

Posted by Nick Burch <ap...@gagravarr.org>.
On Fri, 9 Sep 2022, Peter Busfy wrote:
> I started using POI recently. And I ran to one interesting issue with 
> fonts. I have one dedicated class where I store all styles which I use 
> in my project. Here in this class, I also hold font. So far, I just need 
> only one font in whole project. So, I initialized this one font, only 
> once, and stored it as a class variable. And then I used this font in 
> all style's initializations.

Are you caching the styles too? Styles are per-workbook.

> Surprisingly it stared causes quite unpredictable behavior. In some 
> sheets it works with any problems, but in some other issues occurred.

If you're creating a fresh style every time, you're probably just running 
out of styles and Excel is ignoring all the ones past its max.

Re-use styles across cells and sheets and you won't run out, then Excel 
will pay attention to all of them

Nick

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