Yazı Tipi Ayarları İle İlgilenme

Font Ayarlarını Yapılandırma

Aspose.Cells, bir Microsoft Excel dosyasını temsil eden Workbook sınıfını sağlar. Workbook sınıfı, bir Excel dosyasındaki her çalışma sayfasına erişime izin veren WorksheetCollection içerir. Bir çalışma sayfası, Worksheet sınıfı tarafından temsil edilir. Worksheet sınıfı, bir Cells koleksiyonu sağlar. Cells koleksiyonundaki her öğe, Cell sınıfının bir nesnesini temsil eder.

Aspose.Cells, Cell sınıfının setStyle metodunu sağlar. Bu metod, bir hücrenin biçimlendirmesini ayarlamak için kullanılır. Ayrıca Style sınıfının nesnesi, yazı tipi ayarlarını yapılandırmak için özellikler sağlar.

Bu makalede, şunları gösterecektir:

Yazı Tipi Adını Ayarlama

Hücrelerdeki metne belirli bir yazı tipi uygulamak için Font nesnesinin setName özelliğini kullanın.

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

Yazı Tipi Stilini Kalın Yapma

Font nesnesinin setBold özelliğini true olarak ayarlayarak metni kalın yapın.

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

Yazı Tipi Boyutunu Ayarlama

Font nesnesinin setSize özelliğini kullanarak yazı tipi boyutunu ayarlayın.

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

Yazı Tipi Altı Çizgi Türünü Ayarlama

Font nesnesinin setUnderline özelliği ile metni altı çizili yapın. Aspose.Cells, FontUnderlineType numaralandırmasında çeşitli önceden tanımlanmış yazı tipi alt çizgi türleri sunar.

Yazı Tipi Altı Çizgi Tipleri Açıklama
NONE Alt çizgi yok
SINGLE Tek bir alt çizgi
DOUBLE Çift alt çizgi
ACCOUNTING Tek bir muhasebe alt çizgisi
DOUBLE_ACCOUNTING Çift muhasebe alt çizgisi
DASH Kesikli Alt Çizgi
DASH_DOT_DOT_HEAVY Kalın Kesikli Nokta-Nokta Alt Çizgi
DASH_DOT_HEAVY Kesikli Nokta-Nokta Alt Çizgi
DASHED_HEAVY Kalın Kesikli Alt Çizgi
DASH_LONG Uzun Kesik Alt Çizgi
DASH_LONG_HEAVY Kalın Uzun Kesik Alt Çizgi
DOT_DASH Çizgi-Nokta Alt Çizgi
DOT_DOT_DASH Çizgi-Nokta-Nokta Alt Çizgi
DOTTED Noktalı Alt Çizgi
DOTTED_HEAVY Kalın Noktalı Alt Çizgi
HEAVY Kalın Alt Çizgi
WAVE Dalgalı Alt Çizgi
WAVY_DOUBLE Çift Dalgalı Alt Çizgi
WAVY_HEAVY Kalın Dalgalı Alt Çizgi
WORDS Sadece Boşluk Olmayan Karakterlere Alt Çizgi Uygula
// 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");

Yazı Tipi Rengini Ayarlama

Font nesnesinin setColor özelliği ile yazı tipi rengini ayarlayın. Color enum’den herhangi bir rengi seçin ve seçilen rengi Font nesnesinin setColor özelliğine atayın.

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

Metin Üzerine Çizgi Çekme Efektini Ayarlama

Font nesnesinin setStrikeout özelliği ile metin üzerine çizgi çekme efektini ayarlayın.

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

Alt Skript Ayarlama

Font nesnesinin setSubscript özelliği ile metni alt skript yapın.

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

Üst Skript Ayarlama

Font nesnesinin setSuperscript özelliği ile metni üst skript yapın.

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

Gelişmiş Konular