From 9efa4e2aae6fb29a7477dfec884e4498bd9c2f39 Mon Sep 17 00:00:00 2001
From: Hugues Malphettes <hmalphettes@gmail.com>
Date: Tue, 21 Jan 2014 06:05:00 +0700
Subject: [PATCH] Update the range of the sheet when creating a cell for the
 content of its comments

---
 bits/70_xlsx.js | 8 ++++++++
 xlsx.js         | 8 ++++++++
 2 files changed, 16 insertions(+)

diff --git a/bits/70_xlsx.js b/bits/70_xlsx.js
index fdbefca..21032b5 100644
--- a/bits/70_xlsx.js
+++ b/bits/70_xlsx.js
@@ -535,6 +535,14 @@ function insertCommentsIntoSheet(sheetName, sheet, comments) {
 		if (!cell) {
 			cell = {};
 			sheet[comment.ref] = cell;
+			var range = decode_range(sheet["!ref"]);
+			var thisCell = decode_cell(comment.ref);
+			if(range.s.r > thisCell.r) range.s.r = thisCell.r;
+			if(range.e.r < thisCell.r) range.e.r = thisCell.r;
+			if(range.s.c > thisCell.c) range.s.c = thisCell.c;
+			if(range.e.c < thisCell.c) range.e.c = thisCell.c;
+			var encoded = encode_range(range);
+			if (encoded !== sheet["!ref"]) sheet["!ref"] = encoded;
 		} 
 
 		if (!cell.c) {
diff --git a/xlsx.js b/xlsx.js
index d346cf1..10e0979 100644
--- a/xlsx.js
+++ b/xlsx.js
@@ -1114,6 +1114,14 @@ function insertCommentsIntoSheet(sheetName, sheet, comments) {
 		if (!cell) {
 			cell = {};
 			sheet[comment.ref] = cell;
+			var range = decode_range(sheet["!ref"]);
+			var thisCell = decode_cell(comment.ref);
+			if(range.s.r > thisCell.r) range.s.r = thisCell.r;
+			if(range.e.r < thisCell.r) range.e.r = thisCell.r;
+			if(range.s.c > thisCell.c) range.s.c = thisCell.c;
+			if(range.e.c < thisCell.c) range.e.c = thisCell.c;
+			var encoded = encode_range(range);
+			if (encoded !== sheet["!ref"]) sheet["!ref"] = encoded;
 		} 
 
 		if (!cell.c) {