本文整理汇总了Java中org.apache.poi.hssf.usermodel.HSSFWorkbook.createCellStyle方法的典型用法代码示例。如果您正苦于以下问题:Java HSSFWorkbook.createCellStyle方法的具体用法?Java HSSFWorkbook.createCellStyle怎么用?Java HSSFWorkbook.createCellStyle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.hssf.usermodel.HSSFWorkbook
的用法示例。
在下文中一共展示了HSSFWorkbook.createCellStyle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCellStyle
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //导入方法依赖的package包/类
/**
* 获取单元格式样式
*
* @param wb
* @param color
* @return
*/
private static HSSFCellStyle getCellStyle(HSSFWorkbook wb, int color) {
if (STYLE_MAP.get(color) != null) {
return STYLE_MAP.get(color);
}
HSSFCellStyle style = wb.createCellStyle();
if (color != -1) {
style.setFillForegroundColor(Short.valueOf(color + ""));
style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
style.setAlignment(CellStyle.ALIGN_CENTER);
}
style.setBorderBottom(CellStyle.BORDER_THIN);
style.setBorderLeft(CellStyle.BORDER_THIN);
style.setBorderRight(CellStyle.BORDER_THIN);
style.setBorderTop(CellStyle.BORDER_THIN);
style.setBottomBorderColor(HSSFColor.BLACK.index);
style.setLeftBorderColor(HSSFColor.BLACK.index);
style.setRightBorderColor(HSSFColor.BLACK.index);
style.setTopBorderColor(HSSFColor.BLACK.index);
STYLE_MAP.put(color, style);
return style;
}
示例2: writeCell
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //导入方法依赖的package包/类
/**
* Write the value to the cell. Override this method if you have complex data types that may need to be exported.
* @param value the value of the cell
* @param cell the cell to write it to
*/
protected void writeCell(Object value, HSSFCell cell, HSSFWorkbook wb)
{
if (value instanceof Number)
{
Number num = (Number) value;
cell.setCellValue(num.doubleValue());
}
else if (value instanceof Date)
{
HSSFCellStyle cellStyle = wb.createCellStyle();
cellStyle.setDataFormat(
wb.getCreationHelper().createDataFormat().getFormat("dd/MM/yyyy HH:mm"));
cell.setCellStyle(cellStyle);
cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
cell.setCellValue((Date) value);
}
else if (value instanceof Calendar)
{
cell.setCellValue((Calendar) value);
}
else
{
cell.setCellValue(new HSSFRichTextString(escapeColumnValue(value)));
}
}
示例3: beforeClass
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //导入方法依赖的package包/类
@BeforeClass
public static void beforeClass() {
workbook = new HSSFWorkbook();
sheet = workbook.createSheet("Default");
Row row = sheet.createRow(ypos++);
CellStyle style = workbook.createCellStyle();
style.setWrapText(true);
setCell(style, row, 1, "Bytes\nSize");
setCell(style, row, 2, "Serialization\nRaw");
setCell(style, row, 3, "Externalizor\nRaw");
setCell(style, row, 4, "Serialization\nCompressed");
setCell(style, row, 5, "Externalizor\nCompressed");
setCell(style, row, 7, "Rate\nrw / sec");
setCell(style, row, 8, "Serialization\nRaw");
setCell(style, row, 9, "Externalizor\nRaw");
setCell(style, row, 10, "Serialization\nCompressed");
setCell(style, row, 11, "Externalizor\nCompressed");
}
示例4: createHeader
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //导入方法依赖的package包/类
public static boolean createHeader(HSSFWorkbook workbook, HSSFSheet sheet,String[] header) throws Exception{
boolean flag = false;
try {
HSSFCellStyle cellStyle = workbook.createCellStyle();
cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
HSSFRow head_row = sheet.createRow(0); // 创建行
// 操作head
for (short h = 0; h < header.length; h++) {
createcsv(head_row, h, header[h], cellStyle);
}
flag = true;
} catch (Exception e) {
logger.error(sheet.getSheetName() + " : 抬头标题创建失败");
throw e;
}
return flag;
}
示例5: createCellStyleForColumnHeading
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //导入方法依赖的package包/类
public static HSSFCellStyle createCellStyleForColumnHeading(HSSFWorkbook workBook) {
HSSFCellStyle cellStyle = workBook.createCellStyle();
HSSFFont fontObj = workBook.createFont();
cellStyle.setBorderBottom(BorderStyle.THIN);
cellStyle.setBorderTop(BorderStyle.THIN);
cellStyle.setBorderLeft(BorderStyle.THIN);
cellStyle.setBorderRight(BorderStyle.THIN);
cellStyle.setWrapText(true);
cellStyle.setAlignment(HorizontalAlignment.CENTER);
cellStyle.setFillBackgroundColor(Short.valueOf("22").shortValue());
cellStyle.setFillPattern(FillPatternType.BIG_SPOTS);
cellStyle.setFillForegroundColor(Short.valueOf("22").shortValue());
cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
fontObj.setFontName("Calibri");
fontObj.setFontHeightInPoints(Short.valueOf("12").shortValue());
fontObj.setBold(true);
fontObj.setColor(Short.valueOf("8").shortValue());
cellStyle.setFont(fontObj);
return cellStyle;
}
示例6: buildExcelDocument
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //导入方法依赖的package包/类
@Override
protected void buildExcelDocument(Map<String, Object> model,
HSSFWorkbook workbook, HttpServletRequest request, HttpServletResponse response)
throws Exception {
// get data model which is passed by the Spring container
List<RatingCountBean> listOfRating = (List<RatingCountBean>) model.get("listOfRatingCount");
// create a new Excel sheet
HSSFSheet sheet = workbook.createSheet("Feedback Report");
sheet.setDefaultColumnWidth(30);
// create style for header cells
CellStyle style = workbook.createCellStyle();
Font font = workbook.createFont();
font.setFontName("Arial");
style.setFillForegroundColor(HSSFColor.BLUE.index);
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
font.setColor(HSSFColor.WHITE.index);
style.setFont(font);
// create header row
HSSFRow header = sheet.createRow(0);
header.createCell(0).setCellValue("Question Number");
header.getCell(0).setCellStyle(style);
header.createCell(1).setCellValue("Question");
header.getCell(1).setCellStyle(style);
header.createCell(2).setCellValue("Very Poor");
header.getCell(2).setCellStyle(style);
header.createCell(3).setCellValue("Poor");
header.getCell(3).setCellStyle(style);
header.createCell(4).setCellValue("Good");
header.getCell(4).setCellStyle(style);
header.createCell(5).setCellValue("Best");
header.getCell(5).setCellStyle(style);
header.createCell(6).setCellValue("Excellent");
header.getCell(6).setCellStyle(style);
// create data rows
int rowCount = 1;
for (RatingCountBean rating : listOfRating) {
HSSFRow aRow = sheet.createRow(rowCount++);
aRow.createCell(0).setCellValue(rating.getQuestionId());
aRow.createCell(1).setCellValue(rating.getQuestionText());
aRow.createCell(2).setCellValue(rating.getRating_one_total_count());
aRow.createCell(3).setCellValue(rating.getRating_two_total_count());
aRow.createCell(4).setCellValue(rating.getRating_three_total_count());
aRow.createCell(5).setCellValue(rating.getRating_four_total_count());
aRow.createCell(6).setCellValue(rating.getRating_five_total_count());
}
}
示例7: test_001
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //导入方法依赖的package包/类
@Test
public void test_001()
{
HSSFWorkbook v_Workbook = new HSSFWorkbook();
HSSFSheet v_Sheet = v_Workbook.createSheet("测试单元格颜色");
v_Sheet.setColumnWidth(0 ,2560);
for (int v_RowIndex=0; v_RowIndex<4000; v_RowIndex++)
{
HSSFRow v_Row = v_Sheet.createRow(v_RowIndex);
for (int v_ColIndex=0; v_ColIndex<1; v_ColIndex++)
{
HSSFCell v_Cell = v_Row.createCell(v_ColIndex);
HSSFCellStyle v_CellStyle = v_Workbook.createCellStyle();
v_CellStyle.setFillForegroundColor((short)(v_RowIndex + 1));
v_CellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
v_Cell.setCellStyle(v_CellStyle);
v_Cell.setCellValue("" + (v_RowIndex + 1));
}
}
ExcelHelp.save(v_Workbook ,"/Users/hy/Downloads/测试2003版本的单元格颜色");
}
示例8: createHeader
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //导入方法依赖的package包/类
private void createHeader(
HSSFWorkbook wb,
HSSFSheet sheet,
List<TascaDadaDto> informeCamps) {
HSSFFont bold;
bold = wb.createFont();
bold.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
bold.setColor(HSSFColor.WHITE.index);
HSSFCellStyle headerStyle;
headerStyle = wb.createCellStyle();
headerStyle.setFillPattern(HSSFCellStyle.FINE_DOTS);
headerStyle.setFillBackgroundColor(HSSFColor.GREY_80_PERCENT.index);
headerStyle.setFont(bold);
int rowNum = 0;
int colNum = 0;
// Capçalera
HSSFRow xlsRow = sheet.createRow(rowNum++);
HSSFCell cell;
cell = xlsRow.createCell(colNum++);
cell.setCellValue(new HSSFRichTextString(StringUtils.capitalize("Expedient")));
cell.setCellStyle(headerStyle);
for (TascaDadaDto camp : informeCamps) {
sheet.autoSizeColumn(colNum);
cell = xlsRow.createCell(colNum++);
cell.setCellValue(new HSSFRichTextString(StringUtils.capitalize(camp.getCampEtiqueta())));
cell.setCellStyle(headerStyle);
}
}
示例9: buildExcelDocument
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //导入方法依赖的package包/类
@Override
protected void buildExcelDocument(Map<String, Object> model,
HSSFWorkbook workbook, HttpServletRequest request, HttpServletResponse response)
throws Exception {
// get data model which is passed by the Spring container
@SuppressWarnings("unchecked")
List<HrmsLogin> users = (List<HrmsLogin>) model.get("allUsers");
// create a new Excel sheet
HSSFSheet sheet = workbook.createSheet("User List");
sheet.setDefaultColumnWidth(30);
// create style for header cells
CellStyle style = workbook.createCellStyle();
Font font = workbook.createFont();
font.setFontName("Arial");
style.setFillForegroundColor(HSSFColor.BLUE.index);
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
font.setColor(HSSFColor.WHITE.index);
style.setFont(font);
// create header row
HSSFRow header = sheet.createRow(0);
header.createCell(0).setCellValue("Employee ID");
header.getCell(0).setCellStyle(style);
header.createCell(1).setCellValue("Username");
header.getCell(1).setCellStyle(style);
header.createCell(2).setCellValue("Password");
header.getCell(2).setCellStyle(style);
header.createCell(3).setCellValue("Role");
header.getCell(3).setCellStyle(style);
// create data rows
int rowCount = 1;
for (HrmsLogin account : users) {
HSSFRow aRow = sheet.createRow(rowCount++);
aRow.createCell(0).setCellValue(account.getHrmsEmployeeDetails().getEmpId());
aRow.createCell(1).setCellValue(account.getUsername());
aRow.createCell(2).setCellValue(account.getPassword());
aRow.createCell(3).setCellValue(account.getRole());
}
}
示例10: setBold
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //导入方法依赖的package包/类
private static void setBold(HSSFWorkbook workbook, HSSFCell cell) {
HSSFCellStyle boldStyle = workbook.createCellStyle();
HSSFFont boldFont = workbook.createFont();
boldFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
boldStyle.setFont(boldFont);
cell.setCellStyle(boldStyle);
}
示例11: generate
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //导入方法依赖的package包/类
/**
* MS Excelワークブックを生成する.
* <p>
* このメソッドでサポートするのは、1ブック1シートのデータのみ. 罫線を出力することは可能だが、線種や太さなどの指定はできない.
* 生成したデータのファイル出力は行わず、戻り値としてデータを返す.
* </p>
* @param context Excelブック生成に関する情報
* @return MS Excelワークブックデータ
*/
public byte[] generate(WorkbookGeneratorContext context) {
if (LOG.isDebugEnabled()) {
LOG.debug("generate start");
}
checkState(context);
HSSFWorkbook workBook = new HSSFWorkbook();
HSSFSheet sheet = workBook.createSheet(context.sheetName);
HSSFCellStyle style = workBook.createCellStyle();
setBorder(context, style);
// ヘッダー作成
int count = 0;
if (createHeader(context, sheet, style)) {
count++;
}
if (LOG.isDebugEnabled()) {
LOG.debug(" createRow start");
}
// データ作成
createRow(context, workBook, sheet, count, style);
if (LOG.isDebugEnabled()) {
LOG.debug(" createRow end");
}
try {
if (LOG.isDebugEnabled()) {
LOG.debug(" toByte start");
}
// バイナリデータに変換して返す
return toByte(workBook);
} finally {
if (LOG.isDebugEnabled()) {
LOG.debug(" toByte end");
}
}
}
示例12: copyCellStyle
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //导入方法依赖的package包/类
public static HSSFCellStyle copyCellStyle(HSSFWorkbook workbook,
HSSFCellStyle style) {
HSSFCellStyle newCellStyle = workbook.createCellStyle();
newCellStyle.setAlignment(style.getAlignment());
newCellStyle.setBorderBottom(style.getBorderBottom());
newCellStyle.setBorderLeft(style.getBorderLeft());
newCellStyle.setBorderRight(style.getBorderRight());
newCellStyle.setBorderTop(style.getBorderTop());
newCellStyle.setBottomBorderColor(style.getBottomBorderColor());
newCellStyle.setDataFormat(style.getDataFormat());
newCellStyle.setFillBackgroundColor(style.getFillBackgroundColor());
newCellStyle.setFillForegroundColor(style.getFillForegroundColor());
newCellStyle.setFillPattern(style.getFillPattern());
newCellStyle.setHidden(style.getHidden());
newCellStyle.setIndention(style.getIndention());
newCellStyle.setLeftBorderColor(style.getLeftBorderColor());
newCellStyle.setLocked(style.getLocked());
newCellStyle.setRightBorderColor(style.getRightBorderColor());
newCellStyle.setRotation(style.getRotation());
newCellStyle.setTopBorderColor(style.getTopBorderColor());
newCellStyle.setVerticalAlignment(style.getVerticalAlignment());
newCellStyle.setWrapText(style.getWrapText());
HSSFFont font = workbook.getFontAt(style.getFontIndex());
newCellStyle.setFont(font);
return newCellStyle;
}
示例13: copyCellStyle
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //导入方法依赖的package包/类
public static HSSFCellStyle copyCellStyle(final HSSFWorkbook workbook, final HSSFCellStyle style) {
final HSSFCellStyle newCellStyle = workbook.createCellStyle();
newCellStyle.setAlignment(style.getAlignment());
newCellStyle.setBorderBottom(style.getBorderBottom());
newCellStyle.setBorderLeft(style.getBorderLeft());
newCellStyle.setBorderRight(style.getBorderRight());
newCellStyle.setBorderTop(style.getBorderTop());
newCellStyle.setBottomBorderColor(style.getBottomBorderColor());
newCellStyle.setDataFormat(style.getDataFormat());
newCellStyle.setFillBackgroundColor(style.getFillBackgroundColor());
newCellStyle.setFillForegroundColor(style.getFillForegroundColor());
newCellStyle.setFillPattern(style.getFillPattern());
newCellStyle.setHidden(style.getHidden());
newCellStyle.setIndention(style.getIndention());
newCellStyle.setLeftBorderColor(style.getLeftBorderColor());
newCellStyle.setLocked(style.getLocked());
newCellStyle.setRightBorderColor(style.getRightBorderColor());
newCellStyle.setRotation(style.getRotation());
newCellStyle.setTopBorderColor(style.getTopBorderColor());
newCellStyle.setVerticalAlignment(style.getVerticalAlignment());
newCellStyle.setWrapText(style.getWrapText());
final HSSFFont font = workbook.getFontAt(style.getFontIndex());
newCellStyle.setFont(font);
return newCellStyle;
}
示例14: createCellStyleForComRepSetUp
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //导入方法依赖的package包/类
public static HSSFCellStyle createCellStyleForComRepSetUp(HSSFWorkbook workBook) {
HSSFCellStyle cellStyle = workBook.createCellStyle();
HSSFFont fontObj = workBook.createFont();
cellStyle.setAlignment(HorizontalAlignment.CENTER);
fontObj.setFontName("Calibri");
fontObj.setFontHeightInPoints(Short.valueOf("12").shortValue());
fontObj.setBold(true);
fontObj.setColor((short) 17);
cellStyle.setFont(fontObj);
return cellStyle;
}
示例15: createCelStyleForTime
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //导入方法依赖的package包/类
public static HSSFCellStyle createCelStyleForTime(HSSFWorkbook workBook)
{
HSSFCellStyle cellStyle = workBook.createCellStyle();
CreationHelper createHelper = workBook.getCreationHelper();
cellStyle.setDataFormat(
createHelper.createDataFormat().getFormat("m/d/yy h:mm:ss"));
return cellStyle;
}