2019-11-07 11:45:03 +02:00
|
|
|
use docx_core;
|
2019-09-11 21:28:14 +03:00
|
|
|
use wasm_bindgen::prelude::*;
|
|
|
|
|
|
|
|
|
|
#[wasm_bindgen]
|
|
|
|
|
#[derive(Debug)]
|
2019-11-15 06:33:59 +02:00
|
|
|
pub struct Docx(docx_core::Docx<'static>);
|
2019-09-11 21:28:14 +03:00
|
|
|
|
|
|
|
|
#[wasm_bindgen]
|
2019-11-07 11:45:03 +02:00
|
|
|
#[allow(non_snake_case)]
|
|
|
|
|
pub fn createDocx() -> Docx {
|
|
|
|
|
Docx(docx_core::Docx::new())
|
2019-09-11 21:28:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[wasm_bindgen]
|
2019-11-07 11:45:03 +02:00
|
|
|
impl Docx {
|
|
|
|
|
pub fn add_paragraph(mut self) -> Self {
|
2019-11-13 09:51:58 +02:00
|
|
|
self.0 = self.0.add_paragraph(
|
|
|
|
|
docx_core::Paragraph::new().add_run(docx_core::Run::new().add_text("Hello")),
|
|
|
|
|
);
|
2019-11-07 11:45:03 +02:00
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-11 11:34:55 +02:00
|
|
|
pub fn build(&self) -> Result<Vec<u8>, JsValue> {
|
2019-11-07 11:45:03 +02:00
|
|
|
let buf = Vec::new();
|
|
|
|
|
let mut cur = std::io::Cursor::new(buf);
|
2019-11-11 11:34:55 +02:00
|
|
|
let res = self.0.build().pack(&mut cur);
|
|
|
|
|
if res.is_err() {
|
|
|
|
|
return Err(format!("{:?}", res).into());
|
|
|
|
|
}
|
|
|
|
|
Ok(cur.into_inner())
|
2019-09-11 21:28:14 +03:00
|
|
|
}
|
|
|
|
|
|
2019-11-07 11:45:03 +02:00
|
|
|
pub fn test(&self, t: docx_core::StyleType) {
|
|
|
|
|
()
|
2019-09-11 21:28:14 +03:00
|
|
|
}
|
|
|
|
|
}
|