pub struct VbaProject {
pub project_id: String,
pub modules: Vec<VbaModule>,
pub raw_donor: Vec<u8>,
pub seed_prefix_bytes: Vec<u8>,
pub seed_module_cookie: u16,
pub protection_lines: Option<String>,
}Expand description
A workbook’s VBA project: its modules plus the raw material needed to
patch (not rebuild from scratch) a vbaProject.bin on export.
Fields§
§project_id: StringProject ID GUID, e.g. "{7B4E3A2C-1F5D-4A6B-9C8E-2D3F4A5B6C7D}".
Must stay internally consistent with protection_lines – never
mutated after import/creation, so it always is. If CMG/DPB/GC
protection-state lines are ever made independently settable, they
must correspond to this exact ID or Excel reports the whole project
“unviewable” (a real finding from the POC, not a hypothetical).
modules: Vec<VbaModule>The project’s modules, in no particular order. Names are unique case-insensitively.
raw_donor: Vec<u8>The full original vbaProject.bin bytes this project was imported
from, or (for a project created fresh in this session)
vba_synth::synthetic_raw_donor()’s from-scratch bytes – export’s
patch base. See vba_xlsx.rs.
seed_prefix_bytes: Vec<u8>P-code prefix bytes to donate to the first module ever added to a
project that started with none – kept separate from modules
rather than as a phantom placeholder module, so it never shows up in
list_vba_modules/export. Once a project has at least one real
module, new modules instead borrow prefix bytes from an existing
one, and this field goes unused.
VbaModule::module_cookie to donate to the first module ever added
to a project that started with none – same donation scheme as
seed_prefix_bytes, see there for why.
protection_lines: Option<String>The donor’s original PROJECT stream CMG=/DPB=/GC= lines
(joined with \r\n), reproduced verbatim on export – None for a
project created fresh in this session, which never had any. See
vba_xlsx::build_project_stream for why these must be preserved
rather than dropped.
Implementations§
Source§impl VbaProject
impl VbaProject
Sourcepub fn new_empty() -> Self
pub fn new_empty() -> Self
A brand-new, empty VBA project with no real Excel-authored file
behind it anywhere – raw_donor and seed_prefix_bytes are built
by vba_synth entirely from scratch. See vba_synth’s doc comment
for why that’s now possible.
Sourcepub fn find_module(&self, name: &str) -> Option<&VbaModule>
pub fn find_module(&self, name: &str) -> Option<&VbaModule>
Finds a module by name, matched case-insensitively as VBA does.
Sourcepub fn find_module_mut(&mut self, name: &str) -> Option<&mut VbaModule>
pub fn find_module_mut(&mut self, name: &str) -> Option<&mut VbaModule>
VbaProject::find_module, mutably.
Sourcepub fn module_name_taken(&self, name: &str) -> bool
pub fn module_name_taken(&self, name: &str) -> bool
Whether a module of this name already exists, matched case-insensitively.
Sourcepub fn check_modules(&self) -> Vec<(String, Result<ModuleSyntax, Error>)>
pub fn check_modules(&self) -> Vec<(String, Result<ModuleSyntax, Error>)>
Checks every module, resolving names against the whole project.
This is the check to prefer wherever the project is in hand.
VbaModule::check_syntax sees one module and so has to accept any
name it cannot resolve, since a sibling may declare it; here the
siblings are known, so x = arr(1) with no arr anywhere is
reported the way Excel reports it – Excel compiles a project, not a
file.
Returns one entry per module, in modules order, pairing the
module’s name with its result. A module whose source does not parse
still contributes whatever names it declares to the others, since a
parse failure in one module is not evidence about another.
Sourcepub fn check_modules_partial(
&self,
) -> Vec<(String, Result<ModuleSyntax, Error>)>
pub fn check_modules_partial( &self, ) -> Vec<(String, Result<ModuleSyntax, Error>)>
check_modules for a project that is not
the whole story – one whose procedures may live in a referenced
project this VbaProject does not model.
Modules still resolve against each other; the only thing that
changes is that a name resolving nowhere is accepted rather than
reported, as in check_syntax_partial. Nothing in a workbook
records whether such a reference exists, so this is a caller’s
assertion, not something to infer.
Trait Implementations§
Source§impl Clone for VbaProject
impl Clone for VbaProject
Source§fn clone(&self) -> VbaProject
fn clone(&self) -> VbaProject
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more