フォント設定の扱い
テキストのルック アンド フィールは、フォント設定を変更することで制御できます。これらのフォント設定には、下の図に示すように、フォントの名前、スタイル、サイズ、色、およびその他の効果が含まれる場合があります。
Microsoft エクセルのフォント設定
Microsoft Excel と同様に、Aspose.Cells もセルのフォント設定の構成をサポートしています。
フォント設定の構成
Aspose.Cells はクラスを提供し、ワークブックMicrosoft Excel ファイルを表します。のワークブッククラスにはワークシート コレクションこれにより、Excel ファイル内の各ワークシートにアクセスできます。ワークシートは、ワークシートクラス。のワークシートクラスはCellsコレクション。の各項目Cellsコレクションはのオブジェクトを表しますCellクラス。
Aspose.Cells はCellクラス'setStyle メソッド。セルの書式を設定するために使用されます。また、オブジェクトのスタイルクラスは、フォント設定を構成するためのプロパティを提供します。
この記事では、次の方法について説明します。
- 特定のフォントをテキストに適用します。
- テキストを太字に設定.
- フォントサイズを設定する.
- フォントの色を設定する.
- テキストに下線を引く.
- 取り消し線テキスト.
- テキストを下付き文字に設定.
- テキストを上付き文字に設定.
フォント名の設定
を使用して、セル内のテキストに特定のフォントを適用します。フォントオブジェクトのセット名財産。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SettingFontName.class) + "data/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Accessing the added worksheet in the Excel file | |
int sheetIndex = workbook.getWorksheets().add(); | |
Worksheet worksheet = workbook.getWorksheets().get(sheetIndex); | |
Cells cells = worksheet.getCells(); | |
// Adding some value to the "A1" cell | |
Cell cell = cells.get("A1"); | |
cell.setValue("Hello Aspose!"); | |
// Setting the font name to "Times New Roman" | |
Style style = cell.getStyle(); | |
Font font = style.getFont(); | |
font.setName("Times New Roman"); | |
cell.setStyle(style); | |
// Saving the modified Excel file in default format | |
workbook.save(dataDir + "SettingFontName_out.xls"); |
フォント スタイルを太字に設定する
を設定して、テキストを太字に設定します。フォントオブジェクトのsetBoldプロパティへ真実.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the output directory. | |
String outputDir = Utils.Get_OutputDirectory(); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Adding a new worksheet to the Excel object | |
int i = workbook.getWorksheets().add(); | |
// Obtaining the reference of the newly added worksheet by passing its sheet index | |
Worksheet worksheet = workbook.getWorksheets().get(i); | |
// Accessing the "A1" cell from the worksheet | |
Cell cell = worksheet.getCells().get("A1"); | |
// Adding some value to the "A1" cell | |
cell.putValue("Hello Aspose!"); | |
// Obtaining the style of the cell | |
Style style = cell.getStyle(); | |
// Setting the font weight to bold | |
style.getFont().setBold(true); | |
// Applying the style to the cell | |
cell.setStyle(style); | |
// Saving the Excel file | |
workbook.save(outputDir + "book1.out.xlsx", SaveFormat.XLSX); |
フォントサイズの設定
を使用してフォント サイズを設定します。フォントオブジェクトのセットサイズ財産。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SetFontSize.class) + "data/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Accessing the added worksheet in the Excel file | |
int sheetIndex = workbook.getWorksheets().add(); | |
Worksheet worksheet = workbook.getWorksheets().get(sheetIndex); | |
Cells cells = worksheet.getCells(); | |
// Adding some value to the "A1" cell | |
Cell cell = cells.get("A1"); | |
cell.setValue("Hello Aspose!"); | |
// Setting the font weight to bold | |
Style style = cell.getStyle(); | |
Font font = style.getFont(); | |
font.setSize(14); | |
cell.setStyle(style); | |
cell.setStyle(style); | |
// Saving the modified Excel file in default format | |
workbook.save(dataDir + "SetFontSize_out.xls"); |
フォントの下線タイプの設定
でテキストに下線を引くフォントオブジェクトのsetUnderline財産。 Aspose.Cells は、さまざまな定義済みフォントの下線タイプをFontUnderlineType列挙。
フォントの下線の種類 | 説明 | ||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
なし | 下線なし | ||||||||||||||||||||||||||||||||||||||||||||||||||
独身 | 一重下線 | ||||||||||||||||||||||||||||||||||||||||||||||||||
ダブル | 二重下線 | ||||||||||||||||||||||||||||||||||||||||||||||||||
会計 | 単一の会計下線 | ||||||||||||||||||||||||||||||||||||||||||||||||||
DOUBLE_ACCOUNTING | 二重会計下線 | ||||||||||||||||||||||||||||||||||||||||||||||||||
ダッシュ | 破線の下線 | ||||||||||||||||||||||||||||||||||||||||||||||||||
ダッシュ_ドット_DOT_HEAVY | 太い一点一点下線 | ||||||||||||||||||||||||||||||||||||||||||||||||||
ダッシュ_ドット_重い | 太い一点鎖線の下線 | ||||||||||||||||||||||||||||||||||||||||||||||||||
DASHED_HEAVY | 太い破線の下線 | ||||||||||||||||||||||||||||||||||||||||||||||||||
DASH_LONG | 長い破線の下線 | ||||||||||||||||||||||||||||||||||||||||||||||||||
ダッシュ_長いです_重い | 太い長い破線の下線 | ||||||||||||||||||||||||||||||||||||||||||||||||||
DOT_DASH | 一点鎖線の下線 | ||||||||||||||||||||||||||||||||||||||||||||||||||
ドット_ドット_ダッシュ | 一点一点下線 | ||||||||||||||||||||||||||||||||||||||||||||||||||
点在 | 点線の下線 | ||||||||||||||||||||||||||||||||||||||||||||||||||
DOTTED_HEAVY | 太い点線の下線 | ||||||||||||||||||||||||||||||||||||||||||||||||||
重い | 太い下線 | ||||||||||||||||||||||||||||||||||||||||||||||||||
波 | 波下線 | ||||||||||||||||||||||||||||||||||||||||||||||||||
WAVY_DOUBLE | 二重波下線 | ||||||||||||||||||||||||||||||||||||||||||||||||||
WAVY_HEAVY | 太波下線 | ||||||||||||||||||||||||||||||||||||||||||||||||||
言葉 |
スペース以外の文字のみに下線を引く | ||||||||||||||||||||||||||||||||||||||||||||||||||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
フォントの色の設定
でフォントの色を設定しますフォントオブジェクトのsetColor財産。から任意の色を選択色列挙し、選択した色をフォントオブジェクトのsetColor.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SetFontColor.class) + "data/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Accessing the added worksheet in the Excel file | |
int sheetIndex = workbook.getWorksheets().add(); | |
Worksheet worksheet = workbook.getWorksheets().get(sheetIndex); | |
Cells cells = worksheet.getCells(); | |
// Adding some value to the "A1" cell | |
Cell cell = cells.get("A1"); | |
cell.setValue("Hello Aspose!"); | |
// Setting the font color to blue | |
Style style = cell.getStyle(); | |
Font font = style.getFont(); | |
font.setColor(Color.getBlue()); | |
cell.setStyle(style); | |
cell.setStyle(style); | |
// Saving the modified Excel file in default format | |
workbook.save(dataDir + "SetFontColor_out.xls"); |
テキストに取り消し線効果を設定する
取り消し線テキストフォントオブジェクトのsetStrikeout財産。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SettingStrikeOutEffect.class) + "data/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Accessing the added worksheet in the Excel file | |
int sheetIndex = workbook.getWorksheets().add(); | |
Worksheet worksheet = workbook.getWorksheets().get(sheetIndex); | |
Cells cells = worksheet.getCells(); | |
// Adding some value to the "A1" cell | |
Cell cell = cells.get("A1"); | |
cell.setValue("Hello Aspose!"); | |
// Setting the strike out effect on the font | |
Style style = cell.getStyle(); | |
Font font = style.getFont(); | |
font.setStrikeout(true); | |
cell.setStyle(style); |
添え字の設定
を使用してテキストを上付きにします。フォントオブジェクトのsetSubscript財産。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SetSubscript.class) + "data/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Accessing the added worksheet in the Excel file | |
int sheetIndex = workbook.getWorksheets().add(); | |
Worksheet worksheet = workbook.getWorksheets().get(sheetIndex); | |
Cells cells = worksheet.getCells(); | |
// Adding some value to the "A1" cell | |
Cell cell = cells.get("A1"); | |
cell.setValue("Hello Aspose!"); | |
// Setting subscript effect | |
Style style = cell.getStyle(); | |
Font font = style.getFont(); | |
font.setSubscript(true); | |
cell.setStyle(style); |
上付き文字の設定
でテキストに上付き文字を適用しますフォントオブジェクトのset上付き文字財産。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SetSubscript.class) + "data/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Accessing the added worksheet in the Excel file | |
int sheetIndex = workbook.getWorksheets().add(); | |
Worksheet worksheet = workbook.getWorksheets().get(sheetIndex); | |
Cells cells = worksheet.getCells(); | |
// Adding some value to the "A1" cell | |
Cell cell = cells.get("A1"); | |
cell.setValue("Hello Aspose!"); | |
// Setting superscript effect | |
Style style = cell.getStyle(); | |
Font font = style.getFont(); | |
font.setSuperscript(true); | |
cell.setStyle(style); |