tafia / calamine

A pure Rust Excel/OpenDocument SpreadSheets file reader: rust on metal sheets
MIT License
1.61k stars 155 forks source link

special excel name how to get value #335

Closed figo361 closed 1 year ago

figo361 commented 1 year ago

image this kind of name how to get value ,in rust struct name can't have / this symbol。

tafia commented 1 year ago

Can you provide me with an example? (a file and a simple failing test?) I believe it should read the proper encoding.

figo361 commented 1 year ago

e yes ,i found a new way to get this data ,my way is define a struct to accept excel data with its title,so i open the excel and then rename its titile name to get its data ,but i meet a new error image this kind of code is not success ,why This style of writing is not supported

figo361 commented 1 year ago

image this style is support ,but its not graceful

dimastbk commented 1 year ago

What do you want do? If you want to compare cell and your values, you should use:

if Some(&DataType::String(s)) == range.get_value((0, 0)) {
    println!("123")
}

Not if let. In your last example, you copy value of cell (0, 25) to title.

let range = Range::from_sparse(vec![Cell::new((0, 0), String("A".to_string()))]);
let title = "B".to_string();
if let Some(DataType::String(title)) = range.get_value((0, 0)) {
    println!("{}", title);  // A
}
figo361 commented 1 year ago

Thank you, I don't want to copy the value of title. I want to change the value of title because it has a special symbol /

figo361 commented 1 year ago

oh ,sorry i means is header

figo361 commented 1 year ago

thanks ! it work like this .

            if Some(&DataType::String(
                "医疗器械注册人/备案人英文名称".to_string(),
            )) == range.get((0, 25))
            {
                range.set_value(
                    (0, 25),
                    DataType::String("医疗器械注册人_备案人英文名称".to_string()),
                );
            };