java createcell_Java Workbook.createCellStyle方法代碼示例

本文整理匯總了Java中org.apache.poi.ss.usermodel.Workbook.createCellStyle方法的典型用法代碼示例。如果您正苦於以下問題:Java Workbook.createCellStyle方法的具體用法?Java Workbook.createCellStyle怎麽用?Java Workbook.createCellStyle使用的例子?那麽恭喜您, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.poi.ss.usermodel.Workbook的用法示例。

在下文中一共展示了Workbook.createCellStyle方法的17個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Java代碼示例。

示例1: defaultDataCellStyle

​點讚 6

import org.apache.poi.ss.usermodel.Workbook; //導入方法依賴的package包/類

/**

* Returns the default data cell style. Obtained from:

* http://svn.apache.org/repos/asf/poi

* /trunk/src/examples/src/org/apache/poi/ss/examples/TimesheetDemo.java

*

* @param wb the wb

* @return the cell style

*/

protected CellStyle defaultDataCellStyle(final Workbook wb) {

CellStyle style;

style = wb.createCellStyle();

style.setAlignment(HorizontalAlignment.CENTER);

style.setWrapText(true);

style.setBorderRight(BorderStyle.THIN);

style.setRightBorderColor(IndexedColors.BLACK.getIndex());

style.setBorderLeft(BorderStyle.THIN);

style.setLeftBorderColor(IndexedColors.BLACK.getIndex());

style.setBorderTop(BorderStyle.THIN);

style.setTopBorderColor(IndexedColors.BLACK.getIndex());

style.setBorderBottom(BorderStyle.THIN);

style.setBottomBorderColor(IndexedColors.BLACK.getIndex());

style.setDataFormat(doubleDataFormat);

return style;

}

開發者ID:TFyre,項目名稱:vaadin-gridexport,代碼行數:25,

示例2: defaultHeaderCellStyle

​點讚 4

import org.apache.poi.ss.usermodel.Workbook; //導入方法依賴的package包/類

/**

* Returns the default header style. Obtained from:

* http://svn.apache.org/repos/asf/poi

* /trunk/src/examples/src/org/apache/poi/ss/examples/TimesheetDemo.java

*

* @param wb the wb

* @return the cell style

*/

protected CellStyle defaultHeaderCellStyle(final Workbook wb) {

CellStyle style;

final Font monthFont = wb.createFont();

monthFont.setFontHeightInPoints((short) 11);

monthFont.setColor(IndexedColors.WHITE.getIndex());

style = wb.createCellStyle();

style.setAlignment(HorizontalAlignment.CENTER);

style.setVerticalAlignment(VerticalAlignment.CENTER);

style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());

style.setFillPattern(FillPatternType.SOLID_FOREGROUND);

style.setFont(monthFont);

style.setWrapText(true);

return style;

}

開發者ID:TFyre,項目名稱:vaadin-gridexport,代碼行數:23,

示例3: doCreateCellStyle

​點讚 4

import org.apache.poi.ss.usermodel.Workbook; //導入方法依賴的package包/類

/** 創建每個CellStyle,並放到map之中

* @param workbook

* @param styleInfo

* @param dataFormat

* @return

*/

public static CellStyle doCreateCellStyle(Workbook workbook,ExportCellStyleInfo styleInfo,String dataFormat) {

if(styleInfo != null ){

CellStyle cellStyle = workbook.createCellStyle();

setStyleValue(ExportCellStyleInfo.class, cellStyle, styleInfo);

if(styleInfo.getFontStyleInfo() != null){

Font fontStyle = workbook.createFont();

setStyleValue(ExportFontStyleInfo.class, fontStyle, styleInfo.getFontStyleInfo());

cellStyle.setFont(fontStyle);

}

if(!StringUtils.isEmpty(dataFormat)){

short format = workbook.createDataFormat().getFormat(dataFormat);

cellStyle.setDataFormat(format);

}

return cellStyle;

}

return null;

}

開發者ID:long47964,項目名稱:excel-utils,代碼行數:24,

示例4: defaultTitleCellStyle

​點讚 4

import org.apache.poi.ss.usermodel.Workbook; //導入方法依賴的package包/類

/**

* Returns the default title style. Obtained from:

* http://svn.apache.org/repos/asf/poi

* /trunk/src/examples/src/org/apache/poi/ss/examples/TimesheetDemo.java

*

* @param wb the wb

* @return the cell style

*/

protected CellStyle defaultTitleCellStyle(final Workbook wb) {

CellStyle style;

final Font titleFont = wb.createFont();

titleFont.setFontHeightInPoints((short) 18);

titleFont.setBold(true);

style = wb.createCellStyle();

style.setAlignment(HorizontalAlignment.CENTER);

style.setVerticalAlignment(VerticalAlignment.CENTER);

style.setFont(titleFont);

return style;

}

開發者ID:TFyre,項目名稱:vaadin-gridexport,代碼行數:20,

示例5: createStyles

​點讚 3

import org.apache.poi.ss.usermodel.Workbook; //導入方法依賴的package包/類

/**

* 創建表格樣式

* @param wb 工作薄對象

* @return 樣式列表

*/

private Map createStyles(Workbook wb) {

Map styles = new HashMap();

CellStyle style = wb.createCellStyle();

style.setAlignment(CellStyle.ALIGN_CENTER);

style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);

Font titleFont = wb.createFont();

titleFont.setFontName("Arial");

titleFont.setFontHeightInPoints((short) 16);

titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);

style.setFont(titleFont);

styles.put("title", style);

style = wb.createCellStyle();

style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);

style.setBorderRight(CellStyle.BORDER_THIN);

style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());

style.setBorderLeft(CellStyle.BORDER_THIN);

style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());

style.setBorderTop(CellStyle.BORDER_THIN);

style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());

style.setBorderBottom(CellStyle.BORDER_THIN);

style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());

Font dataFont = wb.createFont();

dataFont.setFontName("Arial");

dataFont.setFontHeightInPoints((short) 10);

style.setFont(dataFont);

styles.put("data", style);

style = wb.createCellStyle();

style.cloneStyleFrom(styles.get("data"));

style.setAlignment(CellStyle.ALIGN_LEFT);

styles.put("data1", style);

style = wb.createCellStyle();

style.cloneStyleFrom(styles.get("data"));

style.setAlignment(CellStyle.ALIGN_CENTER);

styles.put("data2", style);

style = wb.createCellStyle();

style.cloneStyleFrom(styles.get("data"));

style.setAlignment(CellStyle.ALIGN_RIGHT);

styles.put("data3", style);

style = wb.createCellStyle();

style.cloneStyleFrom(styles.get("data"));

//style.setWrapText(true);

style.setAlignment(CellStyle.ALIGN_CENTER);

style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());

style.setFillPattern(CellStyle.SOLID_FOREGROUND);

Font headerFont = wb.createFont();

headerFont.setFontName("Arial");

headerFont.setFontHeightInPoints((short) 10);

headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);

headerFont.setColor(IndexedColors.WHITE.getIndex());

style.setFont(headerFont);

styles.put("header", style);

return styles;

}

開發者ID:sombie007,項目名稱:ExcelHandle,代碼行數:66,

示例6: createBorderedStyle

​點讚 3

import org.apache.poi.ss.usermodel.Workbook; //導入方法依賴的package包/類

private static CellStyle createBorderedStyle(Workbook wb) {

CellStyle style = wb.createCellStyle();

style.setBorderRight(CellStyle.BORDER_THIN);

style.setRightBorderColor(IndexedColors.BLACK.getIndex());

style.setBorderBottom(CellStyle.BORDER_THIN);

style.setBottomBorderColor(IndexedColors.BLACK.getIndex());

style.setBorderLeft(CellStyle.BORDER_THIN);

style.setLeftBorderColor(IndexedColors.BLACK.getIndex());

style.setBorderTop(CellStyle.BORDER_THIN);

style.setTopBorderColor(IndexedColors.BLACK.getIndex());

return style;

}

開發者ID:Vitaliy-Yakovchuk,項目名稱:ramus,代碼行數:13,

示例7: createStyles

​點讚 3

import org.apache.poi.ss.usermodel.Workbook; //導入方法依賴的package包/類

/**

* excel 樣式

*

* @return

*/

public Map createStyles(Workbook workbook) {

Map styles = new HashMap();

CellStyle style = workbook.createCellStyle();

style.setAlignment((short) 2);

style.setVerticalAlignment((short) 1);

Font titleFont = workbook.createFont();

titleFont.setFontName("Arial");

titleFont.setFontHeightInPoints((short) 16);

titleFont.setBoldweight((short) 700);

style.setFont(titleFont);

styles.put("title", style);

style = workbook.createCellStyle();

style.setVerticalAlignment((short) 1);

style.setBorderRight((short) 1);

style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());

style.setBorderLeft((short) 1);

style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());

style.setBorderTop((short) 1);

style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());

style.setBorderBottom((short) 1);

style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());

Font dataFont = workbook.createFont();

dataFont.setFontName("Arial");

dataFont.setFontHeightInPoints((short) 10);

style.setFont(dataFont);

styles.put("data", style);

style = workbook.createCellStyle();

style.cloneStyleFrom((CellStyle) styles.get("data"));

style.setAlignment((short) 1);

styles.put("data1", style);

style = workbook.createCellStyle();

style.cloneStyleFrom((CellStyle) styles.get("data"));

style.setAlignment((short) 2);

styles.put("data2", style);

style = workbook.createCellStyle();

style.cloneStyleFrom((CellStyle) styles.get("data"));

style.setAlignment((short) 3);

styles.put("data3", style);

style = workbook.createCellStyle();

style.cloneStyleFrom((CellStyle) styles.get("data"));

style.setAlignment((short) 2);

style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());

style.setFillPattern((short) 1);

Font headerFont = workbook.createFont();

headerFont.setFontName("Arial");

headerFont.setFontHeightInPoints((short) 10);

headerFont.setBoldweight((short) 700);

headerFont.setColor(IndexedColors.WHITE.getIndex());

style.setFont(headerFont);

styles.put("header", style);

return styles;

}

開發者ID:zhangbiy,項目名稱:exportExcel,代碼行數:58,

示例8: createBorderCellStyle

​點讚 3

import org.apache.poi.ss.usermodel.Workbook; //導入方法依賴的package包/類

public CellStyle createBorderCellStyle(Workbook workbook, boolean showBorder) {

CellStyle style = workbook.createCellStyle();

if (showBorder) {

style.setBorderRight(BorderStyle.THIN);

style.setRightBorderColor(IndexedColors.BLACK.getIndex());

style.setBorderBottom(BorderStyle.THIN);

style.setBottomBorderColor(IndexedColors.BLACK.getIndex());

style.setBorderLeft(BorderStyle.THIN);

style.setLeftBorderColor(IndexedColors.BLACK.getIndex());

style.setBorderTop(BorderStyle.THIN);

style.setTopBorderColor(IndexedColors.BLACK.getIndex());

}

return style;

}

開發者ID:bsteker,項目名稱:bdf2,代碼行數:15,

示例9: createCellStyle

​點讚 2

import org.apache.poi.ss.usermodel.Workbook; //導入方法依賴的package包/類

private static XSSFCellStyle createCellStyle(Workbook workbook) {

XSSFCellStyle xstyle = (XSSFCellStyle) workbook.createCellStyle();

XSSFFont font = (XSSFFont) workbook.createFont();

font.setFontHeightInPoints((short) 11);

xstyle.setFont(font);

return xstyle;

}

開發者ID:Adobe-Consulting-Services,項目名稱:aem-epic-tool,代碼行數:8,

示例10: initialize

​點讚 2

import org.apache.poi.ss.usermodel.Workbook; //導入方法依賴的package包/類

@Override

public void initialize(Workbook workbook) {

this.borderStyle = workbook.createCellStyle();

this.borderStyle.setBorderBottom(BorderStyle.THIN);

this.borderStyle.setBorderTop(BorderStyle.THIN);

this.borderStyle.setBorderRight(BorderStyle.THIN);

this.borderStyle.setBorderLeft(BorderStyle.THIN);

}

開發者ID:Coreoz,項目名稱:Windmill,代碼行數:9,

示例11: initializeSheet

​點讚 2

import org.apache.poi.ss.usermodel.Workbook; //導入方法依賴的package包/類

private static CellStyle initializeSheet(Workbook wb, Sheet sheet) {

PrintSetup printSetup = sheet.getPrintSetup();

printSetup.setLandscape(true);

sheet.setFitToPage(true);

sheet.setHorizontallyCenter(true);

CellStyle styleTitle;

Font titleFont = wb.createFont();

titleFont.setFontHeightInPoints((short) 12);

titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);

titleFont.setFontName("Arial");

styleTitle = wb.createCellStyle();

styleTitle.setFont(titleFont);

return styleTitle;

}

開發者ID:servicecatalog,項目名稱:oscm,代碼行數:16,

示例12: createDateStyle

​點讚 2

import org.apache.poi.ss.usermodel.Workbook; //導入方法依賴的package包/類

private CellStyle createDateStyle(Workbook workbook) {

CellStyle style = workbook.createCellStyle();

style.setDataFormat(workbook.getCreationHelper().createDataFormat()

.getFormat("m/d/yy"));

return style;

}

開發者ID:Vitaliy-Yakovchuk,項目名稱:ramus,代碼行數:8,

示例13: defaultTotalsDoubleCellStyle

​點讚 2

import org.apache.poi.ss.usermodel.Workbook; //導入方法依賴的package包/類

/**

* Returns the default totals row style for Double data. Obtained from:

* http://svn.apache.org/repos/asf/poi

* /trunk/src/examples/src/org/apache/poi/ss/examples/TimesheetDemo.java

*

* @param wb the wb

* @return the cell style

*/

protected CellStyle defaultTotalsDoubleCellStyle(final Workbook wb) {

CellStyle style;

style = wb.createCellStyle();

style.setAlignment(HorizontalAlignment.CENTER);

style.setVerticalAlignment(VerticalAlignment.CENTER);

style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());

style.setFillPattern(FillPatternType.SOLID_FOREGROUND);

style.setDataFormat(doubleDataFormat);

return style;

}

開發者ID:TFyre,項目名稱:vaadin-gridexport,代碼行數:19,

示例14: defaultTotalsIntegerCellStyle

​點讚 2

import org.apache.poi.ss.usermodel.Workbook; //導入方法依賴的package包/類

/**

* Returns the default totals row style for Integer data. Obtained from:

* http://svn.apache.org/repos/asf/poi

* /trunk/src/examples/src/org/apache/poi/ss/examples/TimesheetDemo.java

*

* @param wb the wb

* @return the cell style

*/

protected CellStyle defaultTotalsIntegerCellStyle(final Workbook wb) {

CellStyle style;

style = wb.createCellStyle();

style.setAlignment(HorizontalAlignment.CENTER);

style.setVerticalAlignment(VerticalAlignment.CENTER);

style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());

style.setFillPattern(FillPatternType.SOLID_FOREGROUND);

style.setDataFormat(integerDataFormat);

return style;

}

開發者ID:TFyre,項目名稱:vaadin-gridexport,代碼行數:19,

示例15: createCell

​點讚 2

import org.apache.poi.ss.usermodel.Workbook; //導入方法依賴的package包/類

/**

* Creates a cell and aligns it a certain way.

*

* @param wb the workbook

* @param row the row to create the cell in

* @param column the column number to create the cell in

* @param halign the horizontal alignment for the cell.

*/

private static void createCell(Workbook wb, Row row, short column, short halign, short valign) {

Cell cell = row.createCell(column);

cell.setCellValue("Align It");

CellStyle cellStyle = wb.createCellStyle();

cellStyle.setAlignment(halign);

cellStyle.setVerticalAlignment(valign);

cell.setCellStyle(cellStyle);

}

開發者ID:robinhowlett,項目名稱:handycapper,代碼行數:17,

示例16: ExcelTestHelper

​點讚 2

import org.apache.poi.ss.usermodel.Workbook; //導入方法依賴的package包/類

ExcelTestHelper(final String parent, boolean generateXls) throws Exception {

this.xls = generateXls;

// Create a test Excel sheet with all types of supported data

Workbook wb = generateXls ? new HSSFWorkbook() : new XSSFWorkbook();

CreationHelper creationHelper = wb.getCreationHelper();

DataFormat dataFormat = creationHelper.createDataFormat();

short fmt = dataFormat.getFormat("yyyy-mm-dd hh:mm:ss");

CellStyle style = wb.createCellStyle();

style.setDataFormat(fmt);

Sheet sheetWithHeader = wb.createSheet("Sheet 1");

// Create header row

Row headerRow = sheetWithHeader.createRow((short) 0);

headerRow.createCell(0).setCellValue("Number");

headerRow.createCell(1).setCellValue("String1");

headerRow.createCell(2).setCellValue("String2");

headerRow.createCell(3).setCellValue("MyTime");

headerRow.createCell(4).setCellValue("Formula");

headerRow.createCell(5).setCellValue("Boolean");

headerRow.createCell(6).setCellValue("Error");

generateSheetData(sheetWithHeader, style, (short)1);

Sheet sheetWithoutHeader = wb.createSheet("Sheet 2");

generateSheetData(sheetWithoutHeader, style, (short)0);

testFilePath = new File(parent, "excelTestFile").getPath();

// Write the output to a file

FileOutputStream fileOut = new FileOutputStream(testFilePath);

wb.write(fileOut);

fileOut.close();

}

開發者ID:dremio,項目名稱:dremio-oss,代碼行數:36,

示例17: builder

​點讚 1

import org.apache.poi.ss.usermodel.Workbook; //導入方法依賴的package包/類

/**

* 構建ExcelStyle

*

* @param workbook

* @return

*/

public static ExcelStyle builder(Workbook workbook) {

ExcelStyle excelStyle = new ExcelStyle(workbook.createCellStyle(), workbook.createFont());

return excelStyle;

}

開發者ID:zhangbiy,項目名稱:exportExcel,代碼行數:11,

注:本文中的org.apache.poi.ss.usermodel.Workbook.createCellStyle方法示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。


版权声明:本文为weixin_29956897原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。