Skip to content
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

Non-ASCII path xlsx file creation failed (Windows) #31

Open
lll9p opened this issue Jun 8, 2022 · 2 comments
Open

Non-ASCII path xlsx file creation failed (Windows) #31

lll9p opened this issue Jun 8, 2022 · 2 comments

Comments

@lll9p
Copy link

lll9p commented Jun 8, 2022

rust edition: 2021
OS: Windows 11(Language: Simplified Chinese)
xlsxwriter = { version = "^0.3" }

minimal reproducible project.zip

codes and erros show as blow,how can I fix this?

Update:
I temporarily bypassed this issue, jut use env::temp_dir to create a temp file, then move tmpfile to target xlsx.

main.rs:

use std::path;
use xlsxwriter;
fn main() {
    let mut p = path::PathBuf::from("中文");
    println!("Test Dir exists: {:?}", &p.exists());
    p.push("测试.xlsx");
    println!("Test File exists: {:?}", &p.exists());
    let out = p.to_str().unwrap();
    let workbook = xlsxwriter::Workbook::new(&out);
    let mut sheet = workbook.add_worksheet(None).expect("Cannot add sheet.");
    // write some data
    sheet
        .write_string(0, 0, "id", None)
        .expect("Cannot write header to sheet");
    workbook.close().expect("Cannot close workbook");
}

Backtrace info

PS>cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.05s
     Running `target\debug\x.exe`
[ERROR] workbook_close(): Error creating '涓枃\娴嬭瘯.xlsx'. System error = No such file or directory
thread 'main' panicked at 'Cannot close workbook: XlsxError { error: 2 }', src\main.rs:15:22
stack backtrace:
   0:     0x7ff69f607dd0 - std::backtrace_rs::backtrace::dbghelp::trace::h97ee1f5cd8c99222
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e\/library\std\src\..\..\backtrace\src\backtrace/dbghelp.rs:98:5
   1:     0x7ff69f607dd0 - std::backtrace_rs::backtrace::trace_unsynchronized::hca9514563d535d79
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e\/library\std\src\..\..\backtrace\src\backtrace/mod.rs:66:5
   2:     0x7ff69f607dd0 - std::sys_common::backtrace::_print_fmt::h5091a9ac0e137374
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e\/library\std\src\sys_common/backtrace.rs:66:5
   3:     0x7ff69f607dd0 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h595f8b1acf763f32
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e\/library\std\src\sys_common/backtrace.rs:45:22
   4:     0x7ff69f65d5ca - core::fmt::write::h5d420c3939530848
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e\/library\core\src\fmt/mod.rs:1194:17
   5:     0x7ff69f5fa133 - std::io::Write::write_fmt::hea00669dfe5d94db
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e\/library\std\src\io/mod.rs:1655:15
   6:     0x7ff69f60b019 - std::sys_common::backtrace::_print::hd09887ca85ce7833
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e\/library\std\src\sys_common/backtrace.rs:48:5
   7:     0x7ff69f60b019 - std::sys_common::backtrace::print::h597452910002c5b1
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e\/library\std\src\sys_common/backtrace.rs:35:9
   8:     0x7ff69f60b019 - std::panicking::default_hook::{{closure}}::h7b626b282e7ce79b
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e\/library\std\src/panicking.rs:295:22
   9:     0x7ff69f60ac9d - std::panicking::default_hook::ha46aeb549e508cbe
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e\/library\std\src/panicking.rs:314:9
  10:     0x7ff69f60b737 - std::panicking::rust_panic_with_hook::h7db84b8bdf224ccb
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e\/library\std\src/panicking.rs:698:17
  11:     0x7ff69f60b635 - std::panicking::begin_panic_handler::{{closure}}::hfd4a1776387728e4
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e\/library\std\src/panicking.rs:588:13
  12:     0x7ff69f6087c7 - std::sys_common::backtrace::__rust_end_short_backtrace::hcad19b897b28265c
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e\/library\std\src\sys_common/backtrace.rs:138:18
  13:     0x7ff69f60b369 - rust_begin_unwind
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e\/library\std\src/panicking.rs:584:5
  14:     0x7ff69f65a045 - core::panicking::panic_fmt::h43a1cc0716104479
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e\/library\core\src/panicking.rs:143:14
  15:     0x7ff69f65a3a3 - core::result::unwrap_failed::h0e3ebc6b7d5f7a9a
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e\/library\core\src/result.rs:1785:5
  16:     0x7ff69f5925f0 - core::result::Result<T,E>::expect::hc133fe9960b20c0a
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e\library\core\src/result.rs:1035:23
  17:     0x7ff69f593389 - x::main::hcb4c0a9f04bf47ad
                               at C:\Users\user\Desktop\x\src\main.rs:15:5
  18:     0x7ff69f592aab - core::ops::function::FnOnce::call_once::hc7ec2afe117adbf6
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e\library\core\src\ops/function.rs:227:5
  19:     0x7ff69f5926fe - std::sys_common::backtrace::__rust_begin_short_backtrace::h507b7365f1a7fc70
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e\library\std\src\sys_common/backtrace.rs:122:18
  20:     0x7ff69f592a11 - std::rt::lang_start::{{closure}}::hb0c635ea1381f500
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e\library\std\src/rt.rs:145:18
  21:     0x7ff69f5e9e13 - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::hda60aeee14444e1e
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e\library\core\src\ops/function.rs:259:13
  22:     0x7ff69f5e9e13 - std::panicking::try::do_call::h2c011b39f85b8f5d
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e\/library\std\src/panicking.rs:492:40
  23:     0x7ff69f5e9e13 - std::panicking::try::h2740f97f45fefbef
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e\/library\std\src/panicking.rs:456:19
  24:     0x7ff69f5e9e13 - std::panic::catch_unwind::h5884b43bb842d87d
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e\/library\std\src/panic.rs:137:14
  25:     0x7ff69f5e9e13 - std::rt::lang_start_internal::{{closure}}::hebb63b2ddf45a83a
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e\/library\std\src/rt.rs:128:48
  26:     0x7ff69f5e9e13 - std::panicking::try::do_call::h21c57b09ab3e22e4
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e\/library\std\src/panicking.rs:492:40
  27:     0x7ff69f5e9e13 - std::panicking::try::h0d1c5e6731f45c72
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e\/library\std\src/panicking.rs:456:19
  28:     0x7ff69f5e9e13 - std::panic::catch_unwind::hc36dd7576657d56e
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e\/library\std\src/panic.rs:137:14
  29:     0x7ff69f5e9e13 - std::rt::lang_start_internal::h33676380eacb58f6
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e\/library\std\src/rt.rs:128:20
  30:     0x7ff69f5929df - std::rt::lang_start::hef7724c030cba052
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e\library\std\src/rt.rs:144:17
  31:     0x7ff69f59340c - main
  32:     0x7ff69f5913ae - __tmainCRTStartup
                               at C:\M\mingw-w64-crt-git\src\crt-x86_64-w64-mingw32\C:/M/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt\crtexe.c:321:15
  33:     0x7ff69f5914e6 - mainCRTStartup
                               at C:\M\mingw-w64-crt-git\src\crt-x86_64-w64-mingw32\C:/M/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt\crtexe.c:202:9
  34:     0x7ff8e8db54e0 - <unknown>
  35:     0x7ff8ead6485b - <unknown>
error: process didn't exit successfully: `target\debug\x.exe` (exit code: 101)
@lll9p
Copy link
Author

lll9p commented Nov 3, 2022

I switched to jmcnamara/rust_xlsxwriter, problem fixed.

@jmcnamara
Copy link

@lll9p What happens if you use the string directly, without a PathBuf:

    let workbook = xlsxwriter::Workbook::new("中文/测试.xlsx");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants