Bug 59127

Summary: Ability to replace the default font
Product: POI Reporter: David North <dtn-asfbugs>
Component: XSSFAssignee: POI Developers List <dev>
Status: RESOLVED WORKSFORME    
Severity: enhancement    
Priority: P2    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Linux   

Description David North 2016-03-05 20:33:12 UTC
The default font is important because the cell sizes are derived from it.

POI adds a default font because Excel requires there to be one; we used to swap it for our own like this:

workbook,getStylseSource().getFonts().clear()
// create a font as normal, it becomes the default by virtue of being first

Unfortunately that no longer works as Javen (quite reasonably) made the returned list an unmodifiable one in r1721857.

So I propose we add some proper API to replace the default font, e.g. add to StylesTable:

void replaceDefaultFont(XSSFFont font)
Comment 1 Javen O'Neal 2016-03-08 05:45:39 UTC
Would
XSSFFont defaultFont = StylesTable.getFonts().get(0);
// mutate defaultFont as needed
work?

StylesTable.getDefaultFont() would be convenient here, returning a reference to the current default font in the styles table

replaceDefaultFont(XSSFFont font) would be tricky because XSSFFonts have an immutable index (into the font table?). All the mutable fields could be copied from the passed-in font to the default font.
Comment 2 David North 2016-06-28 17:16:39 UTC
Thanks Javen. That approach works for us, so no POI change necessary after all.