Jexcel api default font for spreadsheet
Peter Dow <[email protected]> Mon, 10 Jul 2023 17:00:15 -0700
| Newsgroups | gmane.comp.lang.as400.java |
|---|---|
| Message-ID | <[email protected]> |
I'm not a Java programmer, but I'm trying to make a slightly modified
version of Giuseppe Costagliola's SQL2JXL command, by passing it the
name of a font typeface, and the point size of the font, and using that
font as the default for the spreadsheet.
The original version of his SQL2JXL.java does this to create fonts:
WritableFont font = new WritableFont(WritableFont.ARIAL,
WritableFont.DEFAULT_POINT_SIZE);
WritableFont bold = new WritableFont(WritableFont.ARIAL,
WritableFont.DEFAULT_POINT_SIZE,
WritableFont.BOLD);
WritableFont title = new WritableFont(WritableFont.ARIAL, 12,
WritableFont.BOLD);
My new version does the following:
// new parameters
String FONTtype = parameters[21];
String FONTsize = parameters[22];
int iFontSize = Integer.valueOf(FONTsize).intValue();
WritableFont font = new WritableFont(WritableFont.createFont(FONTtype),
iFontSize);
WritableFont bold = new WritableFont(WritableFont.createFont(FONTtype),
iFontSize,
WritableFont.BOLD);
WritableFont title = new WritableFont(WritableFont.createFont(FONTtype),
iFontSize,
WritableFont.BOLD);
But those fonts only seem to apply to individual cells, and only for
certain data types. For example,
// format dates and times
WritableCellFormat dateFormat = new WritableCellFormat
(DateFormats.FORMAT1);
DateFormat tf = new DateFormat("hh:mm:ss");
WritableCellFormat timeFormat = new WritableCellFormat (font, tf);
// when processing a field from the record set, the formats are used
like this:
case Types.DATE:
Date dateValue = rs.getDate (colNum+1);
if (rs.wasNull ()) {
label = new Label(colNum, rowNum, nullValue);
sheet.addCell(label);
} else {
dateTime = new jxl.write.DateTime(colNum, rowNum, dateValue,
dateFormat);
sheet.addCell(dateTime);
}
break;
case Types.TIME:
Time timeValue = rs.getTime (colNum+1);
if (rs.wasNull ()) {
label = new Label(colNum, rowNum, nullValue);
sheet.addCell(label);
} else {
Calendar c = Calendar.getInstance();
c.setTime(timeValue);
c.set(Calendar.YEAR, 1900);
c.set(Calendar.MONTH, 0);
c.set(Calendar.DAY_OF_MONTH, 0);
dateValue = c.getTime();
dateTime = new jxl.write.DateTime(colNum, rowNum, dateValue,
timeFormat);
sheet.addCell(dateTime);
}
break;
Note that the dateFormat does not appear to use the font. Same with
character data - the font is not used.
Some of the stuff I've found out there is iterating through all cells of
the spreadsheet and applying the font just before writing the
spreadsheet to disk.
What I want is a simple default for the entire spreadsheet. Is it possible?
--
*Peter Dow* /
Dow Software Services, Inc.
909 793-9050
[email protected]
[email protected]
/
--
This is the Java Programming on and around the IBM i (JAVA400-L) mailing list
To post a message email: [email protected]
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/java400-l
or email: [email protected]
Before posting, please take a moment to review the archives
at https://archive.midrange.com/java400-l.