Closed Chronophylos closed 1 year ago
Good suggestion. I'll look into it.
I thought about this for a while and I'd prefer to keep new()
as constructor from simple strings since that will work for most people, most of the time, and it simplifies the documentation.
On the other hand Path is better for the times when a simple string path doesn't work and in particular for folks on Windows who can encounter different hurdles with back/forward slashes and network paths.
So as a compromise I've added a new_from_path()
constructor. I've pushed this to main and it works as follows:
use rust_xlsxwriter::{Workbook, XlsxError};
fn main() -> Result<(), XlsxError> {
let path = std::path::Path::new("workbook.xlsx");
let mut workbook = Workbook::new_from_path(&path);
_ = workbook.add_worksheet();
workbook.close()?;
Ok(())
}
Try it out and let me know what you think.
I'm also going to try to add a new_from_file()
constructor for File type instances. However, that is trickier from a lifetime/ownership point of view.
This feature is now in rust_xlsxwriter version 0.8.0: https://rustxlsxwriter.github.io/changelog.html
Thanks for the suggestion. Closing.
Feature Request
Workbook::new
should accept&Path
orPathBuf
instead of&str
.