-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature #99
- Loading branch information
Showing
33 changed files
with
1,090 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
// | ||
// Copyright 2022-2024, John McNamara, [email protected] | ||
|
||
//! An example of adding macros to an `rust_xlsxwriter` file using a VBA macros | ||
//! file extracted from an existing Excel xlsm file. | ||
//! | ||
//! The `vba_extract` utility (https://crates.io/crates/vba_extract) can be used | ||
//! to extract the `vbaProject.bin` file. | ||
use rust_xlsxwriter::{Workbook, XlsxError}; | ||
|
||
fn main() -> Result<(), XlsxError> { | ||
// Create a new Excel file object. | ||
let mut workbook = Workbook::new(); | ||
|
||
// Add the VBA macro file. | ||
workbook.add_vba_project("examples/vbaProject.bin")?; | ||
|
||
// Add a worksheet and some text. | ||
let worksheet = workbook.add_worksheet(); | ||
|
||
// Widen the first column for clarity. | ||
worksheet.set_column_width(0, 30)?; | ||
|
||
worksheet.write(2, 0, "Run macro say_hello()")?; | ||
|
||
// Save the file to disk. Note the `.xlsm` extension. This is required by | ||
// Excel or it raise a warning. | ||
workbook.save("macros.xlsm")?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
// | ||
// Copyright 2022-2024, John McNamara, [email protected] | ||
|
||
//! The following example demonstrates a simple example of adding a vba project | ||
//! to an xlsm file. | ||
use rust_xlsxwriter::{Workbook, XlsxError}; | ||
|
||
#[allow(unused_variables)] | ||
fn main() -> Result<(), XlsxError> { | ||
let mut workbook = Workbook::new(); | ||
|
||
workbook.add_vba_project("examples/vbaProject.bin")?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
// | ||
// Copyright 2022-2024, John McNamara, [email protected] | ||
|
||
//! The following example demonstrates a simple example of adding a vba project | ||
//! to an xlsm file. | ||
use rust_xlsxwriter::{Workbook, XlsxError}; | ||
|
||
fn main() -> Result<(), XlsxError> { | ||
let mut workbook = Workbook::new(); | ||
|
||
workbook.add_vba_project("examples/vbaProject.bin")?; | ||
|
||
let worksheet = workbook.add_worksheet(); | ||
|
||
worksheet.write_formula(0, 0, "=MyMortgageCalc(200000, 25)")?; | ||
|
||
// Note the `.xlsm` extension. | ||
workbook.save("macros.xlsm")?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
// | ||
// Copyright 2022-2024, John McNamara, [email protected] | ||
|
||
//! The following example demonstrates a simple example of adding a vba project | ||
//! to an xlsm file. | ||
use rust_xlsxwriter::{Workbook, XlsxError}; | ||
|
||
fn main() -> Result<(), XlsxError> { | ||
let mut workbook = Workbook::new(); | ||
|
||
workbook.add_vba_project("examples/vbaProject.bin")?; | ||
workbook.set_vba_name("MyWorkbook")?; | ||
|
||
let worksheet = workbook.add_worksheet(); | ||
worksheet.set_vba_name("MySheet1")?; | ||
|
||
// Note the `.xlsm` extension. | ||
workbook.save("macros.xlsm")?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
// | ||
// Copyright 2022-2024, John McNamara, [email protected] | ||
|
||
//! The following example demonstrates a simple example of adding a vba project | ||
//! to an xlsm file. | ||
use rust_xlsxwriter::{Workbook, XlsxError}; | ||
|
||
#[allow(unused_variables)] | ||
fn main() -> Result<(), XlsxError> { | ||
let mut workbook = Workbook::new(); | ||
|
||
workbook.add_vba_project("examples/vbaProject.bin")?; | ||
|
||
let worksheet = workbook.add_worksheet(); | ||
|
||
// Note the `.xlsm` extension. | ||
workbook.save("macros.xlsm")?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
// | ||
// Copyright 2022-2024, John McNamara, [email protected] | ||
|
||
//! The following example demonstrates a simple example of adding a vba project | ||
//! to an xlsm file. | ||
use rust_xlsxwriter::{Workbook, XlsxError}; | ||
|
||
#[allow(unused_variables)] | ||
fn main() -> Result<(), XlsxError> { | ||
let mut workbook = Workbook::new(); | ||
|
||
workbook.add_vba_project_with_signature( | ||
"examples/vbaProject.bin", | ||
"examples/vbaProjectSignature.bin", | ||
)?; | ||
|
||
let worksheet = workbook.add_worksheet(); | ||
|
||
// Note the `.xlsm` extension. | ||
workbook.save("macros.xlsm")?; | ||
|
||
Ok(()) | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.