org.apache.poi.hssf.record.FontRecord Java Examples
The following examples show how to use
org.apache.poi.hssf.record.FontRecord.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HSSFWorkbook.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Get the font at the given index number * @param idx index number * @return HSSFFont at the index */ @Override public HSSFFont getFontAt(short idx) { if(fonts == null) { fonts = new HashMap<Short, HSSFFont>(); } // So we don't confuse users, give them back // the same object every time, but create // them lazily Short sIdx = Short.valueOf(idx); if(fonts.containsKey(sIdx)) { return fonts.get(sIdx); } FontRecord font = workbook.getFontRecordAt(idx); HSSFFont retval = new HSSFFont(idx, font); fonts.put(sIdx, retval); return retval; }
Example #2
Source File: InternalWorkbook.java From lams with GNU General Public License v2.0 | 6 votes |
/** * gets the font record at the given index in the font table. Remember * "There is No Four" (someone at M$ must have gone to Rocky Horror one too * many times) * * @param idx the index to look at (0 or greater but NOT 4) * @return FontRecord located at the given index */ public FontRecord getFontRecordAt(int idx) { int index = idx; if (index > 4) { index -= 1; // adjust for "There is no 4" } if (index > (numfonts - 1)) { throw new ArrayIndexOutOfBoundsException( "There are only " + numfonts + " font records, you asked for " + idx); } FontRecord retval = ( FontRecord ) records.get((records.getFontpos() - (numfonts - 1)) + index); return retval; }
Example #3
Source File: HSSFFont.java From lams with GNU General Public License v2.0 | 5 votes |
/** Creates a new instance of HSSFFont */ protected HSSFFont(short index, FontRecord rec) { font = rec; this.index = index; }
Example #4
Source File: HSSFCellStyle.java From lams with GNU General Public License v2.0 | 5 votes |
public void cloneStyleFrom(HSSFCellStyle source) { // First we need to clone the extended format // record _format.cloneStyleFrom(source._format); // Handle matching things if we cross workbooks if(_workbook != source._workbook) { lastDateFormat.set(Short.MIN_VALUE); lastFormats.set(null); getDataFormatStringCache.set(null); // Then we need to clone the format string, // and update the format record for this short fmt = (short)_workbook.createFormat(source.getDataFormatString() ); setDataFormat(fmt); // Finally we need to clone the font, // and update the format record for this FontRecord fr = _workbook.createNewFont(); fr.cloneStyleFrom( source._workbook.getFontRecordAt( source.getFontIndex() ) ); HSSFFont font = new HSSFFont( (short)_workbook.getFontIndex(fr), fr ); setFont(font); } }
Example #5
Source File: InternalWorkbook.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Retrieves the index of the given font * * @param font the font * * @return the font index * * @throws IllegalArgumentException if the font index can't be determined */ public int getFontIndex(FontRecord font) { for(int i=0; i<=numfonts; i++) { FontRecord thisFont = ( FontRecord ) records.get((records.getFontpos() - (numfonts - 1)) + i); if(thisFont == font) { // There is no 4! return (i > 3) ? i+1 : i; } } throw new IllegalArgumentException("Could not find that font!"); }
Example #6
Source File: InternalWorkbook.java From lams with GNU General Public License v2.0 | 5 votes |
/** * creates a new font record and adds it to the "font table". This causes the * boundsheets to move down one, extended formats to move down (so this function moves * those pointers as well) * * @return FontRecord that was just created */ public FontRecord createNewFont() { FontRecord rec = createFont(); records.add(records.getFontpos()+1, rec); records.setFontpos( records.getFontpos() + 1 ); numfonts++; return rec; }
Example #7
Source File: InternalWorkbook.java From lams with GNU General Public License v2.0 | 5 votes |
/** * creates a Font record with the following magic values: <P> * fontheight = 0xc8<P> * attributes = 0x0<P> * color palette index = 0x7fff<P> * bold weight = 0x190<P> * Font Name Length = 5 <P> * Font Name = Arial <P> */ private static FontRecord createFont() { FontRecord retval = new FontRecord(); retval.setFontHeight(( short ) 0xc8); retval.setAttributes(( short ) 0x0); retval.setColorPaletteIndex(( short ) 0x7fff); retval.setBoldWeight(( short ) 0x190); retval.setFontName("Arial"); return retval; }
Example #8
Source File: XslStyleHelper.java From yarg with Apache License 2.0 | 5 votes |
public static void cloneFont(HSSFCellStyle source, HSSFCellStyle target) { // Handle matching things if we cross workbooks InternalWorkbook sourceWorkbook = getWorkbookFromStyle(source); InternalWorkbook targetWorkbook = getWorkbookFromStyle(target); if (targetWorkbook != sourceWorkbook) { // Finally we need to clone the font, and update the format record for this FontRecord fr = targetWorkbook.createNewFont(); fr.cloneStyleFrom(sourceWorkbook.getFontRecordAt(source.getFontIndex())); HSSFFont font = newInstance(HSSFFont.class, new Class[]{int.class, FontRecord.class}, (short)targetWorkbook.getFontIndex(fr), fr); target.setFont(font); } }
Example #9
Source File: ExcelUtil.java From WebStack-Guns with MIT License | 4 votes |
public HSSFCellStyle getColumnTopStyle(HSSFWorkbook workbook) { // 设置字体 HSSFFont font = workbook.createFont(); //设置字体大小 font.setFontHeightInPoints((short) 14); //字体加粗 font.setFontHeight(FontRecord.sid); //font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); //设置字体名字 font.setFontName("Courier New"); //设置样式; HSSFCellStyle style = workbook.createCellStyle(); //设置底边框; //style.setBorderBottom(HSSFCellStyle.BORDER_THIN); style.setBorderBottom(BorderStyle.THIN); //设置底边框颜色; style.setBottomBorderColor(ExtendedFormatRecord.BRICKS); //设置左边框; style.setBorderLeft(BorderStyle.THIN); //设置左边框颜色; style.setLeftBorderColor(ExtendedFormatRecord.BRICKS); //设置右边框; style.setBorderRight(BorderStyle.THIN); //设置右边框颜色; style.setRightBorderColor(ExtendedFormatRecord.BRICKS); //设置顶边框; style.setBorderTop(BorderStyle.THIN); //设置顶边框颜色; style.setTopBorderColor(ExtendedFormatRecord.BRICKS); //在样式用应用设置的字体; style.setFont(font); //设置自动换行; style.setWrapText(false); //设置水平对齐的样式为居中对齐; style.setAlignment(HorizontalAlignment.CENTER); //设置垂直对齐的样式为居中对齐; style.setVerticalAlignment(VerticalAlignment.CENTER); //设置单元格背景颜色 style.setFillForegroundColor(IndexedColors.PALE_BLUE.getIndex()); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); return style; }
Example #10
Source File: InternalWorkbook.java From lams with GNU General Public License v2.0 | 2 votes |
/** * Removes the given font record from the * file's list. This will make all * subsequent font indicies drop by one, * so you'll need to update those yourself! * * @param rec the font record */ public void removeFontRecord(FontRecord rec) { records.remove(rec); // this updates FontPos for us numfonts--; }