日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java xssf 字体样式_Apache POI字体/Fonts

發布時間:2023/12/9 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java xssf 字体样式_Apache POI字体/Fonts 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

本章介紹如何設置不同的字體,應用樣式,并在Excel電子表格中顯示的方向不同角度的文字。

每個系統附帶一個很大的字體如 Arial, Impact, Times New Roman,等字體集合也可以用新的字體更新,如果需要的話。同樣也有各種風格,其中的字體可以顯示,例如,粗體,斜體,下劃線,刪除線等。

字體和字體樣式

下面的代碼用于特定的字體和樣式應用于一單元格的內容。

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 FontStyle

{

public static void main(String[] args)throws Exception

{

XSSFWorkbook workbook = new XSSFWorkbook();

XSSFSheet spreadsheet = workbook.createSheet("Fontstyle");

XSSFRow row = spreadsheet.createRow(2);

//Create a new font and alter it.

XSSFFont font = workbook.createFont();

font.setFontHeightInPoints((short) 30);

font.setFontName("IMPACT");

font.setItalic(true);

font.setColor(HSSFColor.BRIGHT_GREEN.index);

//Set font into style

XSSFCellStyle style = workbook.createCellStyle();

style.setFont(font);

// Create a cell with a value and set style to it.

XSSFCell cell = row.createCell(1);

cell.setCellValue("Font Style");

cell.setCellStyle(style);

FileOutputStream out = new FileOutputStream(

new File("fontstyle.xlsx"));

workbook.write(out);

out.close();

System.out.println(

"fontstyle.xlsx written successfully");

}

}

讓我們保存上面的代碼在一個名為FontStyle.java文件。從命令提示符編譯并執行它如下。

$javac FontStyle.java

$java FontStyle

它生成一個名為fontstyle.xlsx在當前目錄中的Excel文件并顯示在命令提示符處鍵入以下輸出。

fontstyle.xlsx written successfully

fontstyle.xlsx文件如下所示。

文字方向

在這里,可以學習如何設置不同角度的文本方向。通常單元格的內容以水平方式顯示,由左到右,并在00角;但是可以使用下面的代碼來旋轉文本的方向(如果需要的話)。

import java.io.File;

import java.io.FileOutputStream;

import org.apache.poi.xssf.usermodel.XSSFCell;

import org.apache.poi.xssf.usermodel.XSSFCellStyle;

import org.apache.poi.xssf.usermodel.XSSFRow;

import org.apache.poi.xssf.usermodel.XSSFSheet;

import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class TextDirection

{

public static void main(String[] args)throws Exception

{

XSSFWorkbook workbook = new XSSFWorkbook();

XSSFSheet spreadsheet = workbook.createSheet(

"Text direction");

XSSFRow row = spreadsheet.createRow(2);

XSSFCellStyle myStyle = workbook.createCellStyle();

myStyle.setRotation((short) 0);

XSSFCell cell = row.createCell(1);

cell.setCellValue("0D angle");

cell.setCellStyle(myStyle);

//30 degrees

myStyle=workbook.createCellStyle();

myStyle.setRotation((short) 30);

cell = row.createCell(3);

cell.setCellValue("30D angle");

cell.setCellStyle(myStyle);

//90 degrees

myStyle=workbook.createCellStyle();

myStyle.setRotation((short) 90);

cell = row.createCell(5);

cell.setCellValue("90D angle");

cell.setCellStyle(myStyle);

//120 degrees

myStyle=workbook.createCellStyle();

myStyle.setRotation((short) 120);

cell = row.createCell(7);

cell.setCellValue("120D angle");

cell.setCellStyle(myStyle);

//270 degrees

myStyle = workbook.createCellStyle();

myStyle.setRotation((short) 270);

cell = row.createCell(9);

cell.setCellValue("270D angle");

cell.setCellStyle(myStyle);

//360 degrees

myStyle=workbook.createCellStyle();

myStyle.setRotation((short) 360);

cell = row.createCell(12);

cell.setCellValue("360D angle");

cell.setCellStyle(myStyle);

FileOutputStream out = new FileOutputStream(

new File("textdirection.xlsx"));

workbook.write(out);

out.close();

System.out.println(

"textdirection.xlsx written successfully");

}

}

保持TextDirectin.java文件上面的代碼,然后編譯并從命令提示符如下執行它。

$javac TextDirection.java

$java TextDirection

這將編譯和執行,以生成一個名為textdirection.xlsx在當前目錄中的Excel文件并顯示在命令提示符處鍵入以下輸出。

textdirection.xlsx written successfully

textdirection.xlsx文件如下所示。

¥ 我要打賞

糾錯/補充

收藏

加QQ群啦,易百教程官方技術學習群

注意:建議每個人選自己的技術方向加群,同一個QQ最多限加 3 個群。

總結

以上是生活随笔為你收集整理的java xssf 字体样式_Apache POI字体/Fonts的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。