import
java.io.File;
import
java.io.FileOutputStream;
import
org.apache.poi.hssf.util.HSSFColor;
import
org.apache.poi.xssf.usermodel.XSSFCell;
import
org.apache.poi.xssf.usermodel.XSSFCellStyle;
import
org.apache.poi.xssf.usermodel.XSSFFont;
import
org.apache.poi.xssf.usermodel.XSSFRow;
import
org.apache.poi.xssf.usermodel.XSSFSheet;
import
org.apache.poi.xssf.usermodel.XSSFWorkbook;
public
class
FontsInExcel {
public
static
void
fontFile()
{
XSSFWorkbook myWorkbook =
new
XSSFWorkbook();
XSSFSheet newSpreadsheet
= myWorkbook.createSheet(
"Book"
);
XSSFRow row = newSpreadsheet.createRow(
1
);
XSSFFont font = myWorkbook.createFont();
font.setFontHeightInPoints((
short
)
30
);
font.setFontName(
"Arial"
);
font.setBold(
true
);
font.setItalic(
true
);
font.setColor(HSSFColor.BRIGHT_RED.index);
XSSFCellStyle cellStyle
= myWorkbook.createCellStyle();
cellStyle.setFont(font);
XSSFCell myCell = row.createCell(
6
);
myCell.setCellValue(
"New Font"
);
myCell.setCellStyle(cellStyle);
FileOutputStream file =
new
FileOutputStream(
new
File(
"C:/Book.xlsx"
));
myWorkbook.write(file);
file.close();
}
public
static
void
main(String[] args)
throws
Exception
{
fontFile();
}
}