edit_xlsx/api/cell.rs
1use crate::api::cell::formula::Formula;
2use crate::api::cell::rich_text::RichText;
3use crate::api::cell::values::{CellDisplay, CellType, CellValue};
4use crate::{Format, FormatColor, FormatFont};
5
6pub mod formula;
7pub mod location;
8pub mod values;
9pub mod rich_text;
10
11#[derive(Clone, Debug, Default)]
12pub struct Cell<T: CellDisplay + CellValue> {
13 pub text: Option<T>,
14 pub rich_text: Option<RichText>,
15 pub format: Option<Format>,
16 pub hyperlink: Option<String>,
17 pub(crate) formula: Option<Formula>,
18 pub(crate) cell_type: Option<CellType>,
19 pub(crate) style: Option<u32>,
20}
21
22// use ansi_term::{ANSIString, Style, Colour};
23// impl<T: CellDisplay + CellValue> Cell<T> {
24//
25// pub fn ansi_strings(&self) -> Vec::<ANSIString> {
26// fn to_ansi_style(format_font: &FormatFont) -> Style {
27// let mut style = Style::new();
28// style.is_bold = format_font.bold;
29// style.is_italic = format_font.italic;
30// style.is_underline = format_font.underline;
31// match format_font.color {
32// FormatColor::RGB(r, g, b) => {
33// style.foreground = Some(Colour::RGB(r, g, b));
34// }
35// _ => {}
36// }
37// style
38// }
39//
40// let default_style = if let Some(format) = &self.format {
41// let mut default_style = to_ansi_style(&format.font);
42// match format.fill.fg_color {
43// FormatColor::RGB(r, g, b) => {
44// default_style.background = Some(Colour::RGB(r, g, b));
45// }
46// _ => {}
47// }
48// default_style
49// } else {
50// Style::new()
51// };
52// let mut ansi_string_vec = Vec::new();
53// let text = if let Some(text) = &self.text {
54// text.to_display()
55// } else { "".to_string() };
56// if let Some(rich_text) = &self.rich_text {
57// rich_text.words.iter().for_each(|w| {
58// let mut style = default_style.clone();
59// if let Some(format_font) = &w.font {
60// style = to_ansi_style(format_font);
61// }
62// ansi_string_vec.push(
63// style.paint(w.text.clone())
64// );
65// });
66// } else {
67// ansi_string_vec.push(
68// default_style.paint(text)
69// );
70// };
71// ansi_string_vec
72// }
73// }