edit_xlsx/api/format/font.rs
1//!
2//! This module contains the [`FormatFont`] struct, which used to set the fill of a format.
3//! [`FormatFont`] is used to handle font-related fields, mainly applied to [`Cell`].
4//! # Examples
5//!
6//! Use [`FormatFont`] to set text's font name, size, and color
7//! ```
8//! use edit_xlsx::{Format, FormatColor, FormatFill, Workbook, WorkSheetCol, Write};
9//! let mut workbook = Workbook::from_path("./examples/xlsx/accounting.xlsx").unwrap();
10//! let worksheet = workbook.get_worksheet_mut_by_name("worksheet").unwrap();
11//! let mut format = Format::default();
12//! format.font.name = "Wide Latin".to_string();
13//! format.font.size = 30.0;
14//! format.font.color = FormatColor::Index(4);
15//! worksheet.write_with_format("A1", "It's so fun", &format).unwrap();
16//! workbook.save_as("./examples/font_write_with_font.xlsx").unwrap();
17//! ```
18
19use crate::{Format, FormatColor};
20use crate::Cell;
21
22///
23/// [`FormatFont`] is used to handle font-related fields, mainly applied to [`Cell`].
24/// # Fields
25/// | field | type | meaning |
26/// | --------- | ----------- | -------------------------------------- |
27/// | `bold` | bool | Whether the font is bold. |
28/// | `italic` | bool | Whether the font is italic. |
29/// | `underline` | bool | Whether the font is underlined. |
30/// | `size` | f64 | Font size in point. |
31/// | `color` | [`FormatColor`] | Font color. |
32/// | `name` | [`String`] | Font name, same as displayed in Excel. |
33///
34#[derive(Clone, Debug, PartialEq)]
35pub struct FormatFont {
36 pub bold: bool,
37 pub italic: bool,
38 pub underline: bool,
39 pub size: f64,
40 pub color: FormatColor,
41 pub name: String,
42}
43
44impl Default for FormatFont {
45 ///
46 /// Method [`FormatFont::default()`] creates a default [`FormatFont`] in Excel,
47 /// with font name *Calibri* and font size 11.0 in point
48 ///
49 /// When using [`Format::default()`], its `font` field will be filled by this method.
50 fn default() -> Self {
51 FormatFont {
52 bold: false,
53 italic: false,
54 underline: false,
55 size: 11.0,
56 color: Default::default(),
57 name: "Calibri".to_string(),
58 }
59 }
60}