Skip to content

Commit 8454211

Browse files
tamaroningrajyan
andauthored
Add Format.clone() method (#11)
* use format ctor to clone format objetcts * feat: implement format clone by clone method * remove DeepClone --------- Co-authored-by: Yohta Kimura <[email protected]>
1 parent 439dce8 commit 8454211

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

rust/src/wrapper/format.rs

+9
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,15 @@ impl Format {
192192
self.inner.lock().unwrap()
193193
}
194194

195+
/// Clone a Format object.
196+
#[wasm_bindgen(js_name = "clone")]
197+
pub fn deep_clone(&self) -> Format {
198+
let inner = self.inner.lock().unwrap();
199+
Format {
200+
inner: Arc::new(Mutex::new(inner.clone())),
201+
}
202+
}
203+
195204
/// Set the Format alignment properties.
196205
///
197206
/// This method is used to set the horizontal and vertical data alignment

test/expected/format_clone.xlsx

5.21 KB
Binary file not shown.

test/format.test.ts

+22
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,25 @@ describe("xlsx-wasm test", () => {
204204
expect(actual).matchXlsx(expected);
205205
});
206206
});
207+
208+
describe("xlsx-wasm test", () => {
209+
test("clone format object", async () => {
210+
// Arrange
211+
const workbook = new Workbook();
212+
213+
// Act
214+
const worksheet = workbook.addWorksheet();
215+
const baseFormat = new Format().setBold();
216+
const format1 = baseFormat.clone().setItalic();
217+
const format2 = baseFormat.clone().setFontColor(Color.red());
218+
219+
worksheet.writeStringWithFormat(0, 0, "bold", baseFormat);
220+
worksheet.writeStringWithFormat(0, 1, "bold italic", format1);
221+
worksheet.writeStringWithFormat(0, 2, "bold red", format2);
222+
223+
// Assert
224+
const actual = await readXlsx(workbook.saveToBufferSync());
225+
const expected = await readXlsxFile("./expected/format_clone.xlsx");
226+
expect(actual).matchXlsx(expected);
227+
});
228+
});

0 commit comments

Comments
 (0)