From f7835d67b21ca269650dcb2d3250ee1c7d3f5b5b Mon Sep 17 00:00:00 2001
From: Robin Hu <rhu@novus.com>
Date: Mon, 2 Nov 2020 16:45:11 -0500
Subject: [PATCH] Add support for outline configuration

- "Summary rows below detail"
- "Summary columns to right of detail"
---
 README.md        | 4 ++++
 bits/67_wsxml.js | 7 +++++++
 2 files changed, 11 insertions(+)

diff --git a/README.md b/README.md
index dd26b86..4047ad5 100644
--- a/README.md
+++ b/README.md
@@ -1093,6 +1093,10 @@ In addition to the base sheet keys, worksheets also add:
   will write all cells in the merge range if they exist, so be sure that only
   the first cell (upper-left) in the range is set.
 
+- `ws['!outline']`: configure how outlines should behave.
+  Example: `{above: true}` - equivalent of unchecking the Excel option "Summary rows below detail".
+  `{left: true}` - equivalent of unchecking the Excel option "Summary option to the right of detail."
+
 - `ws['!protect']`: object of write sheet protection properties.  The `password`
   key specifies the password for formats that support password-protected sheets
   (XLSX/XLSB/XLS).  The writer uses the XOR obfuscation method.  The following
diff --git a/bits/67_wsxml.js b/bits/67_wsxml.js
index 91452ca..f342a4e 100644
--- a/bits/67_wsxml.js
+++ b/bits/67_wsxml.js
@@ -114,6 +114,13 @@ function write_ws_xml_sheetpr(ws, wb, idx, opts, o) {
 		props.codeName = escapexml(cname);
 	}
 
+	if(ws && ws["!outline"]) {
+		var outlineprops = {summaryBelow:1, summaryRight:1};
+		if(ws["!outline"].above) outlineprops.summaryBelow = 0;
+		if(ws["!outline"].left) outlineprops.summaryRight = 0;
+		payload = (payload||"") + writextag('outlinePr', null, outlineprops);
+	}
+
 	if(!needed && !payload) return;
 	o[o.length] = (writextag('sheetPr', payload, props));
 }