谁能告诉我如何在一个单元格中放置不同大小的文本。像尺寸为20的小字幕和相同字符串中的16..with字幕,使用新的行分隔符。
发布于 2017-09-18 15:04:36
你需要一个RichTextString。您还需要确保行足够高,并且单元格对文本进行换行:
public static void main(String[] args) throws IOException {
FileInputStream fis = new FileInputStream(FILE_NAME);
XSSFWorkbook wb = new XSSFWorkbook(fis);
Sheet sheet = wb.getSheetAt(0);
Row row = sheet.rowIterator().next();
Cell cell = row.cellIterator().next();
XSSFFont font1 = wb.createFont();
font1.setFontHeight(20);
font1.setBold(true);
XSSFFont font2 = wb.createFont();
font2.setFontHeight(16);
font2.setBold(false);
XSSFRichTextString richString = new XSSFRichTextString("Hello,\nWorld!");
richString.applyFont(0, 6, font1);
richString.applyFont(6, 13, font2);
cell.setCellValue(richString);
CellStyle cs = wb.createCellStyle();
cs.setWrapText(true);
cell.setCellStyle(cs);
row.setHeightInPoints((3*sheet.getDefaultRowHeightInPoints()));
FileOutputStream fos = new FileOutputStream(FILE_NAME);
wb.write(fos);
fos.close();
wb.close();
fis.close();
}
https://stackoverflow.com/questions/46277893
复制相似问题