-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: proposal for new types addition and optional integration with rust_xlsxwriter
#339
Comments
@tafia please let me know what you think in the next days if you can, at least for the first points, because this coming weekend I would have some time to work on this. If you need more explanation, this is how the use calamine::{RangeDeserializerBuilder, Reader, Xlsx, NumberOrString};
struct ExcelRow {
metric: String,
value: NumberOrString,
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let path = format!("{}/tests/excel.xlsx", env!("CARGO_MANIFEST_DIR"));
let mut excel: Xlsx<_> = open_workbook(path)?;
let range = excel
.worksheet_range("Sheet1")
.ok_or(calamine::Error::Msg("Cannot find Sheet1"))??;
let iter_result =
RangeDeserializerBuilder::with_headers(&COLUMNS).from_range::<_, ExcelRow>(&range)?;
} |
Hey, sorry for the late answer,
|
|
Could you explain a bit more what you mean here. For context I understand the Excel 1900/1904 date differences in general, just not what is meant here. |
|
Calamine now uses hack for converting time 1904 to 1900, and for time 1904 as_time() produces bad results. I think 1) calamine should store start date in DataType (like |
@dimastbk can you please clarify if this issue would be fixed by using |
@tafia if you can please merge PR #389 and #398, then I'm ready to create a PR (building on them) to implement the |
@tafia I hope you're going to answer me soon because I have some time this week to work on this, while next week I'll have to move to other projects, thanks |
I would like to open a discussion to add a few convenience data types with
serde::Deserialize
trait implementations. With these new data types it would become trivial to deserialize Excel cells which normally contain a certain type (for instance a float) but may also contain other values such as strings, errors, etc. This proposal also discusses the optional integration with the stellarrust_xlsxwriter
crate, and the opportunity to use its Excel specificrust_xlsxwriter::ExcelDateTime
type to represent date and/or time instead of the genericchrono::naive::NaiveDate
.I am splitting this proposal into separate sections within a single Feature Request because all points are related:
Rename
DataType::as_f64
intoDataType::as_float
andDataType::as_i64
toDataType::as_int
. This is for consistency withDataType::is_float
/DataType::get_float
andDataType::is_int
/DataType::get_int
. and with the proposed new data types (see point 2). This is not a loss of generality because numerical values in Excel are anyway stored asf64
types, see reference here. This change could be introduced by first addingDataType::as_float
andDataType::as_int
and movingDataType::as_f64
andDataType::as_i64
to undocumented / deprecated state, before final removal.For each
DataType
variant, add a correspondingVariantOrString
type, and implement theDefault
,PartialEq
,Eq
when appropriate for the type (seestd::cmp::Eq
), andserde::Deserialize
traits (plus the optional traitrust_xlsxwriter::IntoExcelData
when the featurerust_xlsxwriter
is enabled, see point 3).So for instance for the
DataType::Float
variant, aFloatOrSTring
type should be introduced as follows. This way, the very common case where an Excel cell can contain either correct floats or anything else could be easily deserialized aslet float_or_string: FloatOrString = result?;
.Add an optional feature
rust_xlsxwriter
, to conveniently integrateCalamine
types with therust_xlsxwriter
crate. With this feature enabled, therust_xlsxwriter::IntoExcelData
would be implemented for mostCalamine
types (including the new ones), therust_xlsxwriter::IntoExcelDateTime
would be implemented forCalamine
types which can be converted to a date type withas_date
, and therust_xlsxwriter::IntoFilterData
trait would be implemented for string and float types (maybe not for integer types because they arei64
).Update the
as_datetime
/as_date
/as_time
methods to returnrust_xlsxwriter::ExcelDateTime
which is a type specifically designed to represent Excel date and/or time, instead of the genericchrono::naive::NaiveDate
. The code would be simplified by relying on theExcelDateTime::parse_from_str
method. This means that thedate
feature would depend on therust_xlsxwriter
feature.@tafia if you agree on this proposal I should be able to implement most of this myself and push PRs for your evaluation.
The text was updated successfully, but these errors were encountered: