-
-
Notifications
You must be signed in to change notification settings - Fork 20
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
Help wanted: create a Wasm example/tutorial using rust_xlsxwriter #38
Comments
On Fri, 12 May 2023 at 10:21, 苯苯 ***@***.***> wrote:
@jmcnamara I am a novice in rust, can I try to do this work?
Sure. Some volunteer is better than no volunteer. :-)
|
@jmcnamara Any plans? For example
I think we or maybe need some planning ? |
I think the best approach would be to create a separate GitHub project and get some examples working with Javascript. Then, once it it working, and we get some user testing/feedback, I will add a chapter in the |
ok |
Hey, was working on a rust lib with python and wasm bindings and noticed this issue. In my case, I couldn't get Could the feature flag be added for chrono? |
It could. I could hide all the date/time types behind This would give the user some access to date/time handling (which is important in Excel) but also chrono if they wanted it. This would also remove, or at least make an option of, a dependency which would be good. Note, this part of the request is similar to #6. |
Could the feature flag be added for chrono? @Ashci42 I have made |
I don't think it is currently possible to run Calling I also think that packager::assemble_file will probably panic, as it calls |
Thanks for taking a look at this.
Excel has metadata with a creation and modification data (which are the same for a new file). It is possible to specify a datetime so that use rust_xlsxwriter::{DocProperties, ExcelDateTime, Workbook, XlsxError};
fn main() -> Result<(), XlsxError> {
let mut workbook = Workbook::new();
// Create a file creation date for the file.
let date = ExcelDateTime::from_ymd(2023, 1, 1)?;
// Add it to the document metadata.
let properties = DocProperties::new().set_creation_datetime(&date);
workbook.set_properties(&properties);
let worksheet = workbook.add_worksheet();
worksheet.write_string(0, 0, "Hello")?;
workbook.save("properties.xlsx")?;
Ok(())
} See: https://rustxlsxwriter.github.io/workbook/checksum.html#checksum-of-a-saved-file However, I don't know if it is still incompatible with Wasm if the
That was only added in recently in v0.44.0. You could test with version v0.43.0 instead. If required I could put it behind a |
Actually I'm wrong. It is called at the creation of |
I have forked the repo (here) changing those two things (making
Yeah, that makes sense. Although maybe a |
Thanks for that. For the
That is still the main help I need here. It doesn't have to be full tutorial, like I asked for above. Even a hello world example with some instructions would be useful to debug and test issues like this. |
I'll take a look at this. In the meanwhile, it could be important to think about Wasm in non-javascript environments. I'm not an expert on this, but I know Wasm was "designed to be capable of being executed without a Javascript VM present". Also, if we look at chrono's |
Yes, you are probably right. I had a look at the |
I have made a minimal example of a rust_xlsxwriter program that compiles to WASM: It is a bit big, but there's not much I can do, since most files are just there to replace std::fs with browser-specific/nodejs-specific/deno-specific code that does the same thing. I also found a bug in the current branch. You are taking the result of Date.now() as if it meant seconds since UNIX_EPOCH, while it actually represents the number of milliseconds since UNIX_EPOCH (so you just have to divide it by 1,000 and it would be fixed) |
That is really great. Thanks! I was able to get the browser example working with minimal fuss. That and the other environments make it perfect for testing so that is just what I needed.
I fixed that on the |
I was able to get all of the targets (Browser, Node.js, Deno and WASI) working after installing a few dependencies. So that is really useful for testing.
It doesn't seem too bad. I have a few minor suggestions. I'll make them directly on your repo a bit later. Thanks once more. |
@Clipi-12 I added support in I've pushed it to a different branch ( $ wasmtime --dir=. pkg/wasi/rust_xlsx_wasm_example.wasm
Error: failed to run main module `pkg/wasi/rust_xlsx_wasm_example.wasm`
Caused by:
0: failed to instantiate "pkg/wasi/rust_xlsx_wasm_example.wasm"
1: unknown import: `__wbindgen_placeholder__::__wbindgen_throw` has not been defined
|
EDIT: never mind, I understand what you meant with the last commit. It is indeed very useful! I'll probably remove some code in the example thanks to that |
@jmcnamara I modified a private copy of the wasm2 branch and got rid of the error by simply avoiding to import wasm-bindgen in wasi. Honestly I think the best option is to rename the Well, everything but Also, an additional benefit is that if we rename the feature flag to |
…st_xlsxwriter#38 (comment) . This shouldn't compile until the following changes are pushed jmcnamara/rust_xlsxwriter#38 (comment)
That is good. I meant to attach the updated example but somehow failed to do it, but it looks like you figured it out anyway. Apologies for slow responses, I have some other things going on at the moment. |
I got a chance to look at this again and your recent changes look good. I've cleaned things up on my side and merged the changes onto main. I'll push the changes to crates.io in the next few days if everything is okay on your side and mine.
I'm going to stick with
Good point. I made that change.
I don't really get this. Could you explain a bit more. Or submit a PR against main with the suggested changes. |
I was about to submit a PR when I noticed that it actually doesn't matter. I thought that we could ignore the However, the panic no longer occurs, and even if it did, it's honestly more safe to just do the check, in case it would ever get solved (which it already is). |
Thank for that @Clipi-12 I've pushed the changes to crates.io in v0.47.0. I've mentioned your repo in the release notes: https://rustxlsxwriter.github.io/changelog.html#0470---2023-09-02 Thanks once more for the help. There will probably be some improvements to be added over time (in both repos) but this is a good start. I'm going to close this feature request since I think it completes the "Help needed" request. |
Help wanted
It would be great if someone could create a Wasm example/tutorial using
rust_xlsxwriter
.Ideally I could add this as a section in or link from the Working with the rust_xlsxwriter library user guide.
An example like one in the SheetJS tutorial would be good but don't copy it exactly.
It would be good to use the
write_row_matrix()
orwrite_column_matrix()
methods that are currently on main (#16) and which will be in v0.39.0.It would also be nice to use whatever is the current Rust/Wasm best practices.
The text was updated successfully, but these errors were encountered: