本文整理汇总了Java中org.apache.poi.ss.usermodel.CellStyle.setWrapText方法的典型用法代码示例。如果您正苦于以下问题:Java CellStyle.setWrapText方法的具体用法?Java CellStyle.setWrapText怎么用?Java CellStyle.setWrapText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.ss.usermodel.CellStyle
的用法示例。
在下文中一共展示了CellStyle.setWrapText方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: defaultDataCellStyle
import org.apache.poi.ss.usermodel.CellStyle; //导入方法依赖的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;
}
示例2: defaultHeaderCellStyle
import org.apache.poi.ss.usermodel.CellStyle; //导入方法依赖的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;
}
示例3: setCommonStyle
import org.apache.poi.ss.usermodel.CellStyle; //导入方法依赖的package包/类
/**
* 设置通用的对齐居中、边框等
*
* @param style 样式
*/
private void setCommonStyle(CellStyle style) {
// 设置单元格居中对齐、自动换行
style.setAlignment(CellStyle.ALIGN_CENTER);
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
style.setWrapText(true);
//设置单元格字体
if (!buildInFontMap.containsKey(FONT_KEY)) {
Font font = workbook.createFont();
//通用字体
font.setBoldweight(Font.BOLDWEIGHT_BOLD);
font.setFontName("宋体");
font.setFontHeight((short) 200);
buildInFontMap.put(FONT_KEY, font);
}
style.setFont(buildInFontMap.get(FONT_KEY));
// 设置单元格边框为细线条
style.setBorderLeft(CellStyle.BORDER_THIN);
style.setBorderBottom(CellStyle.BORDER_THIN);
style.setBorderRight(CellStyle.BORDER_THIN);
style.setBorderTop(CellStyle.BORDER_THIN);
}
示例4: createSheet
import org.apache.poi.ss.usermodel.CellStyle; //导入方法依赖的package包/类
/**
* Creates an excel sheet in the provided workbook using provided parameters.
*
* @param input the data to put in the sheet-
* @param sheetName the name to user for the sheet.
* @param wb the workbook to create the sheet in.
*/
private void createSheet( List<MessageResourceEntry> input,
String sheetName,
Workbook wb)
{
// create a new sheet
String name = StringUtils.isBlank(sheetName) ? this.defaultSheetName : sheetName;
LOG.info("Create sheet with name " + name);
Sheet sheet = wb.createSheet(name);
sheet.setZoom(this.zoom, 100);
Map<Locale, Integer> langs = getLanguageInformation(input);
createHeader(sheet, langs);
CellStyle keyStyle = sheet.getWorkbook().createCellStyle();
keyStyle.setAlignment(CellStyle.ALIGN_LEFT);
keyStyle.setBorderBottom(CellStyle.BORDER_THIN);
keyStyle.setBorderRight(CellStyle.BORDER_MEDIUM);
Font f = sheet.getWorkbook().createFont();
f.setBoldweight(Font.BOLDWEIGHT_NORMAL);
keyStyle.setFont(f);
CellStyle valueStyle = sheet.getWorkbook().createCellStyle();
valueStyle.setAlignment(CellStyle.ALIGN_LEFT);
valueStyle.setVerticalAlignment(CellStyle.VERTICAL_TOP);
valueStyle.setBorderBottom(CellStyle.BORDER_THIN);
valueStyle.setBorderRight(CellStyle.BORDER_THIN);
valueStyle.setBorderTop(CellStyle.BORDER_THIN);
valueStyle.setBorderLeft(CellStyle.BORDER_THIN);
valueStyle.setFont(f);
valueStyle.setWrapText(true);
CellStyle emptyStyle = sheet.getWorkbook().createCellStyle();
emptyStyle.setAlignment(CellStyle.ALIGN_LEFT);
emptyStyle.setVerticalAlignment(CellStyle.VERTICAL_TOP);
emptyStyle.setBorderBottom(CellStyle.BORDER_THIN);
emptyStyle.setBorderRight(CellStyle.BORDER_THIN);
emptyStyle.setBorderTop(CellStyle.BORDER_THIN);
emptyStyle.setBorderLeft(CellStyle.BORDER_THIN);
emptyStyle.setFont(f);
emptyStyle.setFillForegroundColor(IndexedColors.LAVENDER.getIndex());
emptyStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
emptyStyle.setWrapText(true);
LOG.info("Write data to sheet " + name);
int rowIndex = this.languageHeaderRow + 1;
for (MessageResourceEntry entry : input)
{
Row row = sheet.createRow(rowIndex);
createContentRow(entry, row, langs, keyStyle, valueStyle, emptyStyle);
rowIndex++;
}
sizeColumns(sheet, langs);
sheet.createFreezePane(this.firstLanguageColumn, this.languageHeaderRow + 1, this.firstLanguageColumn, this.languageHeaderRow + 1);
}
示例5: writeComment
import org.apache.poi.ss.usermodel.CellStyle; //导入方法依赖的package包/类
/**
* Adds the given information as a new row to the sheet.
* @param id: plant ID number
* @param comment: comment left by visitor
* @param timestamp: time the user left the comment
*/
public void writeComment(String id, String commonName, String cultivar, String gardenLocation, String comment, Date timestamp){
Row row = commentsSheet.createRow((short) commentCount);
Cell cell = row.createCell(0);
cell.setCellValue(id);
cell = row.createCell(1);
cell.setCellValue(commonName);
cell = row.createCell(2);
cell.setCellValue(cultivar);
cell = row.createCell(3);
cell.setCellValue(gardenLocation);
cell = row.createCell(4);
CellStyle style = workbook.createCellStyle();
style.setWrapText(true);
cell.setCellStyle(style);
cell.setCellValue(comment);
cell = row.createCell(5);
cell.setCellValue(timestamp.toString());
commentCount++;
}
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-4-dorfner-v2,代码行数:34,代码来源:CollectedDataWriter.java
示例6: createHSSFCellStyles
import org.apache.poi.ss.usermodel.CellStyle; //导入方法依赖的package包/类
private Map<String, CellStyle> createHSSFCellStyles(Workbook wb, int[] contextBgColor, int[] contextFontColor, int contextFontSize, int contextFontAlign, int[] headerBgColor,
int[] headerFontColor, int headerFontSize, int headerAlign) {
Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
HSSFWorkbook workbook = (HSSFWorkbook) wb;
HSSFPalette palette = workbook.getCustomPalette();
palette.setColorAtIndex((short) 11, (byte) contextBgColor[0], (byte) contextBgColor[1], (byte) contextBgColor[2]);
palette.setColorAtIndex((short) 12, (byte) contextFontColor[0], (byte) contextFontColor[1], (byte) contextFontColor[2]);
palette.setColorAtIndex((short) 13, (byte) headerBgColor[0], (byte) headerBgColor[1], (byte) headerBgColor[2]);
palette.setColorAtIndex((short) 14, (byte) headerFontColor[0], (byte) headerFontColor[1], (byte) headerFontColor[2]);
HSSFFont headerFont = workbook.createFont();
headerFont.setCharSet(HSSFFont.DEFAULT_CHARSET);
headerFont.setFontName("宋体");
headerFont.setColor((short) 14);
headerFont.setBold(true);
headerFont.setFontHeightInPoints((short) headerFontSize);
CellStyle headerStyle = this.createBorderCellStyle(workbook, true);
headerStyle.setFont(headerFont);
headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
headerStyle.setFillForegroundColor((short) 13);
this.setCellStyleAligment(headerStyle, headerAlign);
headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
styles.put(GridStyleType.headerStyle.name(), headerStyle);
HSSFFont dataFont = workbook.createFont();
dataFont.setColor((short) 12);
dataFont.setFontHeightInPoints((short) contextFontSize);
dataFont.setCharSet(HSSFFont.DEFAULT_CHARSET);
dataFont.setFontName("宋体");
CellStyle dataAlignLeftStyle = this.createBorderCellStyle(workbook, true);
dataAlignLeftStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
dataAlignLeftStyle.setFillForegroundColor((short) 11);
dataAlignLeftStyle.setFont(dataFont);
dataAlignLeftStyle.setVerticalAlignment(VerticalAlignment.CENTER);
dataAlignLeftStyle.setWrapText(true);
dataAlignLeftStyle.setAlignment(HorizontalAlignment.LEFT);
styles.put(GridStyleType.dataAlignLeftStyle.name(), dataAlignLeftStyle);
CellStyle dataAlignCenterStyle = this.createBorderCellStyle(workbook, true);
dataAlignCenterStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
dataAlignCenterStyle.setFillForegroundColor((short) 11);
dataAlignCenterStyle.setFont(dataFont);
dataAlignCenterStyle.setVerticalAlignment(VerticalAlignment.CENTER);
dataAlignCenterStyle.setWrapText(true);
dataAlignCenterStyle.setAlignment(HorizontalAlignment.CENTER);
styles.put(GridStyleType.dataAlignCenterStyle.name(), dataAlignCenterStyle);
CellStyle dataAlignRightStyle = this.createBorderCellStyle(workbook, true);
dataAlignRightStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
dataAlignRightStyle.setFillForegroundColor((short) 11);
dataAlignRightStyle.setFont(dataFont);
dataAlignRightStyle.setVerticalAlignment(VerticalAlignment.CENTER);
dataAlignRightStyle.setWrapText(true);
dataAlignRightStyle.setAlignment(HorizontalAlignment.RIGHT);
styles.put(GridStyleType.dataAlignRightStyle.name(), dataAlignRightStyle);
CellStyle dateStyle = this.createBorderCellStyle(workbook, true);
CreationHelper helper = workbook.getCreationHelper();
dateStyle.setDataFormat(helper.createDataFormat().getFormat("m/d/yy h:mm"));
dateStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
dateStyle.setFillForegroundColor((short) 11);
dateStyle.setFont(dataFont);
dateStyle.setVerticalAlignment(VerticalAlignment.CENTER);
this.setCellStyleAligment(dateStyle, contextFontAlign);
styles.put(GridStyleType.dateStyle.name(), dateStyle);
return styles;
}