Bug 59127 - Ability to replace the default font
Summary: Ability to replace the default font
Status: RESOLVED WORKSFORME
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: unspecified
Hardware: PC Linux
: P2 enhancement (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-03-05 20:33 UTC by David North
Modified: 2016-06-28 17:16 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.