/// <summary>
        /// Creates an excel file.
        /// Writes the content of a list into a worksheet of an excelfile and save the file.
        /// </summary>
        /// <param name="worksheet">Sheet to populate</param>
        /// <param name="autosizeColumnWidth">If true, the columns will be autosized. </param>
        /// <returns>
        /// The <see cref="MemoryStream"/>.
        /// </returns>
        public void PopulateSheet(ExcelWorksheet worksheet, bool autosizeColumnWidth = false)
        {
            var resultCalculator = new SpeciesObservationProvenanceResultCalculator(currentUser, SessionHandler.MySettings);
            var data             = resultCalculator.GetSpeciesObservationProvenances();

            AddHeaders(worksheet);
            AddSpeciesObservationsData(worksheet, data);
            FormatHeader(worksheet, 1, 3);

            if (autosizeColumnWidth)
            {
                worksheet.Cells.AutoFitColumns(0);
            }
        }
        /// <summary>
        /// Constructor of an excel xml file with species observation provenances.
        /// </summary>
        /// <param name="currentUser">Current user context</param>
        public SpeciesObservationProvenanceExcelXml(IUserContext currentUser, bool createWoorkbook = true)
            : base()
        {
            var resultCalculator = new SpeciesObservationProvenanceResultCalculator(currentUser, SessionHandler.MySettings);
            var data             = resultCalculator.GetSpeciesObservationProvenances();

            var rowsXml = new StringBuilder();

            //Add row with column headers
            rowsXml.AppendLine(base.GetRowStart());
            rowsXml.AppendLine(base.GetColumnNameRowLine(Resource.ResultViewSpeciesObservationProvenanceTableColumnNameHeader));
            rowsXml.AppendLine(base.GetColumnNameRowLine(Resource.ResultViewSpeciesObservationProvenanceTableColumnValueHeader));
            rowsXml.AppendLine(base.GetColumnNameRowLine(Resource.ResultViewSpeciesObservationProvenanceTableColumnSpeciesObservationCountHeader));
            rowsXml.AppendLine(base.GetRowEnd());

            //Data values
            foreach (var row in data)
            {
                rowsXml.AppendLine(base.GetRowStart());
                rowsXml.AppendLine(base.GetDataRowLine("String", row.Name));
                rowsXml.AppendLine(base.GetRowEnd());

                //Data subvalues
                foreach (var details in row.Values)
                {
                    rowsXml.AppendLine(base.GetRowStart());
                    rowsXml.AppendLine(base.GetDataRowLine("String", string.Empty));
                    rowsXml.AppendLine(base.GetDataRowLine("String", details.Value ?? "-", true));
                    rowsXml.AppendLine(base.GetDataRowLine("Number", details.SpeciesObservationCount.ToString()));
                    rowsXml.AppendLine(base.GetRowEnd());
                }
            }

            var onlySheet = !createWoorkbook;

            _xmlBuilder = new StringBuilder();

            // Create initial section or a new worksheet
            _xmlBuilder.AppendLine(GetInitialSectionOrNewWorksheet(ref createWoorkbook, Resource.SpeciesObservationProvenanceReportSheetName));

            var rowCount = data.Select(v => v.Values.Count).Sum() + data.Count;

            // Specify column and row counts
            _xmlBuilder.AppendLine(GetColumnInitialSection(4, rowCount));

            // Specify column widths
            _xmlBuilder.AppendLine(base.GetColumnWidthLine(90));
            _xmlBuilder.AppendLine(base.GetColumnWidthLine(250));
            _xmlBuilder.AppendLine(base.GetColumnWidthLine(150));

            _xmlBuilder.Append(rowsXml);

            if (onlySheet)
            {
                return;
            }

            // Add final section of the xml document.
            _xmlBuilder.AppendLine(GetFinalSection());
            _xmlBuilder.Replace("&", "&amp;");
        }