MortalreminderPT / edit-xlsx

A quick and easy-to-use Rust library for Excel file editing.
https://crates.io/crates/edit-xlsx
22 stars 4 forks source link

Can't change font name? #3

Closed Antonio225t closed 6 months ago

Antonio225t commented 6 months ago

Hi, how do I change the font? Is there a way to do so? Thanks in advance. 👍

MortalreminderPT commented 6 months ago

I'm sorry that the current version doesn't allow for switching fonts, but I'll look into adding this in a future version.

MortalreminderPT commented 6 months ago

After I checked, it's not very difficult to change fonts, so I added support for modifying fonts. It has been tested and it works very well for modifying English and Chinese fonts, you can see an example of using it in examples/hello_world. Futhermore, I made an update to this feature in crates.io and you can use it in version 0.3.6.

Antonio225t commented 6 months ago

Thanks for the update. I'm gonna check it out now 👍

Antonio225t commented 6 months ago

Coming back here, it now panics at the Workbook::new() giving me this traceback:

thread 'main' panicked at C:\Users\Windows\.cargo\registry\src\index.crates.io-6f17d22bba15001f\edit-xlsx-0.3.6\src\api\workbook.rs:52:59:
called `Result::unwrap()` on an `Err` value: ZipError(Io(Os { code: 3, kind: NotFound, message: "Impossibile trovare il percorso specificato." }))
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library\std\src\panicking.rs:645
   1: core::panicking::panic_fmt
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library\core\src\panicking.rs:72
   2: core::result::unwrap_failed
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library\core\src\result.rs:1653
   3: enum2$<core::result::Result<edit_xlsx::api::workbook::Workbook,enum2$<edit_xlsx::result::WorkbookError> > >::unwrap<edit_xlsx::api::workbook::Workbook,enum2$<edit_xlsx::result::WorkbookError> >
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112\library\core\src\result.rs:1077
   4: edit_xlsx::api::workbook::Workbook::new
             at C:\Users\Windows\.cargo\registry\src\index.crates.io-6f17d22bba15001f\edit-xlsx-0.3.6\src\api\workbook.rs:52
   5: vimdb::utils::registro::crea_registro
             at .\src\utils\registro.rs:6
   6: vimdb::inserisci_anno
             at .\src\main.rs:67
   7: vimdb::aggiungi_email
             at .\src\main.rs:58
   8: vimdb::main
             at .\src\main.rs:21
   9: core::ops::function::FnOnce::call_once<void (*)(),tuple$<> >
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112\library\core\src\ops\function.rs:250
  10: core::hint::black_box
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112\library\core\src\hint.rs:286
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
error: process didn't exit successfully: `target\debug\vimdb.exe` (exit code: 101)

Looking at:

impl Workbook {
    pub fn new() -> Workbook {
        let mut wb = Self::from_path("resource/new.xlsx").unwrap();
        wb.file_path = String::from("./new.xlsx");
        wb
    }

Seems like the workbook tries to load a resources/new.xlsx but since there is no such files it panics saying that no such file exists. Hope this help fixing this, thanks for your hard work 😃. (Btw, the same code worked fine before the update and I am using Windows 10, you probably needs those informations too.)

EDIT: The Workbook::from_path(path) works fine, only the ::new() doesn't. And changing the font works too. Thank you for your work 👍.

MortalreminderPT commented 6 months ago

First of all, I apologize for the bug and I'll open a new issue for your question and close this issue.