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);
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?
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact
[javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.