Hantera teckensnittsinställningar

Konfigurera teckensnittsinställningar

Aspose.Cells tillhandahåller en klass,Arbetsbok som representerar en Microsoft Excel-fil. DeArbetsbok klass innehåller enArbetsbladssamling som ger åtkomst till varje kalkylblad i en Excel-fil. Ett arbetsblad representeras avArbetsbladklass. DeArbetsblad klass ger enCells samling. Varje objekt iCells samlingen representerar ett föremål förCellklass.

Aspose.Cells tillhandahållerCell klass'setStyle metod, som används för att ställa in en cells formatering. Också föremålet förStilclass tillhandahåller egenskaper för att konfigurera teckensnittsinställningar.

Den här artikeln visar hur du:

Ställa in teckensnittsnamn

Använd ett specifikt teckensnitt på text i celler med hjälp avFont föremålAnge namnfast egendom.

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

Ställ in teckensnitt till fet stil

Ställ in text till fetstil genom att ställa inFont föremålsetFet egendom tillSann.

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

Ställa in teckensnittsstorlek

Ställ in teckenstorleken med hjälp avFont föremålsetSizefast egendom.

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

Ställa in typsnitt understruken typ

Stryk under texten medFont föremålsetUnderlinje fast egendom. Aspose.Cells erbjuder olika fördefinierade teckensnittsunderstrykningstyper iFontUnderlineTypeuppräkning.

Typer av understrykning av teckensnitt Beskrivning
INGEN Ingen understrykning
ENDA En enda understrykning
DUBBEL Dubbel understrykning
BOKFÖRING En enda redovisningsunderstrykning
DUBBEL_REKTO Dubbel redovisningsunderstrykning
RUSA Streckad underlinje
RUSA_PUNKT_PUNKT_HEAVY Tjock streck-punkt-punkt understrykning
RUSA_PUNKT_TUNG Tjock streck-punkt understrykning
DASHED_HEAVY Tjock streckad underlinje
DASH_LONG Lång streckad underlinje
RUSA_LÅNG_TUNG Tjock lång streckad underlinje
DOT_DASH Streck-Prick understrykning
PUNKT_PUNKT_RUSA Streck-Prick-Prick understrykning
PRICKAD Prickad underlinje
DOTTED_HEAVY Tjock prickad underlinje
TUNG Tjock understrykning
VINKA Vågunderstrykning
WAVY_DOUBLE Dubbelvåg understrykning
WAVY_HEAVY Heavy Wave Underline
 ORD Understryka endast tecken som inte är mellanslag
// 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");

Ställa in teckensnittsfärg

Ställ in teckensnittsfärgen medFont föremålsetColor fast egendom. Välj valfri färg frånFärg uppräkning och tilldela den valda färgen tillFont föremålsetColor.

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

Ställa in genomstruken effekt på text

Överstruken text medFont föremålsetStrikeoutfast egendom.

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

Ställa in Subscript

Gör text upphöjd genom att användaFont föremålsetSubscriptfast egendom.

// 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älla in Upphöjd

Använd upphöjd text på text medFont föremålsetSuperscriptfast egendom.

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

Förhandsämnen