I am a beginner with Apache POI library.
in VBA, I know I can select and bold the whole worksheet with following code
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets(1)
ws.Cells.Font.Bold = True
May I know how to select and bold the whole sheet by coding with Apache POI library?
thanks
createRow((int)0); CellStyle style=headRow. getRowStyle(); Font boldFont=hwb. createFont(); boldFont. setBoldweight(Font.
the POI HSSF Font class has two font size settings methods: setFontHeight(short) - Set the font height in unit's of 1/20th of a point. setFontHeightInPoints(short) - Set the font height in point.
To create date cell which display current date to the cell, we can use Apache POI's style feature to format the cell according to the date. The setDateformat() method is used to set date format. Lets see an example in which we are creating a cell containing current date.
There is a pretty good example on this link.
Sheet sheet = wb.createSheet("test");
CellStyle cs = wb.createCellStyle();
Font f = wb.createFont();
f.setBoldweight(Font.BOLDWEIGHT_BOLD);
cs.setFont(f);
sheet.setDefaultColumnStyle(1,cs); //set bold for column 1
The default font for a workbook can be retrieved from index 0. So to modify the font bold setting default for the workbook:
private void setWorkbookDefaultFontToBold(Workbook workbook){
Font defaultFont = workbook.getFontAt(0);
defaultFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
}
It's a really obscure piece of information - it's in the POI Sheet Javadoc for setColumnWidth, in the second or so line:
"...can be displayed in a cell that is formatted with the standard font (first font in the workbook)."
I haven't had to use it heavily, so it may have just happened to work for me (the location and non-prevalence of documentation on it makes me slightly leary of recommending depending on it) but it's somewhere you could start looking
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With