jmcnamara / excel-writer-xlsx

Perl module to create Excel XLSX files.
https://metacpan.org/pod/distribution/Excel-Writer-XLSX/lib/Excel/Writer/XLSX.pm
Other
100 stars 51 forks source link

Support for 'veryHidden' sheets not supported #228

Closed srefsum closed 11 months ago

srefsum commented 5 years ago

Excel supports two modes of hidden sheets:

veryhidden is only available from the vba editor.

It can be implemented this way:

diff --git a/lib/Excel/Writer/XLSX/Workbook.pm b/lib/Excel/Writer/XLSX/Workbook.pm
index a9a488d..ae45dc6 100644
--- a/lib/Excel/Writer/XLSX/Workbook.pm
+++ b/lib/Excel/Writer/XLSX/Workbook.pm
@@ -2599,7 +2599,8 @@ sub _write_sheet {
         'sheetId' => $sheet_id,
     );

-    push @attributes, ( 'state' => 'hidden' ) if $hidden;
+    push @attributes, ( 'state' => 'hidden' )     if ($hidden == 1);
+    push @attributes, ( 'state' => 'veryHidden' ) if ($hidden == 2);
     push @attributes, ( 'r:id' => $r_id );

diff --git a/lib/Excel/Writer/XLSX/Worksheet.pm b/lib/Excel/Writer/XLSX/Worksheet.pm
index fa16dd4..6094218 100644
--- a/lib/Excel/Writer/XLSX/Worksheet.pm
+++ b/lib/Excel/Writer/XLSX/Worksheet.pm
@@ -454,6 +454,25 @@ sub hide {
     ${ $self->{_firstsheet} }  = 0;
 }

+###############################################################################
+#
+# hide_very()
+#
+# Hide this worksheet.
+# Only possible to enable using vba attribute editor
+#
+sub hide_very {
+
+    my $self = shift;
+
+    $self->{_hidden} = 2;
+
+    # A hidden worksheet shouldn't be active or selected.
+    $self->{_selected} = 0;
+    ${ $self->{_activesheet} } = 0;
+    ${ $self->{_firstsheet} }  = 0;
+}
+
srefsum commented 5 years ago

I failed to implement a test case that actually works; but for my installation of office the mentioned code gives the required result.

jmcnamara commented 5 years ago

Seems like a reasonable suggestion. I'll look into it.

jmcnamara commented 12 months ago

I've added a fix for this to main via the $worksheet->very_hidden() method.