Yes, from my investigations I think you are correct. If you create a Font object, assign that font to a cell, modify the same Font object, then assign that font to a second cell, the first cell's font will also change.
That is why I was creating a new Font object for each cell ( by calling workbook.createFont() ). Unfortunately there seems to be a limit to the number of different fonts an Excel spreadsheet can contain. So I then had to prebuild a set of all the possible font, colour and style combinations. This is an inelegant solution that is costly to maintain and error prone. So I am looking for a neater solution :-) Anthony Andrews <[EMAIL PROTECTED]> wrote on 21/11/2005 19:27:44: > I could very well be wrong but I believe that the problem you are > encountering is caused by the fact that you are assigning a > different value to a variable before saving the workbook away to file. > > By this, I mean that you are declaring an HSSFFont object, > initialising it, applying that font object to a cell and then re- > initialising the same font object. I think that it is the re- > initialisation of that font object that is causing you problems. > > The answer is, I think, to do exactly as you suggest in your e- > mail, to declare HSSFFont objects for each combination of font you require. > > [EMAIL PROTECTED] wrote: I am running into some > annoyances with the way fonts are handled. This may > be because of the way Excel works, or because of the way POI is designed, > or because I am doing the wrong thing. > > I am writing a report to track employee leave. The spec is simple: > > - unapproved leave should appear in italics. Approved leave is in normal > font. > - leave without pay should appear in green. Other leave is in black. > > So for example unapproved leave without pay would be both in italics and > green. > > In my first attempt, I created a new font for every cell, and set the > values accordingly. However, Excel seems to have a limit on the number of > fonts in a spreadsheet. I get this message when I open the spreadsheet > > "Some formatting may have changed in this file because the number of fonts > was exceeded". > > To use only the number of fonts I need, I've had to create a seperate font > for every possible combination of leave types and status. > > i.e. > > HSSFFont approvedNormalLeave; > HSSFFont unapprovedNormalLeave; > HSSFFont approvedLeaveWithoutPay; > HSSFFont unapprovedLeaveWithoutPay; > > This seems to work OK. It's very nasty though, with a nice big > if-then-else statement to work out which of the four fonts I need. > It also won't scale. If they later decide that, for example, all leave on > mondays or fridays needs to be in bold, I will then have to double the > number of fonts again! > > i.e > > HSSFFont approvedNormalLeave; > HSSFFont unapprovedNormalLeave; > HSSFFont approvedLeaveWithoutPay; > HSSFFont unapprovedLeaveWithoutPay; > HSSFFont mondayApprovedNormalLeave; > HSSFFont mondayUnapprovedNormalLeave; > HSSFFont mondayApprovedLeaveWithoutPay; > HSSFFont mondayUnapprovedLeaveWithoutPay; > > So my question is, is there a way to create and use fonts "on the fly" on > a per cell basis? Or am I forced to pre-create a global list of all the > possible fonts I might need? > > Thanks for any replies. > > Andreas. > > _____________________________________________________________________ > This email message (including any file attachments transmitted with > it) is for the sole use of the individual or entity to whom it is > addressed and may contain confidential and privileged information. > Any unauthorised review, use, alteration, disclosure or > distribution is prohibited. If you have received this email in > error, please notify the sender by return email and destroy all > copies of the original message. > Any confidentiality or legal professional privilege is not waived or > lost by any mistaken delivery of the email. > Opinions, conclusions and other information in this message that do > not relate to the official business of the company shall be > understood as neither given nor endorsed by it. > > > > --------------------------------- > Yahoo! FareChase - Search multiple travel sites in one click. _____________________________________________________________________ This email message (including any file attachments transmitted with it) is for the sole use of the individual or entity to whom it is addressed and may contain confidential and privileged information. Any unauthorised review, use, alteration, disclosure or distribution is prohibited. If you have received this email in error, please notify the sender by return email and destroy all copies of the original message. Any confidentiality or legal professional privilege is not waived or lost by any mistaken delivery of the email. Opinions, conclusions and other information in this message that do not relate to the official business of the company shall be understood as neither given nor endorsed by it.
