5 releases
0.1.4 | Oct 23, 2024 |
---|---|
0.1.3 | Oct 23, 2024 |
0.1.2 | Oct 23, 2024 |
0.1.1 | Oct 22, 2024 |
0.1.0 | Oct 22, 2024 |
#649 in Procedural macros
71 downloads per month
13KB
217 lines
Cargo.toml 引入
io-excel = "0.1.4"
serde = { version = "1.0", features = ["derive"] }
calamine = "0.26.1"
rust_xlsxwriter = "0.79.0"
Code demo
Read Excel For Vec
Record::read_excel("中文名称.xlsx", "Sheet1"),分别为 file_path 和 sheet name
use io_excel::IOExcel;
#[derive(IOExcel, Debug)]
pub struct Record {
#[column(name = "省份")]
pub province: String,
#[column(name = "城市")]
pub city: String,
}
fn main() {
let record_list = Record::read_excel("中文名称.xlsx", "Sheet1").unwrap();
for record in &record_list {
eprintln!("{:#?}", record);
}
}
输出结果
Record {
province: "湖北",
city: "武汉",
}
Record {
province: "湖北",
city: "孝感",
}
Write Excel With Vec
Record::write_excel("中文名称.xlsx", "Sheet1", record_list).unwrap();分别为 file_path 和 sheet name and record_list
use io_excel::IOExcel;
#[derive(IOExcel, Debug)]
pub struct Record {
#[column(name = "省份")]
pub province: String,
#[column(name = "城市")]
pub city: String,
}
fn main() {
let record_list = Record::read_excel("中文名称.xlsx", "Sheet1").unwrap();
Record::write_excel("中文名称2.xlsx", "第二个中文名称", &record_list).unwrap();
}
Write Excel Which Some Column Is None
use io_excel::IOExcel;
#[derive(IOExcel, Debug)]
pub struct Record {
#[column(name = "省份")]
pub province: String,
#[column(name = "城市")]
pub city: Option<String>,
#[column(name = "版本号")]
pub name: u32,
}
fn main() {
let record_list = Record::read_excel("中文名称.xlsx", "Sheet1").unwrap();
for record in &record_list {
eprintln!("{:#?}", record);
}
Record::write_excel("中文名称2.xlsx", "第二个中文名称", &record_list).unwrap();
}
Dependencies
~13MB
~267K SLoC