private void UpdateInstructions()
        {
            ISheet instructionsSheet = XlsWorkbook.GetSheet(InstructionsSheet);

            if (instructionsSheet != null)
            {
                RecalculateSheet(instructionsSheet);
            }
        }
        /// <summary>
        /// Writes the Excel worksheet for this COBie sheet
        /// </summary>
        /// <param name="sheet"></param>
        private void WriteSheet(ICOBieSheet <COBieRow> sheet)
        {
            ISheet excelSheet = XlsWorkbook.GetSheet(sheet.SheetName) ?? XlsWorkbook.CreateSheet(sheet.SheetName);

            var datasetHeaders = sheet.Columns.Values.ToList();
            var sheetHeaders   = GetTargetHeaders(excelSheet);

            ValidateHeaders(datasetHeaders, sheetHeaders, sheet.SheetName);


            // Enumerate rows
            for (int r = 0; r < sheet.RowCount; r++)
            {
                if (r >= UInt16.MaxValue)
                {
                    // TODO: Warn overflow of XLS 2003 worksheet
                    break;
                }

                COBieRow row = sheet[r];

                // GET THE ROW + 1 - This stops us overwriting the headers of the worksheet
                IRow excelRow = excelSheet.GetRow(r + 1) ?? excelSheet.CreateRow(r + 1);

                for (int c = 0; c < sheet.Columns.Count; c++)
                {
                    COBieCell cell = row[c];

                    ICell excelCell = excelRow.GetCell(c) ?? excelRow.CreateCell(c);

                    SetCellValue(excelCell, cell);
                    FormatCell(excelCell, cell);
                }
            }

            if ((sheet.RowCount == 0) &&
                (_colours.ContainsKey("Grey"))
                )
            {
                excelSheet.TabColorIndex = _colours["Grey"].Indexed;
            }
            if (sheet.SheetName != Constants.WORKSHEET_PICKLISTS)
            {
                HighlightErrors(excelSheet, sheet);
            }


            RecalculateSheet(excelSheet);
        }
        private void ReportErrors(COBieWorkbook workbook, ICOBieValidationTemplate validationTemplate = null)
        {
            var errorsSheet = XlsWorkbook.GetSheet(ErrorsSheet) ?? XlsWorkbook.CreateSheet(ErrorsSheet);
            ICOBieSheetValidationTemplate sheetValidator = null;

            foreach (var sheet in workbook.OrderBy(w => w.SheetName))
            {
                if (sheet.SheetName != Constants.WORKSHEET_PICKLISTS)
                {
                    if (validationTemplate != null && validationTemplate.Sheet.ContainsKey(sheet.SheetName))
                    {
                        sheetValidator = validationTemplate.Sheet[sheet.SheetName];
                    }
                    // Ensure the validation is up to date
                    sheet.Validate(workbook, ErrorRowIndexBase.RowTwo, sheetValidator);
                }

                WriteErrors(errorsSheet, sheet.Errors);
            }
        }
        /// <summary>
        /// Create a rules sheet
        /// </summary>
        private void ReportRules()
        {
            ISheet rulesSheet = XlsWorkbook.GetSheet(RulesSheet) ?? XlsWorkbook.CreateSheet(RulesSheet);
            //Add Header
            List <string> headings = new List <string>()
            {
                "Component Sheet Excluded Objects",
                "Type Sheet Excluded Objects",
                "Assembly Sheet Excluded Objects",
                "Attributes Excludes All Sheets (Name Containing)",
                "Attributes Excludes All Sheets (Name Equal)",
                "Attributes Excludes All Sheets (Name Starts With)",
                "Attributes Excludes Components (Name Containing)",
                "Attributes Excludes Components (Name Equal)",
                "Attributes Excludes Facility (Name Containing)",
                "Attributes Excludes Facility (Name Equal)",
                "Attributes Excludes Floor (Name Containing)",
                "Attributes Excludes Floor (Name Equal)",
                "Attributes Excludes Space (Name Containing)",
                "Attributes Excludes Space (Name Equal)",
                "Attributes Excludes Space (PropertySet Name)",
                "Attributes Excludes Spare (Name Containing)",
                "Attributes Excludes Spare (Name Equal)",
                "Attributes Excludes Types (Name Containing)",
                "Attributes Excludes Types (Name Equal)",
                "Attributes Excludes Types (PropertySet Name)",
                "Attributes Excludes Zone (Name Containing)"
            };
            int col = 0;

            IRow excelRow = rulesSheet.GetRow(0) ?? rulesSheet.CreateRow(0);

            foreach (string title in headings)
            {
                ICell excelCell = excelRow.GetCell(col) ?? excelRow.CreateCell(col);
                excelCell.SetCellValue(title);
                col++;
            }

            WriteExcludesObjects(0, rulesSheet, Excludes.ObjectType.Component);
            WriteExcludesObjects(1, rulesSheet, Excludes.ObjectType.Types);
            WriteExcludesObjects(2, rulesSheet, Excludes.ObjectType.Assembly);

            WriteExcludesStrings(3, rulesSheet, Excludes.Common.AttributesContain);
            WriteExcludesStrings(4, rulesSheet, Excludes.Common.AttributesEqualTo);
            WriteExcludesStrings(5, rulesSheet, Excludes.Common.AttributesStartWith);
            WriteExcludesStrings(6, rulesSheet, Excludes.Component.AttributesContain);
            WriteExcludesStrings(7, rulesSheet, Excludes.Component.AttributesEqualTo);
            WriteExcludesStrings(8, rulesSheet, Excludes.Facility.AttributesContain);
            WriteExcludesStrings(9, rulesSheet, Excludes.Facility.AttributesEqualTo);
            WriteExcludesStrings(10, rulesSheet, Excludes.Floor.AttributesContain);
            WriteExcludesStrings(11, rulesSheet, Excludes.Floor.AttributesEqualTo);
            WriteExcludesStrings(12, rulesSheet, Excludes.Space.AttributesContain);
            WriteExcludesStrings(13, rulesSheet, Excludes.Space.AttributesEqualTo);
            WriteExcludesStrings(14, rulesSheet, Excludes.Space.PropertySetsEqualTo);
            WriteExcludesStrings(15, rulesSheet, Excludes.Spare.AttributesContain);
            WriteExcludesStrings(16, rulesSheet, Excludes.Spare.AttributesEqualTo);
            WriteExcludesStrings(17, rulesSheet, Excludes.Types.AttributesContain);
            WriteExcludesStrings(18, rulesSheet, Excludes.Types.AttributesEqualTo);
            WriteExcludesStrings(19, rulesSheet, Excludes.Types.PropertySetsEqualTo);
            WriteExcludesStrings(20, rulesSheet, Excludes.Zone.AttributesContain);

            for (int c = 0; c < headings.Count; c++)
            {
                rulesSheet.AutoSizeColumn(c);
            }
        }