问题
How can i import a new font to POI API with extensions ttf & otf , without install these fonts into the environment ?
Is there a jar that i should update it with the path of the new font ?
回答1:
Normally
You cannot add fonts... You can think your (office) files just like HTML. Font lives outside the document. You just set the font name, family, etc.
Update:
However, someone has already tried to do that. Using embedded files, you could add font files.
Link:
http://apache-poi.1045710.n5.nabble.com/Font-embedding-into-XSLF-td5713937.html
It is far from easy. There's no easy way to insert embedded files.
- Embed files into Excel using Apache POI
- Embedding HSSF(excel) into HSLF(ppt) using apache poi
回答2:
In the meantime I've implemented an API to embed the fonts easily. This version goes live with POI 4.1.0.
POI can't consume .ttf/.otf directly, but needs some help from googles sfntly. My demo project can be found under github/poi-font-mbender.
I won't provide a copy & paste of the sample class as you also need the rest of the sfntly library, which is not available as maven artifact.
来源:https://stackoverflow.com/questions/22453259/poi-importing-new-fonts-to-the-poi