org.apache.poi.ss.usermodel.CellStyle.setWrapText()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(10.0k)|赞(0)|评价(0)|浏览(589)

本文整理了Java中org.apache.poi.ss.usermodel.CellStyle.setWrapText()方法的一些代码示例,展示了CellStyle.setWrapText()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CellStyle.setWrapText()方法的具体详情如下:
包路径:org.apache.poi.ss.usermodel.CellStyle
类名称:CellStyle
方法名:setWrapText

CellStyle.setWrapText介绍

[英]Set whether the text should be wrapped. Setting this flag to true make all content visible whithin a cell by displaying it on multiple lines
[中]设置是否应包装文本。将此标志设置为true,通过在多行上显示单元格中的所有内容,使其可见

代码示例

代码示例来源:origin: stackoverflow.com

CellStyle cs = wb.createCellStyle();
cs.setWrapText(true);
cell.setCellStyle(cs);

代码示例来源:origin: primefaces/primefaces

protected void applyOptions(Workbook wb, DataTable table, Sheet sheet, ExporterOptions options) {
  facetStyle = wb.createCellStyle();
  facetStyle.setAlignment(HorizontalAlignment.CENTER);
  facetStyle.setVerticalAlignment(VerticalAlignment.CENTER);
  facetStyle.setWrapText(true);
  applyFacetOptions(wb, options, facetStyle);
  cellStyle = wb.createCellStyle();
  cellStyle.setAlignment(HorizontalAlignment.LEFT);
  applyCellOptions(wb, options, cellStyle);
  PrintSetup printSetup = sheet.getPrintSetup();
  printSetup.setLandscape(true);
  printSetup.setPaperSize(PrintSetup.A4_PAPERSIZE);
  sheet.setPrintGridlines(true);
}

代码示例来源:origin: alibaba/easyexcel

/**
 *
 * @param workbook
 * @return
 */
public static CellStyle buildDefaultCellStyle(Workbook workbook) {
  CellStyle newCellStyle = workbook.createCellStyle();
  Font font = workbook.createFont();
  font.setFontName("宋体");
  font.setFontHeightInPoints((short)14);
  font.setBold(true);
  newCellStyle.setFont(font);
  newCellStyle.setWrapText(true);
  newCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
  newCellStyle.setAlignment(HorizontalAlignment.CENTER);
  newCellStyle.setLocked(true);
  newCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
  newCellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
  newCellStyle.setBorderBottom(BorderStyle.THIN);
  newCellStyle.setBorderLeft(BorderStyle.THIN);
  return newCellStyle;
}

代码示例来源:origin: stackoverflow.com

public class SO{
public static void main(String[] args) {

  try {
    FileInputStream is = new FileInputStream(new File("D:\\Users\\user2777005\\Desktop\\bob.xlsx"));
    XSSFWorkbook wb = new XSSFWorkbook(is);
    String header = "123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789";
    Sheet sheet = wb.getSheet("Sheet1");
    sheet.setColumnWidth(0, 18000);
    Row row = sheet.createRow(0);
    Cell cell = row.createCell(0);

    if(header.length() > 50){ //Length of String for my test
      sheet.setColumnWidth(0, 18000); //Set column width, you'll probably want to tweak the second int
      CellStyle style = wb.createCellStyle(); //Create new style
      style.setWrapText(true); //Set wordwrap
      cell.setCellStyle(style); //Apply style to cell
      cell.setCellValue(header); //Write header
    }

    wb.write(new FileOutputStream(new File("D:\\Users\\user2777005\\Desktop\\bob.xlsx")));
  } catch (IOException e) {
    e.printStackTrace();
  }
}
}

代码示例来源:origin: stackoverflow.com

Workbook wb = new XSSFWorkbook();   //or new HSSFWorkbook();
 Sheet sheet = wb.createSheet();
 Row row = sheet.createRow(2);
 Cell cell = row.createCell(2);
 cell.setCellValue("Use \n with word wrap on to create a new line");
 //to enable newlines you need set a cell styles with wrap=true
 CellStyle cs = wb.createCellStyle();
 cs.setWrapText(true);
 cell.setCellStyle(cs);
 //increase row height to accomodate two lines of text
 row.setHeightInPoints((2*sheet.getDefaultRowHeightInPoints()));
 //adjust column width to fit the content
 sheet.autoSizeColumn((short)2);
 FileOutputStream fileOut = new FileOutputStream("ooxml-newlines.xlsx");
 wb.write(fileOut);
 fileOut.close();

代码示例来源:origin: apache/tika

private void dumpXLSX(Connection c, Path reportsRoot) throws IOException, SQLException {
  Statement st = c.createStatement();
  Path out = reportsRoot.resolve(reportFilename);
  Files.createDirectories(out.getParent());
  SXSSFWorkbook wb = new SXSSFWorkbook(new XSSFWorkbook(), 100, true, true);
  wb.setCompressTempFiles(true);
  defaultIntegerFormatter.reset(wb.getXSSFWorkbook());
  defaultDoubleFormatter.reset(wb.getXSSFWorkbook());
  sqlCellStyle = wb.createCellStyle();
  sqlCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
  sqlCellStyle.setWrapText(true);
  try {
    dumpReportToWorkbook(st, wb);
  } finally {
    try (OutputStream os = Files.newOutputStream(out)) {
      wb.write(os);
    } finally {
      wb.dispose();
    }
  }
}

代码示例来源:origin: org.apache.poi/poi

/**
 * Sets the format properties of the given style based on the given map.
 *
 * @param style cell style
 * @param workbook parent workbook
 * @param properties map of format properties (String -> Object)
 * @see #getFormatProperties(CellStyle)
 */
private static void setFormatProperties(CellStyle style, Workbook workbook, Map<String, Object> properties) {
  style.setAlignment(getHorizontalAlignment(properties, ALIGNMENT));
  style.setVerticalAlignment(getVerticalAlignment(properties, VERTICAL_ALIGNMENT));
  style.setBorderBottom(getBorderStyle(properties, BORDER_BOTTOM));
  style.setBorderLeft(getBorderStyle(properties, BORDER_LEFT));
  style.setBorderRight(getBorderStyle(properties, BORDER_RIGHT));
  style.setBorderTop(getBorderStyle(properties, BORDER_TOP));
  style.setBottomBorderColor(getShort(properties, BOTTOM_BORDER_COLOR));
  style.setDataFormat(getShort(properties, DATA_FORMAT));
  style.setFillPattern(getFillPattern(properties, FILL_PATTERN));
  style.setFillForegroundColor(getShort(properties, FILL_FOREGROUND_COLOR));
  style.setFillBackgroundColor(getShort(properties, FILL_BACKGROUND_COLOR));
  style.setFont(workbook.getFontAt(getInt(properties, FONT)));
  style.setHidden(getBoolean(properties, HIDDEN));
  style.setIndention(getShort(properties, INDENTION));
  style.setLeftBorderColor(getShort(properties, LEFT_BORDER_COLOR));
  style.setLocked(getBoolean(properties, LOCKED));
  style.setRightBorderColor(getShort(properties, RIGHT_BORDER_COLOR));
  style.setRotation(getShort(properties, ROTATION));
  style.setTopBorderColor(getShort(properties, TOP_BORDER_COLOR));
  style.setWrapText(getBoolean(properties, WRAP_TEXT));
}

代码示例来源:origin: Vatavuk/excel-io

@Override
  public void accept(final CellStyle style) {
    style.setWrapText(this.value);
  }
}

代码示例来源:origin: stackoverflow.com

Cell cell = rowhead.createCell((short) 0));
 cell.setCellValue("Hi there it is my lengthy \n column please help");
 CellStyle cs = wb.createCellStyle();
 cs.setWrapText(true);
 cell.setCellStyle(cs);

代码示例来源:origin: stackoverflow.com

CellStyle cellStyle = workSheet.getWorkbook().createCellStyle();
cellStyle.setAlignment(CellStyle.ALIGN_CENTER);
cellStyle.setWrapText(true);

for (int i=0; i <= records.size(); i++) {
// Create a new row
Row row = workSheet.createRow((short) i);
Cell cell001 = row.createCell(columnIndex);
cell001.setCellValue("some value");
cell001.setCellStyle(cellStyle);
}

代码示例来源:origin: org.spdx/spdx-tools

public static CellStyle createCenterStyle(Workbook wb) {
  CellStyle centerStyle = wb.createCellStyle();
  centerStyle.setWrapText(false);
  centerStyle.setAlignment(HorizontalAlignment.CENTER);
  return centerStyle;
}

代码示例来源:origin: stackoverflow.com

Workbook wb = new XSSFWorkbook();  
Sheet sheet = wb.createSheet();

Row row = sheet.createRow(2);
Cell cell = row.createCell(2);
cell.setCellValue("Use \n with word wrap on to create a new line");

CellStyle cs = wb.createCellStyle();
cs.setWrapText(true);   //Wrapping text
cell.setCellStyle(cs);

代码示例来源:origin: stackoverflow.com

Workbook wb=WorkbookFactory.create(new FileInputStream(filePath));
CellStyle cs=wb.createCellStyle();
cs.setWrapText(true);
Cell cell=wb.getSheet(0).getRow(0).getCell();
cell.setCellStyle(cs);

代码示例来源:origin: org.jeecg/easypoi-base

@Override
public CellStyle stringSeptailStyle(Workbook workbook, boolean isWarp) {
  CellStyle style = workbook.createCellStyle();
  style.setAlignment(CellStyle.ALIGN_CENTER);
  style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
  style.setDataFormat(STRING_FORMAT);
  if (isWarp) {
    style.setWrapText(true);
  }
  return style;
}

代码示例来源:origin: zhangdaiscott/jeasypoi

@Override
public CellStyle stringSeptailStyle(Workbook workbook, boolean isWarp) {
  CellStyle style = workbook.createCellStyle();
  style.setAlignment(CellStyle.ALIGN_CENTER);
  style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
  style.setDataFormat(STRING_FORMAT);
  if (isWarp) {
    style.setWrapText(true);
  }
  return style;
}

代码示例来源:origin: org.jeecg/easypoi-base

@Override
public CellStyle stringNoneStyle(Workbook workbook, boolean isWarp) {
  CellStyle style = workbook.createCellStyle();
  style.setAlignment(CellStyle.ALIGN_CENTER);
  style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
  style.setDataFormat(STRING_FORMAT);
  if (isWarp) {
    style.setWrapText(true);
  }
  return style;
}

代码示例来源:origin: cn.afterturn/easypoi-base

@Override
public CellStyle stringNoneStyle(Workbook workbook, boolean isWarp) {
  CellStyle style = workbook.createCellStyle();
  style.setAlignment(HorizontalAlignment.CENTER);
  style.setVerticalAlignment(VerticalAlignment.CENTER);
  style.setDataFormat(STRING_FORMAT);
  if (isWarp) {
    style.setWrapText(true);
  }
  return style;
}

代码示例来源:origin: pentaho/pentaho-reporting

@Test
public void testNullElementSttle() {
 ExcelCellStyleBuilder builder = new ExcelCellStyleBuilder( workbook );
 when( workbook.createCellStyle() ).thenReturn( xlsStyle );
 builder.withElementStyle( null, styleKey );
 verify( xlsStyle, times( 0 ) ).setAlignment( any( HorizontalAlignment.class ) );
 verify( xlsStyle, times( 0 ) ).setVerticalAlignment( any( VerticalAlignment.class ) );
 verify( xlsStyle, times( 0 ) ).setFont( any() );
 verify( xlsStyle, times( 0 ) ).setWrapText( anyBoolean() );
 verify( xlsStyle, times( 0 ) ).setIndention( anyShort() );
 verify( xlsStyle, times( 0 ) ).setDataFormat( anyShort() );
}

代码示例来源:origin: org.jeecg/easypoi-base

@Override
public CellStyle getTitleStyle(short color) {
  CellStyle titleStyle = workbook.createCellStyle();
  titleStyle.setBorderLeft((short) 1); // 左边框
  titleStyle.setBorderRight((short) 1); // 右边框
  titleStyle.setBorderBottom((short) 1);
  titleStyle.setBorderTop((short) 1);
  titleStyle.setAlignment(CellStyle.ALIGN_CENTER);
  titleStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
  titleStyle.setWrapText(true);
  return titleStyle;
}

代码示例来源:origin: cn.afterturn/easypoi-base

@Override
public CellStyle getTitleStyle(short color) {
  CellStyle titleStyle = workbook.createCellStyle();
  titleStyle.setBorderLeft(BorderStyle.THIN);
  titleStyle.setBorderRight(BorderStyle.THIN);
  titleStyle.setBorderBottom(BorderStyle.THIN);
  titleStyle.setBorderTop(BorderStyle.THIN);
  titleStyle.setAlignment(HorizontalAlignment.CENTER);
  titleStyle.setVerticalAlignment(VerticalAlignment.CENTER);
  titleStyle.setWrapText(true);
  return titleStyle;
}

相关文章

微信公众号

最新文章

更多