Umgang mit Schriftart Einstellungen

Konfigurieren von Schriftarteinstellungen

Aspose.Cells bietet eine Klasse, Workbook die eine Microsoft Excel-Datei darstellt. Die Klasse Workbook enthält eine WorksheetCollection die den Zugriff auf jede Arbeitsmappe in einer Excel-Datei ermöglicht. Eine Arbeitsmappe wird durch die Klasse Worksheet dargestellt. Die Klasse Worksheet bietet eine Cells Sammlung. Jedes Element in der Cells Sammlung stellt ein Objekt der Klasse Cell dar.

Aspose.Cells bietet die Cell Klasse' setStyle Methode, um die Formatierung einer Zelle festzulegen. Außerdem, bietet das Objekt der Klasse Style Eigenschaften zur Konfiguration der Schriftarteinstellungen.

Dieser Artikel zeigt, wie:

Schriftartname festlegen

Wenden Sie einer spezifischen Schriftart für Text in Zellen die Font Objekt’s setName Eigenschaft an.

// 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");

Schriftschnitt auf Fett setzen

Setzen Sie den Text fett, indem Sie das Font Objekt’s setBold Eigenschaft auf true setzen.

// 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);

Schriftgröße festlegen

Legen Sie die Schriftgröße mit der Font Objekt’s setSize Eigenschaft fest.

// 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");

Schriftart-Unterstrich-Typ festlegen

Unterstreichen Sie den Text mit der Font Objekt’s setUnderline Eigenschaft. Aspose.Cells bietet verschiedene vordefinierte Schriftart-Unterstricharten in der FontUnderlineType Aufzählung.

Schriftart-Unterstreichungstypen Beschreibung
NONE Kein Unterstrich
SINGLE Ein einfacher Unterstrich
DOUBLE Doppelter Unterstrich
ACCOUNTING Einzelner Unterstrich für Rechnungswesen
DOUBLE_ACCOUNTING Doppelter Unterstrich für Rechnungswesen
DASH Gestrichelter Unterstrich
DASH_DOT_DOT_HEAVY Dicker Strich-Punkt-Punkt-Unterstrich
DASH_DOT_HEAVY Dicker Strich-Punkt-Unterstrich
DASHED_HEAVY Dicker gestrichelter Unterstrich
DASH_LONG Lang gestrichelter Unterstrich
DASH_LONG_HEAVY Dicker lang gestrichelter Unterstrich
DOT_DASH Strich-Punkt-Unterstrich
DOT_DOT_DASH Strich-Punkt-Punkt-Unterstrich
DOTTED Gepunkteter Unterstrich
DOTTED_HEAVY Dicker Gepunkteter Unterstrich
HEAVY Dicker Unterstrich
WAVE Wellenunterstrich
WAVY_DOUBLE Doppelter Wellenunterstrich
WAVY_HEAVY Starker Wellenunterstrich
WORDS Unterstrichene Non-Space-Zeichen Nur
// 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(SettingFontUnderlineType.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 to be underlined
Style style = cell.getStyle();
Font font = style.getFont();
font.setUnderline(FontUnderlineType.SINGLE);
cell.setStyle(style);
cell.setStyle(style);
// Saving the modified Excel file in default format
workbook.save(dataDir + "SFUnderlineType_out.xls");

Schriftfarbe festlegen

Legen Sie die Schriftfarbe mit der Font-Eigenschaft setColor des Font-Objekts fest. Wählen Sie eine Farbe aus der Color-Aufzählung aus und weisen Sie die ausgewählte Farbe dem Font-Objekt über setColor zu.

// 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");

Effekt Durchgestrichener Text festlegen

Durchstreichen Sie den Text mit der Font-Eigenschaft setStrikeout des Font-Objekts.

// 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);

Tiefgestellte Zahl festlegen

Machen Sie den Text tiefgestellt, indem Sie die Font-Eigenschaft setSubscript des Font-Objekts verwenden.

// 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);

Hochgestellte Zahl festlegen

Wenden Sie den Hochstellen-Effekt auf den Text mit der Font-Eigenschaft setSuperscript des Font-Objekts an.

// 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);

Erweiterte Themen