Rust是一款新型的、主打安全的语言。但是,百度上搜索读取excel的库还很难找。不过,我找到了一款,推荐给大家:ooxml, 当前版本0.2.7.
这是依赖:
[dependencies]
ooxml = "0.2.7"
itertools = "0.11.0"
具体代码如下:
use ooxml::document::SpreadsheetDocument;
fn main() {
let filename = "F:/programWorks/Java/demo4cupdata/demoB.xlsx";
let xlsx =
SpreadsheetDocument::open(filename).unwrap();
let workbook = xlsx.get_workbook();
// println!("我能自己输出点什么吗?{:?}", xlsx);
let sheet_names = workbook.worksheet_names();
println!("包含:");
for name in sheet_names {
println!("{}", name);
}
for (sheet_idx, sheet) in workbook.worksheets().iter().enumerate() {
println!("worksheet {}", sheet_idx);
println!("worksheet dimension: {:?}", sheet.dimenstion());
println!("---------DATA---------");
for rows in sheet.rows() {
// get cell values
let cols: Vec<_> = rows
.into_iter()
.map(|cell| cell.value().unwrap_or_default())
.collect();
println!("{}", itertools::join(&cols, ","));
for cell in cols {
println!("{}", cell);
}
}
}
}
亲测可用。
————————————————
原文链接:https://blog.csdn.net/xplidelphi/article/details/132476334
如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!
txttool.com 说一段 esp56物联 查询128 IP查询