本文整理汇总了Java中jxl.write.WritableCellFormat.setFont方法的典型用法代码示例。如果您正苦于以下问题:Java WritableCellFormat.setFont方法的具体用法?Java WritableCellFormat.setFont怎么用?Java WritableCellFormat.setFont使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jxl.write.WritableCellFormat
的用法示例。
在下文中一共展示了WritableCellFormat.setFont方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateWriteableCellFormats
import jxl.write.WritableCellFormat; //导入方法依赖的package包/类
protected Map<CellFormat, WritableCellFormat> generateWriteableCellFormats(WritableCellFormat base) {
try {
WritableFont bold = new WritableFont(WritableFont.createFont(base.getFont().getName()),
base.getFont().getPointSize(), WritableFont.BOLD);
Map<CellFormat, WritableCellFormat> result = new HashMap<>();
for (boolean isCentered : new boolean[] { true, false }) {
for (boolean isBold : new boolean[] { true, false }) {
for (boolean hasTopBorder : new boolean[] { true, false }) {
CellFormat f = new CellFormat();
f.isCentered = isCentered;
f.isBold = isBold;
f.hasTopBorder = hasTopBorder;
WritableCellFormat format = new WritableCellFormat(base);
if (isCentered) format.setAlignment(Alignment.CENTRE);
if (isBold) format.setFont(bold);
if (hasTopBorder) format.setBorder(Border.TOP, BorderLineStyle.THIN);
result.put(f, format);
}
}
}
return result;
}
catch (WriteException e) { throw new RuntimeException(e); }
}
示例2: getFormatRed
import jxl.write.WritableCellFormat; //导入方法依赖的package包/类
/**
* @return the formatRed
*/
public WritableCellFormat getFormatRed() throws Exception{
// if(formatRed == null){
formatRed=new WritableCellFormat();
formatRed.setAlignment(jxl.format.Alignment.CENTRE);
formatRed.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
WritableFont wf_color = new WritableFont(WritableFont.ARIAL,10,WritableFont.NO_BOLD,false,UnderlineStyle.NO_UNDERLINE,Colour.RED);
WritableCellFormat wff_color = new WritableCellFormat(wf_color);
formatRed.setBorder(Border.ALL, BorderLineStyle.THIN);
formatRed.setFont(wf_color);
// }
return formatRed;
}
示例3: createCellFormats
import jxl.write.WritableCellFormat; //导入方法依赖的package包/类
/**
* In order to set text to bold, red, or green, we need to create cell
* formats for each style.
*/
private void createCellFormats() {
// Insert a dummy empty cell, so we can obtain its cell. This allows to
// start with a default cell format.
Label cell = new Label(0, 0, " ");
CellFormat cellFormat = cell.getCellFormat();
try {
// Create the bold format
final WritableFont boldFont = new WritableFont(cellFormat.getFont());
mBoldFormat = new WritableCellFormat(cellFormat);
boldFont.setBoldStyle(WritableFont.BOLD);
mBoldFormat.setFont(boldFont);
mBoldFormat.setAlignment(Alignment.CENTRE);
// Center other formats
mDefaultFormat = new WritableCellFormat(cellFormat);
mDefaultFormat.setAlignment(Alignment.CENTRE);
mLongDurationFormat.setAlignment(Alignment.CENTRE);
mShortDurationFormat.setAlignment(Alignment.CENTRE);
mDateFormat.setAlignment(Alignment.CENTRE);
} catch (WriteException e) {
Log.e(TAG, "createCellFormats Could not create cell formats", e);
}
}
示例4: outputDataHeadings
import jxl.write.WritableCellFormat; //导入方法依赖的package包/类
/**
* Outputs the data headings row.
*
* @param workSheet to add the row to
* @param table to fetch metadata from
* @param startRow to add the headings at
* @param helpTextRowNumbers - the map of column names to row index for each
* bit of help text
* @throws WriteException if any of the writes to workSheet failed
* @return the row to carry on inserting at
*/
private int outputDataHeadings(WritableSheet workSheet, Table table, final int startRow, final Map<String, Integer> helpTextRowNumbers) throws WriteException {
int currentRow = startRow;
int columnNumber = 0;
final WritableCellFormat columnHeadingFormat = getBoldFormat();
columnHeadingFormat.setBackground(Colour.VERY_LIGHT_YELLOW);
WritableFont font = new WritableFont(WritableFont.ARIAL, 8, WritableFont.BOLD);
font.setColour(Colour.BLUE);
font.setUnderlineStyle(UnderlineStyle.SINGLE);
columnHeadingFormat.setFont(font);
for (Column column : table.columns()) {
if(columnNumber < MAX_EXCEL_COLUMNS && !column.getName().equals("id") && !column.getName().equals("version")) {
// Data heading is a link back to the help text
WritableHyperlink linkToHelp = new WritableHyperlink(
columnNumber, currentRow,
spreadsheetifyName(column.getName()),
workSheet, 0, helpTextRowNumbers.get(column.getName()));
workSheet.addHyperlink(linkToHelp);
WritableCell label = workSheet.getWritableCell(columnNumber, currentRow);
label.setCellFormat(columnHeadingFormat);
// Update the help text such that it is a link to the heading
Cell helpCell = workSheet.getCell(0, helpTextRowNumbers.get(column.getName()));
WritableHyperlink linkFromHelp = new WritableHyperlink(
0, helpTextRowNumbers.get(column.getName()),
helpCell.getContents(),
workSheet, columnNumber, currentRow);
workSheet.addHyperlink(linkFromHelp);
columnNumber++;
}
}
currentRow++;
return currentRow;
}
示例5: generateExcelReport
import jxl.write.WritableCellFormat; //导入方法依赖的package包/类
public void generateExcelReport()
{
if(this.reports.isEmpty())
{
this.status = "There is no data yet";
this.success = false;
this.exception = "Please run linkcrawler at least once in order to be able to generate a report";
return;
}
try {
String reportDir = System.getProperty("user.dir") + File.separatorChar + "Reports";
Date date = new Date();
DateFormat dateFormat = new SimpleDateFormat("yyyy_MM_dd__HH_mm_ss");
String reportDirFile = reportDir + File.separatorChar + "Report_" + dateFormat.format(date);
reportLocation = reportDirFile;
String reportExcelFile = reportDirFile + File.separatorChar + "ReportExcel.xls";
File reportDirPointer = new File(reportDir);
File reportDirFilePointer = new File(reportDirFile);
//Creating directories if not there
if(!reportDirFilePointer.exists())
{
reportDirPointer.mkdir();
reportDirFilePointer.mkdir();
}
File reportExcelFilePointer = new File(reportExcelFile);
reportExcelFilePointer.createNewFile();
WritableWorkbook workbook = Workbook.createWorkbook(reportExcelFilePointer);
int sheetNumber = 0;
for(UrlReport ur : reports)
{
WritableSheet sheet = workbook.createSheet("Crawled Url " + (sheetNumber + 1), sheetNumber++);
WritableFont blackHeadersFont = new WritableFont(WritableFont.ARIAL, 8, WritableFont.BOLD,false, UnderlineStyle.NO_UNDERLINE, Colour.WHITE);
WritableCellFormat blackHeadersFormatBackground = new WritableCellFormat();
blackHeadersFormatBackground.setBackground(Colour.BLUE) ;
blackHeadersFormatBackground.setBorder(Border.ALL, BorderLineStyle.THIN,Colour.BLACK);
blackHeadersFormatBackground.setFont(blackHeadersFont);
blackHeadersFormatBackground.setAlignment(Alignment.LEFT);
WritableFont whiteValueFont = new WritableFont(WritableFont.ARIAL, 8, WritableFont.BOLD,false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK);
WritableCellFormat whiteValueFormatBackground = new WritableCellFormat();
whiteValueFormatBackground.setBackground(Colour.WHITE);
whiteValueFormatBackground.setBorder(Border.ALL, BorderLineStyle.THIN,Colour.BLACK);
whiteValueFormatBackground.setFont(whiteValueFont);
whiteValueFormatBackground.setAlignment(Alignment.LEFT);
Label introLabel = new Label(0, 0, "Site:", blackHeadersFormatBackground);
Label introLabelValue = new Label(1, 0, ur.getPageUrl()+" ", whiteValueFormatBackground);
sheet.addCell(introLabel);
sheet.addCell(introLabelValue);
int staringRow = 0;
staringRow = prepareLinksDataDetail(sheet, ur, staringRow, LinkTypes.INTERNAL, "Internal links ", blackHeadersFormatBackground, whiteValueFormatBackground);
staringRow = prepareLinksDataDetail(sheet, ur, staringRow, LinkTypes.EXTERNAL, "External links ", blackHeadersFormatBackground, whiteValueFormatBackground);
staringRow = prepareLinksDataDetail(sheet, ur, staringRow, LinkTypes.SPECIAL, "Special links ", blackHeadersFormatBackground, whiteValueFormatBackground);
staringRow = prepareLinksDataDetail(sheet, ur, staringRow, LinkTypes.IMAGES, "Images ", blackHeadersFormatBackground, whiteValueFormatBackground);
for(int x=0; x < sheet.getColumns(); x++)
{
CellView cell=sheet.getColumnView(x);
cell.setAutosize(true);
sheet.setColumnView(x, cell);
}
}
workbook.write();
workbook.close();
this.status = "Excel report generated";
} catch (Exception ex) {
this.status = "Error when generating Excel File";
this.success = false;
this.exception = ex.getMessage();
}
}
示例6: writeFooter
import jxl.write.WritableCellFormat; //导入方法依赖的package包/类
/**
* Write the average and sum formulas at the bottom of the table.
*
* @param rowNumber The row number for the row after the last row of the meetings.
* @param memberNames The names of each team member.
* @param sumMemberDurations The total speaking time per member, in seconds
* @param avgMemberDurations The average speaking time per member, in seconds
* @param totalMeetingDuration The total time of all meetings.
*/
private void writeFooter(int rowNumber, List<String> memberNames, Map<String, Integer> sumMemberDurations, Map<String, Integer> avgMemberDurations,
long totalMeetingDuration) {
try {
// Create formats we need for the bottom rows of the table.
WritableCellFormat boldTopBorderLabel = new WritableCellFormat(mBoldFormat);
boldTopBorderLabel.setBorder(Border.TOP, BorderLineStyle.DOUBLE);
WritableCellFormat boldTopBorderLongDuration = new WritableCellFormat(mLongDurationFormat);
boldTopBorderLongDuration.setFont(new WritableFont(mBoldFormat.getFont()));
boldTopBorderLongDuration.setBorder(Border.TOP, BorderLineStyle.DOUBLE);
WritableCellFormat boldShortDuration = new WritableCellFormat(mShortDurationFormat);
boldShortDuration.setFont(new WritableFont(mBoldFormat.getFont()));
// Insert the average and total titles.
insertCell(mContext.getString(R.string.member_list_header_sum_duration), rowNumber, 0, boldTopBorderLabel);
insertCell(mContext.getString(R.string.member_list_header_avg_duration), rowNumber + 1, 0, mBoldFormat);
int columnCount = memberNames.size() + 2;
// Insert the average and total durations for all members
for (int i = 0; i < memberNames.size(); i++) {
String memberName = memberNames.get(i);
int col = i + 1;
insertDurationCell(sumMemberDurations.get(memberName), rowNumber, col, boldTopBorderLongDuration);
insertDurationCell(avgMemberDurations.get(memberName), rowNumber + 1, col, boldShortDuration);
}
// Insert the average and total durations for the meetings.
insertDurationCell(totalMeetingDuration, rowNumber, columnCount - 1, boldTopBorderLongDuration);
int numMeetings = rowNumber - 1;
long averageMeetingDuration = numMeetings == 0 ? 0 : totalMeetingDuration / numMeetings;
insertDurationCell(averageMeetingDuration, rowNumber + 1, columnCount - 1, boldShortDuration);
// Now that the whole table is filled, auto-size the width of the first and last columns.
CellView columnView = mSheet.getColumnView(0);
columnView.setAutosize(true);
mSheet.setColumnView(0, columnView);
columnView = mSheet.getColumnView(columnCount - 1);
columnView.setAutosize(true);
mSheet.setColumnView(columnCount - 1, columnView);
} catch (JXLException e) {
Log.e(TAG, "Error adding formulas: " + e.getMessage(), e);
}
}
示例7: initNormalStyle
import jxl.write.WritableCellFormat; //导入方法依赖的package包/类
private synchronized void initNormalStyle()
{
normalStyle = new WritableCellFormat(getArial10Pt(),
NumberFormats.DEFAULT);
normalStyle.setFont(getArial10Pt());
}