本文整理匯總了Java中org.apache.poi.ss.usermodel.Font.getUnderline方法的典型用法代碼示例。如果您正苦於以下問題:Java Font.getUnderline方法的具體用法?Java Font.getUnderline怎麽用?Java Font.getUnderline使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.poi.ss.usermodel.Font
的用法示例。
在下文中一共展示了Font.getUnderline方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: findFont
import org.apache.poi.ss.usermodel.Font; //導入方法依賴的package包/類
private static Font findFont(Workbook workbook, Font font)
{
int numFonts = workbook.getNumberOfFonts();
for (short i = 0; i < numFonts; i++)
{
Font f = workbook.getFontAt(i);
if (f.getBoldweight() == font.getBoldweight() &&
f.getItalic() == font.getItalic() &&
f.getColor() == font.getColor() &&
f.getFontHeight() == font.getFontHeight() &&
f.getUnderline() == font.getUnderline() &&
f.getFontName().equals(font.getFontName()) &&
f.getTypeOffset() == font.getTypeOffset()
)
{
if (!(font instanceof XSSFFont && f instanceof XSSFFont) ||
((XSSFFont) font).getXSSFColor().getARGBHex().equals(((XSSFFont) f).getXSSFColor().getARGBHex()))
{
if (DEBUG)
System.err.println(" Found existing, matching Font!");
return f;
}
}
}
if (DEBUG)
System.err.println(" Did NOT find existing, matching Font!");
return null;
}
示例2: getPoiFont
import org.apache.poi.ss.usermodel.Font; //導入方法依賴的package包/類
PoiFont getPoiFont(com.dua3.utility.text.Font font, TextAttributes attributes) {
String name = String.valueOf(attributes.getOrDefault(TextAttributes.FONT_FAMILY, font.getFamily()));
Object sSize = attributes.get(TextAttributes.FONT_SIZE);
short height = (short) Math.round(sSize == null ? font.getSizeInPoints() : TextUtil.decodeFontSize(sSize.toString()));
final Object sStyle = attributes.get(TextAttributes.FONT_STYLE);
boolean italic = sStyle == null ? font.isItalic() : "italic".equals(sStyle);
final Object sWeight = attributes.get(TextAttributes.FONT_WEIGHT);
boolean bold = sWeight == null ? font.isBold() : "bold".equals(sWeight);
Object sDecoration = attributes.get(TextAttributes.TEXT_DECORATION);
boolean underline = sDecoration == null ? font.isUnderlined() : "underline".equals(sDecoration);
boolean strikethrough = sDecoration == null ? font.isStrikeThrough() : "line-through".equals(sDecoration);
Object sColor = attributes.get(TextAttributes.COLOR);
Color color = sColor == null ? font.getColor() : Color.valueOf(sColor.toString());
// try to find existing font
for (short i = 0; i < poiWorkbook.getNumberOfFonts(); i++) {
Font poiFont = poiWorkbook.getFontAt(i);
if (poiFont.getFontName().equalsIgnoreCase(name)
&& poiFont.getFontHeightInPoints() == height
&& poiFont.getBold() == bold
&& poiFont.getItalic() == italic
&& (poiFont.getUnderline() != Font.U_NONE) == underline
&& poiFont.getStrikeout() == strikethrough
&& getColor(poiFont, Color.BLACK).equals(color)
&& poiFont.getTypeOffset() == Font.SS_NONE) {
return new PoiFont(this, poiFont);
}
}
// if not found, create it
return createFont(font);
}
示例3: get
import org.apache.poi.ss.usermodel.Font; //導入方法依賴的package包/類
@Override
public Object get(Column column, Cell cell, Font font) {
return (long) font.getUnderline();
}
示例4: poiStyle2Netxilia
import org.apache.poi.ss.usermodel.Font; //導入方法依賴的package包/類
public static Styles poiStyle2Netxilia(CellStyle poiStyle, Font font, HSSFPalette palette,
NetxiliaStyleResolver styleResolver) {
List<Style> entries = new ArrayList<Style>();
if (!poiStyle.getWrapText()) {
entries.add(DefaultStyle.nowrap.getStyle());
}
// font
if (font.getItalic()) {
entries.add(DefaultStyle.italic.getStyle());
}
if (font.getStrikeout()) {
entries.add(DefaultStyle.strikeout.getStyle());
}
if (font.getBoldweight() == Font.BOLDWEIGHT_BOLD) {
entries.add(DefaultStyle.bold.getStyle());
}
if (font.getUnderline() != Font.U_NONE) {
entries.add(DefaultStyle.underline.getStyle());
}
// borders
if (poiStyle.getBorderBottom() != CellStyle.BORDER_NONE) {
entries.add(DefaultStyle.borderBottom.getStyle());
}
if (poiStyle.getBorderLeft() != CellStyle.BORDER_NONE) {
entries.add(DefaultStyle.borderLeft.getStyle());
}
if (poiStyle.getBorderTop() != CellStyle.BORDER_NONE) {
entries.add(DefaultStyle.borderTop.getStyle());
}
if (poiStyle.getBorderRight() != CellStyle.BORDER_NONE) {
entries.add(DefaultStyle.borderRight.getStyle());
}
// align
switch (poiStyle.getAlignment()) {
case CellStyle.ALIGN_LEFT:
entries.add(DefaultStyle.alignLeft.getStyle());
break;
case CellStyle.ALIGN_RIGHT:
entries.add(DefaultStyle.alignRight.getStyle());
break;
case CellStyle.ALIGN_CENTER:
entries.add(DefaultStyle.alignCenter.getStyle());
break;
case CellStyle.ALIGN_JUSTIFY:
entries.add(DefaultStyle.alignJustify.getStyle());
break;
}
if (font != null && font.getColor() != 0) {
HSSFColor poiForeground = palette.getColor(font.getColor());
if (poiForeground != null && poiForeground != HSSFColor.AUTOMATIC.getInstance()) {
Style foregroundDef = styleResolver.approximateForeground(poiForeground.getTriplet()[0],
poiForeground.getTriplet()[1], poiForeground.getTriplet()[2]);
if (foregroundDef != null) {
entries.add(foregroundDef);
}
}
}
if (poiStyle.getFillForegroundColor() != 0) {
HSSFColor poiBackground = palette.getColor(poiStyle.getFillForegroundColor());
if (poiBackground != null && poiBackground != HSSFColor.AUTOMATIC.getInstance()) {
Style backgroundDef = styleResolver.approximateBackground(poiBackground.getTriplet()[0],
poiBackground.getTriplet()[1], poiBackground.getTriplet()[2]);
if (backgroundDef != null) {
entries.add(backgroundDef);
}
}
}
return entries.size() > 0 ? Styles.styles(entries) : null;
}
示例5: findCellStyle
import org.apache.poi.ss.usermodel.Font; //導入方法依賴的package包/類
/**
* Find a <code>CellStyle</code> with all the same attributes as the given
* <code>CellStyle</code> but with the given font index.
* @param workbook The <code>Workbook</code>.
* @param cellStyle The <code>CellStyle</code> to find.
* @param font The <code>Font</code> to find.
* @return The <code>CellStyle</code> from the <code>Workbook</code> if
* found, or <code>null</code> if not found.
*/
private static CellStyle findCellStyle(Workbook workbook, CellStyle cellStyle, Font font)
{
int numCellStyles = workbook.getNumCellStyles();
for (short i = 0; i < numCellStyles; i++)
{
CellStyle cs = workbook.getCellStyleAt(i);
Font f = workbook.getFontAt(cs.getFontIndex());
if (cs.getFillForegroundColor() == cellStyle.getFillForegroundColor() &&
cs.getFillBackgroundColor() == cellStyle.getFillBackgroundColor() &&
cs.getDataFormat() == cellStyle.getDataFormat() &&
cs.getAlignment() == cellStyle.getAlignment() &&
cs.getBorderBottom() == cellStyle.getBorderBottom() &&
cs.getBorderLeft() == cellStyle.getBorderLeft() &&
cs.getBorderRight() == cellStyle.getBorderRight() &&
cs.getBorderTop() == cellStyle.getBorderTop() &&
cs.getFillPattern() == cellStyle.getFillPattern() &&
cs.getWrapText() == cellStyle.getWrapText() &&
cs.getRotation() == cellStyle.getRotation() &&
cs.getBottomBorderColor() == cellStyle.getBottomBorderColor() &&
cs.getTopBorderColor() == cellStyle.getTopBorderColor() &&
cs.getLeftBorderColor() == cellStyle.getLeftBorderColor() &&
cs.getRightBorderColor() == cellStyle.getRightBorderColor() &&
cs.getVerticalAlignment() == cellStyle.getVerticalAlignment() &&
cs.getIndention() == cellStyle.getIndention() &&
cs.getLocked() == cellStyle.getLocked() &&
cs.getHidden() == cellStyle.getHidden() &&
f.getBoldweight() == font.getBoldweight() &&
f.getItalic() == font.getItalic() &&
f.getColor() == font.getColor() &&
f.getFontHeight() == font.getFontHeight() &&
f.getUnderline() == font.getUnderline() &&
f.getFontName().equals(font.getFontName()) &&
f.getTypeOffset() == font.getTypeOffset()
)
{
if (!(font instanceof XSSFFont && f instanceof XSSFFont) ||
((XSSFFont) font).getXSSFColor().getARGBHex().equals(((XSSFFont) f).getXSSFColor().getARGBHex()))
{
if (DEBUG)
System.err.println(" Found existing, matching CellStyle with the Font!");
return cs;
}
}
}
if (DEBUG)
System.err.println(" Did NOT find existing, matching CellStyle with the Font!");
return null;
}
示例6: decorateComponent
import org.apache.poi.ss.usermodel.Font; //導入方法依賴的package包/類
public static void decorateComponent(Cell cell, JComponent renderingComponent, JComponent defaultRenderer) {
CellStyle style = cell.getCellStyle();
// Background neither the index or the color works for XSSF cells
Color backgroundColor = CellUtils.poiToAwtColor(style.getFillBackgroundColorColor());
if (backgroundColor != null) {
renderingComponent.setBackground(backgroundColor);
} else {
renderingComponent.setBackground(defaultRenderer.getBackground());
}
// Font and forground
short fontIndex = style.getFontIndex();
if (fontIndex > 0) {
Font xlsFont = cell.getSheet().getWorkbook().getFontAt(fontIndex);
java.awt.Font font = java.awt.Font.decode(xlsFont.getFontName());
font = font.deriveFont((float) xlsFont.getFontHeightInPoints());
font = font.deriveFont(java.awt.Font.PLAIN);
if (xlsFont.getItalic()) {
font = font.deriveFont(java.awt.Font.ITALIC);
}
if (xlsFont.getBoldweight() == Font.BOLDWEIGHT_BOLD) {
font = font.deriveFont(java.awt.Font.BOLD);
}
if (xlsFont.getUnderline() > Font.U_NONE) {
// no underline in fonts
}
short fontColorIndex = xlsFont.getColor();
Color fontColor = CellUtils.shortToColor(fontColorIndex);
if (fontColor != null) {
renderingComponent.setForeground(fontColor);
} else {
renderingComponent.setForeground(defaultRenderer.getForeground());
}
renderingComponent.setFont(font);
} else {
renderingComponent.setForeground(defaultRenderer.getForeground());
renderingComponent.setFont(defaultRenderer.getFont());
}
// Borders
// At the moment done in renderer but should be done with a JLayer to paint over the grid
renderingComponent.setBorder(new CellBorder(cell));
if (cell.getCellComment() != null) {
renderingComponent.setToolTipText(cell.getCellComment().getString().getString());
}
}
示例7: addFontAttributes
import org.apache.poi.ss.usermodel.Font; //導入方法依賴的package包/類
/**
* Add font details to an AttributedString.
* @param attrString
* The AttributedString to modify.
* @param font
* The font to take attributes from.
* @param startIdx
* The index of the first character to be attributed (inclusive).
* @param endIdx
* The index of the last character to be attributed (inclusive).
*/
protected void addFontAttributes( AttributedString attrString, Font font, int startIdx, int endIdx) {
attrString.addAttribute(TextAttribute.FAMILY, font.getFontName(), startIdx, endIdx);
attrString.addAttribute(TextAttribute.SIZE, (float)font.getFontHeightInPoints(), startIdx, endIdx);
if (font.getBoldweight() == Font.BOLDWEIGHT_BOLD) attrString.addAttribute(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD, startIdx, endIdx);
if (font.getItalic() ) attrString.addAttribute(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE, startIdx, endIdx);
if (font.getUnderline() == Font.U_SINGLE ) attrString.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON, startIdx, endIdx);
}