本文整理汇总了Java中jxl.format.CellFormat类的典型用法代码示例。如果您正苦于以下问题:Java CellFormat类的具体用法?Java CellFormat怎么用?Java CellFormat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CellFormat类属于jxl.format包,在下文中一共展示了CellFormat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addColumnName
import jxl.format.CellFormat; //导入依赖的package包/类
public void addColumnName(String... columnNames) throws WriteException {
int columnCount = this.sheet.getColumns();
// System.err.println("columnCount:" + columnCount);
for (int i = 0; i < columnNames.length; i++) {
// 通过函数WritableFont()设置字体样式
// 第一个参数表示所选字体
// 第二个参数表示字体大小
// 第三个参数表示粗体样式,有BOLD和NORMAL两种样式
// 第四个参数表示是否斜体,此处true表示为斜体
// 第五个参数表示下划线样式
// 第六个参数表示颜色样式,此处为Red
WritableFont wf = new WritableFont(WritableFont.TIMES, 11, WritableFont.BOLD);
CellFormat cf = new WritableCellFormat(wf);
Label label = new Label(i + columnCount, 0, columnNames[i], cf);
sheet.addCell(label);
}
}
示例2: getFormatIndex
import jxl.format.CellFormat; //导入依赖的package包/类
private short getFormatIndex(final CellFormat cellStyle) {
final Format cellFormat = cellStyle.getFormat();
if(cellFormat == null && cellStyle instanceof XFRecord) {
final XFRecord record = (XFRecord) cellStyle;
return (short) record.formatIndex;
} else if(cellFormat == null) {
return 0;
}
if(cellFormat instanceof DisplayFormat) {
final DisplayFormat displayFormat = (DisplayFormat)cellFormat;
return (short) displayFormat.getFormatIndex();
}
return 0;
}
示例3: hasBorderBottom
import jxl.format.CellFormat; //导入依赖的package包/类
private boolean hasBorderBottom(final Cell cell) {
if(cell == null) {
return false;
}
final CellFormat style = cell.getCellFormat();
if(style == null) {
return false;
}
if(style.getBorder(Border.BOTTOM).equals(Border.NONE)) {
return false;
}
return true;
}
示例4: setCellFormat
import jxl.format.CellFormat; //导入依赖的package包/类
/**
* An API function which sets the format to apply to this cell
*
* @param cf the format to apply to this cell
*/
public void setCellFormat(CellFormat cf)
{
format = (XFRecord) cf;
// If the referenced flag has not been set, this cell has not
// been added to the spreadsheet, so we don't need to perform
// any further logic
if (!referenced)
{
return;
}
// The cell has already been added to the spreadsheet, so the
// formattingRecords reference must be initialized
Assert.verify(formattingRecords != null);
addCellFormat();
}
示例5: getRowCellFormat
import jxl.format.CellFormat; //导入依赖的package包/类
private static WritableCellFormat getRowCellFormat(WritableSheet spreadSheet, int c, int r) {
if (spreadSheet != null) {
Cell cell = spreadSheet.getCell(c, r);
if (cell != null) {
CellFormat cellFormat = cell.getCellFormat();
if (cellFormat != null) {
return new WritableCellFormat(cellFormat);
}
}
}
return null;
}
示例6: writeGoldStandard
import jxl.format.CellFormat; //导入依赖的package包/类
protected void writeGoldStandard(List<Dataset> datasets, Dataset goldStandard) throws Exception {
WorkbookSettings settings = new WorkbookSettings();
settings.setEncoding("iso8859-1");
WorkbookSettings settings2 = new WorkbookSettings();
settings2.setEncoding("utf8");
Workbook w = Workbook.getWorkbook(datasetInfo.getOriginalAnnotationFile(), settings);
WritableWorkbook workbook = Workbook.createWorkbook(datasetInfo.getGoldStandardFile(), w/*, settings2*/);
WritableSheet sheet = workbook.getSheet(0);
CellFormat annotationCell = sheet.getColumnView(10).getFormat();
int itemCount = datasets.get(0).countAnnotations();
for (int itemIdx = 0; itemIdx < itemCount; itemIdx++) {
Integer annot = goldStandard.getAnnotationValue(itemIdx);
int rowIdx = datasets.get(0).getAnnotation(itemIdx).getLine();
CellFormat format = sheet.getWritableCell(10, rowIdx).getCellFormat();
if (format == null)
format = annotationCell;
if (annot != null && annot >= 0)
sheet.addCell(new jxl.write.Number(10, rowIdx, annot,
format));
}
workbook.write();
workbook.close();
w.close();
}
示例7: getFormatPattern
import jxl.format.CellFormat; //导入依赖的package包/类
@Override
public String getFormatPattern() {
// セルのスタイル情報の取得
final CellFormat cellStyle = cell.getCellFormat();
if(cellStyle == null) {
return "";
}
// 変換対象のビルトインフォーマットの場合
final short formatIndex = getFormatIndex(cellStyle);
if(BUILT_IN_FORMATS.containsKey(formatIndex)) {
return BUILT_IN_FORMATS.get(formatIndex);
}
// セルのフォーマットの取得
final Format cellFormat = cellStyle.getFormat();
if(cellFormat == null) {
return "";
}
final String formatPattern = cellFormat.getFormatString();
if(Utils.isEmpty(formatPattern)) {
return "";
}
return formatPattern;
}
示例8: addNumber
import jxl.format.CellFormat; //导入依赖的package包/类
protected void addNumber(WritableSheet sheet, int column, int row,
double value, CellFormat cellFormat) {
try {
jxl.write.Number label = null;
if (cellFormat != null) {
label = new jxl.write.Number(column, row, value, cellFormat);
} else {
label = new jxl.write.Number(column, row, value);
}
sheet.addCell(label);
} catch (Exception ex) {
ex.printStackTrace();
}
}
示例9: addBoolean
import jxl.format.CellFormat; //导入依赖的package包/类
protected void addBoolean(WritableSheet sheet, int column, int row,
boolean value, CellFormat cellFormat) {
try {
jxl.write.Boolean label = null;
if (cellFormat != null) {
label = new jxl.write.Boolean(column, row, value, cellFormat);
} else {
label = new jxl.write.Boolean(column, row, value);
}
sheet.addCell(label);
} catch (Exception ex) {
ex.printStackTrace();
}
}
示例10: addDate
import jxl.format.CellFormat; //导入依赖的package包/类
protected void addDate(WritableSheet sheet, int column, int row,
Date value, CellFormat cellFormat) {
try {
jxl.write.DateTime label = null;
if (cellFormat != null) {
label = new jxl.write.DateTime(column, row, value, cellFormat);
} else {
label = new jxl.write.DateTime(column, row, value);
}
sheet.addCell(label);
} catch (Exception ex) {
ex.printStackTrace();
}
}
示例11: insertCell
import jxl.format.CellFormat; //导入依赖的package包/类
/**
* Write a single cell to the Excel file
*
* @param text
* will be written as text in the cell.
* @param format
* may be null for the default cell format.
*/
private void insertCell(String text, int row, int column, CellFormat format) {
Label label = format == null ? new Label(column, row, text, mDefaultFormat) : new Label(column, row, text, format);
try {
mSheet.addCell(label);
} catch (JXLException e) {
Log.e(TAG, "writeHeader Could not insert cell " + text + " at row=" + row + ", col=" + column, e);
}
}
示例12: insertDurationCell
import jxl.format.CellFormat; //导入依赖的package包/类
private void insertDurationCell(long durationInSeconds, int row, int column, CellFormat cellFormat) {
double durationInDays = (double) durationInSeconds / (24 * 60 * 60);
if (cellFormat == null) cellFormat = durationInSeconds >= 3600 ? mLongDurationFormat : mShortDurationFormat;
Number number = new Number(column, row, durationInDays, cellFormat);
try {
mSheet.addCell(number);
} catch (JXLException e) {
Log.e(TAG, "writeHeader Could not insert cell " + durationInSeconds + " at row=" + row + ", col=" + column, e);
}
}
示例13: createCellFormats
import jxl.format.CellFormat; //导入依赖的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);
}
}
示例14: copyCellFormat
import jxl.format.CellFormat; //导入依赖的package包/类
/**
* Returns an initialized copy of the cell format
*
* @param cf the cell format to copy
* @return a deep copy of the cell format
*/
private WritableCellFormat copyCellFormat(CellFormat cf)
{
try
{
// just do a deep copy of the cell format for now. This will create
// a copy of the format and font also - in the future this may
// need to be sorted out
XFRecord xfr = (XFRecord) cf;
WritableCellFormat f = new WritableCellFormat(xfr);
formatRecords.addStyle(f);
// Maintain the local list of formats
int xfIndex = xfr.getXFIndex();
xfRecords.put(new Integer(xfIndex), f);
int fontIndex = xfr.getFontIndex();
fonts.put(new Integer(fontIndex), new Integer(f.getFontIndex()));
int formatIndex = xfr.getFormatRecord();
formats.put(new Integer(formatIndex), new Integer(f.getFormatRecord()));
return f;
}
catch (NumFormatRecordsException e)
{
logger.warn("Maximum number of format records exceeded. Using " +
"default format.");
return WritableWorkbook.NORMAL_STYLE;
}
}
示例15: CellValue
import jxl.format.CellFormat; //导入依赖的package包/类
/**
* Overloaded constructor used when building writable cells from the
* Java API which also takes a format
*
* @param c the column
* @param t the cell type
* @param r the row
* @param st the format to apply to this cell
*/
protected CellValue(Type t, int c, int r, CellFormat st)
{
super(t);
row = r;
column = c;
format = (XFRecord) st;
referenced = false;
copied = false;
}