This project is read-only.

How to change font and font size?

Apr 9, 2009 at 3:58 AM
Dear James you've done a great job with this project, thank you a lot!

I didn't get it done to change font or font size in code (without altering your source-code).
I realized that in default style you set the first found font.
It'd be very useful to include in the blank.xlsx template various different fonts (by the user) and be able to choose between those provided.
E.g. like passing the sequence number of the existing font to the style contructor or something as a simple solution.

Best Regards, Heinrich
Apr 9, 2009 at 6:04 AM
Now I've got it, using SpreadsheetStyle.AddFont(font).
Jan 26, 2010 at 6:43 PM

How do you set a font name?  This is what I'm trying, but LocalName is read-only so I'm stuck.  I don't see any other way (yet).

var wrappedStyle = SpreadsheetStyle.GetDefault(doc);
wrappedStyle.IsWrapped=true;

var monospaceFont = new DocumentFormat.OpenXml.Spreadsheet.Font();
var fontName = new DocumentFormat.OpenXml.Spreadsheet.FontName();
fontName.LocalName = "Consolas";
monospaceFont.FontName = fontName;
wrappedStyle.SetFont(monospaceFont);

 

Thanks!