简体   繁体   English

使用 apache poi 将单元格内容的一部分设置为粗体?

[英]Setting a part of the cell contents to bold using apache poi?

How can i put this string in to a cell using java apache poi?如何使用 java apache poi 将此字符串放入单元格中?
The string is "Hello world Hello"字符串是“Hello world Hello”
As u can see i need to make a part of the text bold?正如你所看到的,我需要将文本的一部分加粗?
I'm able to set the entire contents of the cell to bold but not specific parts.我可以将单元格的全部内容设置为粗体,但不能将特定部分设置为粗体。
Please help me.请帮我。

This is probably what you are looking for: http://poi.apache.org/spreadsheet/quick-guide.html#DrawingShapes这可能就是你要找的: http : //poi.apache.org/spreadsheet/quick-guide.html#DrawingShapes

Find this in the explanation:在解释中找到这个:

It's possible to use different fonts to style parts of the text in the textbox.可以使用不同的字体来设置文本框中部分文本的样式。 Here's how:就是这样:

HSSFFont font = wb.createFont();
font.setItalic(true);
font.setUnderline(HSSFFont.U_DOUBLE);
HSSFRichTextString string = new HSSFRichTextString("Woo!!!");
string.applyFont(2,5,font);
textbox.setString(string );

This might be useful: http://apache-poi.1045710.n5.nabble.com/Multiple-text-styles-in-Excel-cell-td4922683.html这可能有用: http : //apache-poi.1045710.n5.nabble.com/Multiple-text-styles-in-Excel-cell-td4922683.html

This will print "Hello world Hello" in a cell这将在单元格中打印“Hello world Hello”

XSSFRichTextString rts= new XSSFRichTextString("Hello ");

XSSFFont fontBold= wb.createFont();
fontBold.setBold(true); //set bold
fontBold.setFontHeight(12); //add font size

rts.append("world ",fontBold);
rts.append("Hello");

sheet.getRow(1).getCell(1).setCellValue(rts);
cell.setValue(value);
RichTextString rts = cell.getRichStringCellValue();
rts.applyFont(value.indexOf(subValue), value.length(), boldFonts);
cell.setCellValue(rts);

Where value=something+subValue.其中值=某物+子值。 Here subValue contents will be with bold fonts.这里 subValue 内容将使用粗体。 for example if we have someting="Hello" and subValue="world" we will print:例如,如果我们有 someing="Hello" 和 subValue="world" 我们将打印:

Hello world你好世界

in the cell.在单元格中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM