Exemple #1
0
        internal SLRowProperties Clone()
        {
            SLRowProperties rp = new SLRowProperties(this.DefaultRowHeight);

            rp.DefaultRowHeight = this.DefaultRowHeight;
            rp.StyleIndex       = this.StyleIndex;
            rp.HasHeight        = this.HasHeight;
            rp.fHeight          = this.fHeight;
            rp.lHeightInEMU     = this.lHeightInEMU;
            rp.Hidden           = this.Hidden;
            rp.OutlineLevel     = this.OutlineLevel;
            rp.Collapsed        = this.Collapsed;
            rp.ThickTop         = this.ThickTop;
            rp.ThickBottom      = this.ThickBottom;
            rp.ShowPhonetic     = this.ShowPhonetic;

            return(rp);
        }
        /// <summary>
        /// Copy the style of one row to a range of rows.
        /// </summary>
        /// <param name="FromRowIndex">The row index of the row to be copied from.</param>
        /// <param name="ToStartRowIndex">The row index of the start row of the row range. This is typically the top row.</param>
        /// <param name="ToEndRowIndex">The row index of the end row of the row range. This is typically the bottom row.</param>
        /// <returns>True if successful. False otherwise.</returns>
        public bool CopyRowStyle(int FromRowIndex, int ToStartRowIndex, int ToEndRowIndex)
        {
            int iStartRowIndex = 1, iEndRowIndex = 1;
            bool result = false;
            if (ToStartRowIndex < ToEndRowIndex)
            {
                iStartRowIndex = ToStartRowIndex;
                iEndRowIndex = ToEndRowIndex;
            }
            else
            {
                iStartRowIndex = ToEndRowIndex;
                iEndRowIndex = ToStartRowIndex;
            }

            if (FromRowIndex >= 1 && FromRowIndex <= SLConstants.RowLimit
                && iStartRowIndex >= 1 && iStartRowIndex <= SLConstants.RowLimit
                && iEndRowIndex >= 1 && iEndRowIndex <= SLConstants.RowLimit)
            {
                result = true;

                uint iStyleIndex = 0;
                if (slws.RowProperties.ContainsKey(FromRowIndex))
                {
                    iStyleIndex = slws.RowProperties[FromRowIndex].StyleIndex;
                }

                SLRowProperties rp;
                int i, j;
                for (i = iStartRowIndex; i <= iEndRowIndex; ++i)
                {
                    if (i != FromRowIndex)
                    {
                        if (iStyleIndex == 0)
                        {
                            if (slws.RowProperties.ContainsKey(i))
                            {
                                slws.RowProperties[i].StyleIndex = 0;
                            }
                        }
                        else
                        {
                            if (slws.RowProperties.ContainsKey(i))
                            {
                                slws.RowProperties[i].StyleIndex = iStyleIndex;
                            }
                            else
                            {
                                rp = new SLRowProperties(SimpleTheme.ThemeRowHeight);
                                rp.StyleIndex = iStyleIndex;
                                slws.RowProperties[i] = rp;
                            }

                            slws.RowColumnStyleHistory.Add(new SLRowColumnStyleHistory(true, i));
                        }
                    }
                }

                #region copying cell styles
                SLCell cell;
                SLCellPoint pt, destpt;
                for (j = 1; j <= SLConstants.ColumnLimit; ++j)
                {
                    pt = new SLCellPoint(FromRowIndex, j);
                    if (slws.Cells.ContainsKey(pt))
                    {
                        for (i = iStartRowIndex; i <= iEndRowIndex; ++i)
                        {
                            if (i != FromRowIndex)
                            {
                                destpt = new SLCellPoint(i, j);
                                if (slws.Cells.ContainsKey(destpt))
                                {
                                    slws.Cells[destpt].StyleIndex = slws.Cells[pt].StyleIndex;
                                }
                                else
                                {
                                    cell = new SLCell();
                                    cell.CellText = string.Empty;
                                    cell.StyleIndex = slws.Cells[pt].StyleIndex;
                                    slws.Cells[destpt] = cell;
                                }
                            }
                        }
                    }
                    else
                    {
                        for (i = iStartRowIndex; i <= iEndRowIndex; ++i)
                        {
                            if (i != FromRowIndex)
                            {
                                destpt = new SLCellPoint(i, j);
                                if (slws.Cells.ContainsKey(destpt))
                                {
                                    slws.Cells[destpt].StyleIndex = iStyleIndex;
                                }
                                // no need else because the default style will take over
                            }
                        }
                    }
                }
                #endregion
            }

            return result;
        }
        /// <summary>
        /// Set the row style for a range of rows.
        /// </summary>
        /// <param name="StartRowIndex">The row index of the starting row.</param>
        /// <param name="EndRowIndex">The row index of the ending row.</param>
        /// <param name="RowStyle">The style for the rows.</param>
        /// <returns>True if the row indices are valid. False otherwise.</returns>
        public bool SetRowStyle(int StartRowIndex, int EndRowIndex, SLStyle RowStyle)
        {
            int iStartRowIndex = 1, iEndRowIndex = 1;
            if (StartRowIndex < EndRowIndex)
            {
                iStartRowIndex = StartRowIndex;
                iEndRowIndex = EndRowIndex;
            }
            else
            {
                iStartRowIndex = EndRowIndex;
                iEndRowIndex = StartRowIndex;
            }

            bool result = false;
            if (iStartRowIndex >= 1 && iStartRowIndex <= SLConstants.RowLimit && iEndRowIndex >= 1 && iEndRowIndex <= SLConstants.RowLimit)
            {
                result = true;
                int i = 0;
                int iStyleIndex = this.SaveToStylesheet(RowStyle.ToHash());
                SLRowProperties rp;
                for (i = iStartRowIndex; i <= iEndRowIndex; ++i)
                {
                    if (slws.RowProperties.ContainsKey(i))
                    {
                        rp = slws.RowProperties[i];
                        rp.StyleIndex = (uint)iStyleIndex;
                        slws.RowProperties[i] = rp;
                    }
                    else
                    {
                        rp = new SLRowProperties(SimpleTheme.ThemeRowHeight);
                        rp.StyleIndex = (uint)iStyleIndex;
                        slws.RowProperties.Add(i, rp);
                    }
                    slws.RowColumnStyleHistory.Add(new SLRowColumnStyleHistory(true, i));
                }

                List<SLCellPoint> listCellKeys = slws.Cells.Keys.ToList<SLCellPoint>();
                SLStyle cellstyle;
                foreach (SLCellPoint pt in listCellKeys)
                {
                    if (iStartRowIndex <= pt.RowIndex && pt.RowIndex <= iEndRowIndex)
                    {
                        cellstyle = this.GetCellStyle(pt.RowIndex, pt.ColumnIndex);
                        cellstyle.MergeStyle(RowStyle);
                        this.SetCellStyle(pt.RowIndex, pt.ColumnIndex, cellstyle);
                    }
                }
            }

            return result;
        }
Exemple #4
0
        private void LoadSelectedWorksheet()
        {
            // Need to check?
            //if (string.IsNullOrEmpty(gsSelectedWorksheetRelationshipID)) return;

            WorksheetPart wsp = (WorksheetPart)wbp.GetPartById(gsSelectedWorksheetRelationshipID);

            slws = new SLWorksheet(SimpleTheme.listThemeColors, SimpleTheme.listIndexedColors, SimpleTheme.ThemeColumnWidth, SimpleTheme.ThemeColumnWidthInEMU, SimpleTheme.ThemeMaxDigitWidth, SimpleTheme.listColumnStepSize, SimpleTheme.ThemeRowHeight);

            int index = 0;
            SLColumnProperties cp;
            Column col;
            SLSheetView slsv;
            MergeCell mc;
            SLMergeCell slmc;
            SLConditionalFormatting condformat;
            SLHyperlink hl;

            OpenXmlReader oxrRow;
            int iRowIndex = -1;
            int iColumnIndex = -1;
            int iGuessRowIndex = 0;
            int iGuessColumnIndex = 0;
            SLRowProperties rp;
            Row r;
            Cell c;
            SLCell slc;

            OpenXmlReader oxr = OpenXmlReader.Create(wsp);
            while (oxr.Read())
            {
                if (oxr.ElementType == typeof(SheetProperties))
                {
                    SheetProperties sprop = (SheetProperties)oxr.LoadCurrentElement();
                    slws.PageSettings.SheetProperties.FromSheetProperties(sprop);
                }
                else if (oxr.ElementType == typeof(SheetView))
                {
                    slsv = new SLSheetView();
                    slsv.FromSheetView((SheetView)oxr.LoadCurrentElement());
                    slws.SheetViews.Add(slsv);

                    // we're concerned only with the first workbook view.
                    if (slsv.ShowFormulas && slsv.WorkbookViewId == 0) slws.IsDoubleColumnWidth = true;
                }
                else if (oxr.ElementType == typeof(SheetFormatProperties))
                {
                    SheetFormatProperties sfp = (SheetFormatProperties)oxr.LoadCurrentElement();
                    slws.SheetFormatProperties.FromSheetFormatProperties(sfp);
                }
                else if (oxr.ElementType == typeof(Column))
                {
                    #region Column
                    int i = 0;
                    col = (Column)oxr.LoadCurrentElement();
                    int min = (int)col.Min.Value;
                    int max = (int)col.Max.Value;
                    for (i = min; i <= max; ++i)
                    {
                        cp = new SLColumnProperties(SimpleTheme.ThemeColumnWidth, SimpleTheme.ThemeColumnWidthInEMU, SimpleTheme.ThemeMaxDigitWidth, SimpleTheme.listColumnStepSize);
                        if (col.Width != null)
                        {
                            cp.Width = col.Width.Value;
                            cp.HasWidth = true;
                        }
                        if (col.Style != null)
                        {
                            index = (int)col.Style.Value;
                            // default is 0
                            if (index > 0 && index < listStyle.Count)
                            {
                                cp.StyleIndex = (uint)index;
                            }
                        }
                        if (col.Hidden != null && col.Hidden.Value) cp.Hidden = col.Hidden.Value;
                        if (col.BestFit != null && col.BestFit.Value) cp.BestFit = col.BestFit.Value;
                        if (col.Phonetic != null && col.Phonetic.Value) cp.Phonetic = col.Phonetic.Value;
                        if (col.OutlineLevel != null && col.OutlineLevel.Value > 0) cp.OutlineLevel = col.OutlineLevel.Value;
                        if (col.Collapsed != null && col.Collapsed.Value) cp.Collapsed = col.Collapsed.Value;
                        slws.ColumnProperties[i] = cp;
                    }
                    #endregion
                }
                else if (oxr.ElementType == typeof(Row))
                {
                    #region Row
                    ++iGuessRowIndex;
                    iGuessColumnIndex = 0;
                    r = (Row)oxr.LoadCurrentElement();
                    rp = new SLRowProperties(SimpleTheme.ThemeRowHeight);
                    if (r.RowIndex != null)
                    {
                        iRowIndex = (int)r.RowIndex.Value;
                        iGuessRowIndex = iRowIndex;
                    }
                    if (r.StyleIndex != null)
                    {
                        index = (int)r.StyleIndex.Value;
                        // default is 0
                        if (index > 0 && index < listStyle.Count)
                        {
                            rp.StyleIndex = (uint)index;
                        }
                    }
                    if (r.Height != null)
                    {
                        rp.HasHeight = true;
                        rp.Height = r.Height.Value;
                    }
                    if (r.Hidden != null && r.Hidden.Value) rp.Hidden = r.Hidden.Value;
                    if (r.OutlineLevel != null && r.OutlineLevel.Value > 0) rp.OutlineLevel = r.OutlineLevel.Value;
                    if (r.Collapsed != null && r.Collapsed.Value) rp.Collapsed = r.Collapsed.Value;
                    if (r.ThickTop != null && r.ThickTop.Value) rp.ThickTop = r.ThickTop.Value;
                    if (r.ThickBot != null && r.ThickBot.Value) rp.ThickBottom = r.ThickBot.Value;
                    if (r.ShowPhonetic != null && r.ShowPhonetic.Value) rp.ShowPhonetic = r.ShowPhonetic.Value;

                    if (slws.RowProperties.ContainsKey(iGuessRowIndex))
                    {
                        slws.RowProperties[iGuessRowIndex] = rp;
                    }
                    else
                    {
                        slws.RowProperties.Add(iGuessRowIndex, rp);
                    }

                    oxrRow = OpenXmlReader.Create(r);
                    while (oxrRow.Read())
                    {
                        if (oxrRow.ElementType == typeof(Cell))
                        {
                            ++iGuessColumnIndex;
                            c = (Cell)oxrRow.LoadCurrentElement();
                            slc = new SLCell();
                            slc.FromCell(c);
                            if (c.CellReference != null)
                            {
                                if (SLTool.FormatCellReferenceToRowColumnIndex(c.CellReference.Value, out iRowIndex, out iColumnIndex))
                                {
                                    iGuessRowIndex = iRowIndex;
                                    iGuessColumnIndex = iColumnIndex;
                                    slws.Cells[new SLCellPoint(iGuessRowIndex, iGuessColumnIndex)] = slc;
                                }
                                else
                                {
                                    slws.Cells[new SLCellPoint(iGuessRowIndex, iGuessColumnIndex)] = slc;
                                }
                            }
                            else
                            {
                                slws.Cells[new SLCellPoint(iGuessRowIndex, iGuessColumnIndex)] = slc;
                            }
                        }
                    }
                    oxrRow.Close();
                    #endregion
                }
                else if (oxr.ElementType == typeof(SheetProtection))
                {
                    SLSheetProtection sp = new SLSheetProtection();
                    sp.FromSheetProtection((SheetProtection)oxr.LoadCurrentElement());
                    slws.HasSheetProtection = true;
                    slws.SheetProtection = sp.Clone();
                }
                else if (oxr.ElementType == typeof(AutoFilter))
                {
                    SLAutoFilter af = new SLAutoFilter();
                    af.FromAutoFilter((AutoFilter)oxr.LoadCurrentElement());
                    slws.HasAutoFilter = true;
                    slws.AutoFilter = af.Clone();
                }
                else if (oxr.ElementType == typeof(MergeCell))
                {
                    mc = (MergeCell)oxr.LoadCurrentElement();
                    slmc = new SLMergeCell();
                    slmc.FromMergeCell(mc);
                    if (slmc.IsValid) slws.MergeCells.Add(slmc);
                }
                else if (oxr.ElementType == typeof(ConditionalFormatting))
                {
                    condformat = new SLConditionalFormatting();
                    condformat.FromConditionalFormatting((ConditionalFormatting)oxr.LoadCurrentElement());
                    slws.ConditionalFormattings.Add(condformat);
                }
                else if (oxr.ElementType == typeof(DataValidations))
                {
                    DataValidations dvs = (DataValidations)oxr.LoadCurrentElement();
                    if (dvs.DisablePrompts != null) slws.DataValidationDisablePrompts = dvs.DisablePrompts.Value;
                    if (dvs.XWindow != null) slws.DataValidationXWindow = dvs.XWindow.Value;
                    if (dvs.YWindow != null) slws.DataValidationYWindow = dvs.YWindow.Value;

                    using (OpenXmlReader oxrDataValidation = OpenXmlReader.Create(dvs))
                    {
                        SLDataValidation dv;
                        while (oxrDataValidation.Read())
                        {
                            if (oxrDataValidation.ElementType == typeof(DataValidation))
                            {
                                dv = new SLDataValidation();
                                dv.FromDataValidation((DataValidation)oxrDataValidation.LoadCurrentElement());
                                slws.DataValidations.Add(dv);
                            }
                        }
                    }
                }
                else if (oxr.ElementType == typeof(Hyperlink))
                {
                    hl = new SLHyperlink();
                    hl.FromHyperlink((Hyperlink)oxr.LoadCurrentElement());
                    slws.Hyperlinks.Add(hl);
                }
                else if (oxr.ElementType == typeof(PrintOptions))
                {
                    PrintOptions po = (PrintOptions)oxr.LoadCurrentElement();
                    if (po.HorizontalCentered != null) slws.PageSettings.PrintHorizontalCentered = po.HorizontalCentered.Value;
                    if (po.VerticalCentered != null) slws.PageSettings.PrintVerticalCentered = po.VerticalCentered.Value;
                    if (po.Headings != null) slws.PageSettings.PrintHeadings = po.Headings.Value;
                    if (po.GridLines != null) slws.PageSettings.PrintGridLines = po.GridLines.Value;
                    if (po.GridLinesSet != null) slws.PageSettings.PrintGridLinesSet = po.GridLinesSet.Value;
                }
                else if (oxr.ElementType == typeof(PageMargins))
                {
                    PageMargins pm = (PageMargins)oxr.LoadCurrentElement();
                    if (pm.Left != null) slws.PageSettings.LeftMargin = pm.Left.Value;
                    if (pm.Right != null) slws.PageSettings.RightMargin = pm.Right.Value;
                    if (pm.Top != null) slws.PageSettings.TopMargin = pm.Top.Value;
                    if (pm.Bottom != null) slws.PageSettings.BottomMargin = pm.Bottom.Value;
                    if (pm.Header != null) slws.PageSettings.HeaderMargin = pm.Header.Value;
                    if (pm.Footer != null) slws.PageSettings.FooterMargin = pm.Footer.Value;
                }
                else if (oxr.ElementType == typeof(PageSetup))
                {
                    PageSetup ps = (PageSetup)oxr.LoadCurrentElement();
                    // consider setting to 1 if not one of the "valid" paper sizes?
                    if (ps.PaperSize != null) slws.PageSettings.PaperSize = (SLPaperSizeValues)ps.PaperSize.Value;
                    if (ps.Scale != null) slws.PageSettings.iScale = ps.Scale.Value;
                    if (ps.FirstPageNumber != null) slws.PageSettings.FirstPageNumber = ps.FirstPageNumber.Value;
                    if (ps.FitToWidth != null) slws.PageSettings.iFitToWidth = ps.FitToWidth.Value;
                    if (ps.FitToHeight != null) slws.PageSettings.iFitToHeight = ps.FitToHeight.Value;
                    if (ps.PageOrder != null) slws.PageSettings.PageOrder = ps.PageOrder.Value;
                    if (ps.Orientation != null) slws.PageSettings.Orientation = ps.Orientation.Value;
                    if (ps.UsePrinterDefaults != null) slws.PageSettings.UsePrinterDefaults = ps.UsePrinterDefaults.Value;
                    if (ps.BlackAndWhite != null) slws.PageSettings.BlackAndWhite = ps.BlackAndWhite.Value;
                    if (ps.Draft != null) slws.PageSettings.Draft = ps.Draft.Value;
                    if (ps.CellComments != null) slws.PageSettings.CellComments = ps.CellComments.Value;
                    if (ps.Errors != null) slws.PageSettings.Errors = ps.Errors.Value;
                    if (ps.HorizontalDpi != null) slws.PageSettings.HorizontalDpi = ps.HorizontalDpi.Value;
                    if (ps.VerticalDpi != null) slws.PageSettings.VerticalDpi = ps.VerticalDpi.Value;
                    if (ps.Copies != null) slws.PageSettings.Copies = ps.Copies.Value;
                }
                else if (oxr.ElementType == typeof(HeaderFooter))
                {
                    HeaderFooter hf = (HeaderFooter)oxr.LoadCurrentElement();
                    if (hf.OddHeader != null) slws.PageSettings.OddHeaderText = hf.OddHeader.Text;
                    if (hf.OddFooter != null) slws.PageSettings.OddFooterText = hf.OddFooter.Text;
                    if (hf.EvenHeader != null) slws.PageSettings.EvenHeaderText = hf.EvenHeader.Text;
                    if (hf.EvenFooter != null) slws.PageSettings.EvenFooterText = hf.EvenFooter.Text;
                    if (hf.FirstHeader != null) slws.PageSettings.FirstHeaderText = hf.FirstHeader.Text;
                    if (hf.FirstFooter != null) slws.PageSettings.FirstFooterText = hf.FirstFooter.Text;
                    if (hf.DifferentOddEven != null) slws.PageSettings.DifferentOddEvenPages = hf.DifferentOddEven.Value;
                    if (hf.DifferentFirst != null) slws.PageSettings.DifferentFirstPage = hf.DifferentFirst.Value;
                    if (hf.ScaleWithDoc != null) slws.PageSettings.ScaleWithDocument = hf.ScaleWithDoc.Value;
                    if (hf.AlignWithMargins != null) slws.PageSettings.AlignWithMargins = hf.AlignWithMargins.Value;
                }
                else if (oxr.ElementType == typeof(RowBreaks))
                {
                    SLBreak b;
                    uint rowbkindex;
                    using (OpenXmlReader oxrRowBreaks = OpenXmlReader.Create((RowBreaks)oxr.LoadCurrentElement()))
                    {
                        while (oxrRowBreaks.Read())
                        {
                            if (oxrRowBreaks.ElementType == typeof(Break))
                            {
                                b = new SLBreak();
                                b.FromBreak((Break)oxrRowBreaks.LoadCurrentElement());
                                rowbkindex = b.Id;
                                slws.RowBreaks[(int)rowbkindex] = b;
                            }
                        }
                    }
                }
                else if (oxr.ElementType == typeof(ColumnBreaks))
                {
                    SLBreak b;
                    uint colbkindex;
                    using (OpenXmlReader oxrColBreaks = OpenXmlReader.Create((ColumnBreaks)oxr.LoadCurrentElement()))
                    {
                        while (oxrColBreaks.Read())
                        {
                            if (oxrColBreaks.ElementType == typeof(Break))
                            {
                                b = new SLBreak();
                                b.FromBreak((Break)oxrColBreaks.LoadCurrentElement());
                                colbkindex = b.Id;
                                slws.ColumnBreaks[(int)colbkindex] = b;
                            }
                        }
                    }
                }
                else if (oxr.ElementType == typeof(DocumentFormat.OpenXml.Spreadsheet.Drawing))
                {
                    DocumentFormat.OpenXml.Spreadsheet.Drawing drawing = (DocumentFormat.OpenXml.Spreadsheet.Drawing)oxr.LoadCurrentElement();
                    slws.DrawingId = drawing.Id;
                    if (wsp.DrawingsPart != null)
                    {
                        Xdr.NonVisualDrawingProperties nvdp;
                        uint iUniqueId = 1;
                        using (OpenXmlReader oxrDrawing = OpenXmlReader.Create(wsp.DrawingsPart.WorksheetDrawing))
                        {
                            while (oxrDrawing.Read())
                            {
                                if (oxrDrawing.ElementType == typeof(Xdr.NonVisualDrawingProperties))
                                {
                                    nvdp = (Xdr.NonVisualDrawingProperties)oxrDrawing.LoadCurrentElement();
                                    if (nvdp.Id != null && nvdp.Id.Value > iUniqueId)
                                    {
                                        iUniqueId = nvdp.Id.Value;
                                    }
                                }
                            }
                        }
                        slws.NextWorksheetDrawingId = iUniqueId + 1;
                    }
                }
                else if (oxr.ElementType == typeof(Picture))
                {
                    Picture pic = (Picture)oxr.LoadCurrentElement();
                    slws.BackgroundPictureId = pic.Id;
                    slws.BackgroundPictureDataIsInFile = null;
                }
                else if (oxr.ElementType == typeof(WorksheetExtensionList))
                {
                    WorksheetExtensionList wsextlist = (WorksheetExtensionList)oxr.LoadCurrentElement();

                    SLConditionalFormatting2010 cf2010;
                    X14.SparklineGroup sparkgrp;
                    SLSparklineGroup spkgrp;

                    using (OpenXmlReader oxrext = OpenXmlReader.Create(wsextlist))
                    {
                        while (oxrext.Read())
                        {
                            if (oxrext.ElementType == typeof(X14.ConditionalFormatting))
                            {
                                cf2010 = new SLConditionalFormatting2010();
                                cf2010.FromConditionalFormatting((X14.ConditionalFormatting)oxrext.LoadCurrentElement());
                                slws.ConditionalFormattings2010.Add(cf2010.Clone());
                            }
                            else if (oxrext.ElementType == typeof(X14.SparklineGroup))
                            {
                                sparkgrp = (X14.SparklineGroup)oxrext.LoadCurrentElement();
                                spkgrp = new SLSparklineGroup(SimpleTheme.listThemeColors, SimpleTheme.listIndexedColors);
                                spkgrp.FromSparklineGroup(sparkgrp);
                                slws.SparklineGroups.Add(spkgrp.Clone());
                            }
                        }
                    }
                }
            }
            oxr.Dispose();

            if (wsp.TableDefinitionParts != null)
            {
                SLTable t;
                foreach (TableDefinitionPart tdp in wsp.TableDefinitionParts)
                {
                    t = new SLTable();
                    t.FromTable(tdp.Table);
                    t.RelationshipID = wsp.GetIdOfPart(tdp);
                    t.IsNewTable = false;
                    slws.Tables.Add(t);
                }
            }
        }
        internal SLRowProperties Clone()
        {
            SLRowProperties rp = new SLRowProperties(this.DefaultRowHeight);
            rp.DefaultRowHeight = this.DefaultRowHeight;
            rp.StyleIndex = this.StyleIndex;
            rp.HasHeight = this.HasHeight;
            rp.fHeight = this.fHeight;
            rp.lHeightInEMU = this.lHeightInEMU;
            rp.Hidden = this.Hidden;
            rp.OutlineLevel = this.OutlineLevel;
            rp.Collapsed = this.Collapsed;
            rp.ThickTop = this.ThickTop;
            rp.ThickBottom = this.ThickBottom;
            rp.ShowPhonetic = this.ShowPhonetic;

            return rp;
        }
        /// <summary>
        /// Set the row height for a range of rows.
        /// </summary>
        /// <param name="StartRowIndex">The row index of the starting row.</param>
        /// <param name="EndRowIndex">The row index of the ending row.</param>
        /// <param name="RowHeight">The row height in points.</param>
        /// <returns>True if the row indices are valid. False otherwise.</returns>
        public bool SetRowHeight(int StartRowIndex, int EndRowIndex, double RowHeight)
        {
            int iStartRowIndex = 1, iEndRowIndex = 1;
            if (StartRowIndex < EndRowIndex)
            {
                iStartRowIndex = StartRowIndex;
                iEndRowIndex = EndRowIndex;
            }
            else
            {
                iStartRowIndex = EndRowIndex;
                iEndRowIndex = StartRowIndex;
            }

            bool result = false;
            if (iStartRowIndex >= 1 && iStartRowIndex <= SLConstants.RowLimit && iEndRowIndex >= 1 && iEndRowIndex <= SLConstants.RowLimit)
            {
                result = true;
                int i = 0;
                SLRowProperties rp;
                for (i = iStartRowIndex; i <= iEndRowIndex; ++i)
                {
                    if (slws.RowProperties.ContainsKey(i))
                    {
                        rp = slws.RowProperties[i];
                        rp.Height = RowHeight;
                        slws.RowProperties[i] = rp;
                    }
                    else
                    {
                        rp = new SLRowProperties(SimpleTheme.ThemeRowHeight);
                        rp.Height = RowHeight;
                        slws.RowProperties.Add(i, rp);
                    }
                }
            }

            return result;
        }
        /// <summary>
        /// Automatically fit row height according to cell contents.
        /// </summary>
        /// <param name="StartRowIndex">The row index of the starting row.</param>
        /// <param name="EndRowIndex">The row index of the ending row.</param>
        public void AutoFitRow(int StartRowIndex, int EndRowIndex)
        {
            int iStartRowIndex = 1, iEndRowIndex = 1;
            if (StartRowIndex < EndRowIndex)
            {
                iStartRowIndex = StartRowIndex;
                iEndRowIndex = EndRowIndex;
            }
            else
            {
                iStartRowIndex = EndRowIndex;
                iEndRowIndex = StartRowIndex;
            }

            if (iStartRowIndex < 1) iStartRowIndex = 1;
            if (iStartRowIndex > SLConstants.RowLimit) iStartRowIndex = SLConstants.RowLimit;
            if (iEndRowIndex < 1) iEndRowIndex = 1;
            if (iEndRowIndex > SLConstants.RowLimit) iEndRowIndex = SLConstants.RowLimit;

            Dictionary<int, int> pixellength = this.AutoFitRowColumn(true, iStartRowIndex, iEndRowIndex);

            double fResolution = 96.0;
            using (System.Drawing.Bitmap bm = new System.Drawing.Bitmap(32, 32))
            {
                fResolution = (double)bm.VerticalResolution;
            }

            double fDefaultRowHeight = slws.SheetFormatProperties.DefaultRowHeight;
            double fMinimumHeight = 0;

            SLStyle style;
            string sFontName;
            double fFontSize;
            bool bBold;
            bool bItalic;
            bool bStrike;
            bool bUnderline;
            System.Drawing.FontStyle drawstyle = System.Drawing.FontStyle.Regular;
            System.Drawing.SizeF szf;

            SLRowProperties rp;
            double fRowHeight;
            int iPixelLength;
            foreach (int pixlenpt in pixellength.Keys)
            {
                iPixelLength = pixellength[pixlenpt];
                if (iPixelLength > 0)
                {
                    // height in points = number of pixels * 72 (points per inch) / resolution (DPI)
                    fRowHeight = (double)iPixelLength * 72.0 / fResolution;
                    if (slws.RowProperties.ContainsKey(pixlenpt))
                    {
                        rp = slws.RowProperties[pixlenpt];

                        // if the row has a style, we have to check if the resulting row height
                        // based on the typeface, boldness, italicise-ness and whatnot will change.
                        // Basically we're calculating a "default" row height based on the typeface
                        // set on the entire row.
                        style = new SLStyle();
                        style.FromHash(listStyle[(int)rp.StyleIndex]);
                        if (style.HasFont)
                        {
                            sFontName = SimpleTheme.MinorLatinFont;
                            fFontSize = SLConstants.DefaultFontSize;
                            bBold = false;
                            bItalic = false;
                            bStrike = false;
                            bUnderline = false;
                            drawstyle = System.Drawing.FontStyle.Regular;
                            if (style.fontReal.HasFontScheme)
                            {
                                if (style.fontReal.FontScheme == FontSchemeValues.Major) sFontName = SimpleTheme.MajorLatinFont;
                                else if (style.fontReal.FontScheme == FontSchemeValues.Minor) sFontName = SimpleTheme.MinorLatinFont;
                                else if (style.fontReal.FontName.Length > 0) sFontName = style.fontReal.FontName;
                            }
                            else
                            {
                                if (style.fontReal.FontName.Length > 0) sFontName = style.fontReal.FontName;
                            }

                            if (style.fontReal.FontSize != null) fFontSize = style.fontReal.FontSize.Value;
                            if (style.fontReal.Bold != null && style.fontReal.Bold.Value) bBold = true;
                            if (style.fontReal.Italic != null && style.fontReal.Italic.Value) bItalic = true;
                            if (style.fontReal.Strike != null && style.fontReal.Strike.Value) bStrike = true;
                            if (style.fontReal.HasUnderline) bUnderline = true;

                            if (bBold) drawstyle |= System.Drawing.FontStyle.Bold;
                            if (bItalic) drawstyle |= System.Drawing.FontStyle.Italic;
                            if (bStrike) drawstyle |= System.Drawing.FontStyle.Strikeout;
                            if (bUnderline) drawstyle |= System.Drawing.FontStyle.Underline;

                            // any text will do. Apparently the height is the same regardless.
                            szf = SLTool.MeasureText("0123456789", sFontName, fFontSize, drawstyle);

                            fMinimumHeight = Math.Min(szf.Height, fDefaultRowHeight);
                        }
                        else
                        {
                            fMinimumHeight = fDefaultRowHeight;
                        }

                        if (fRowHeight > fMinimumHeight)
                        {
                            rp.Height = fRowHeight;
                            rp.CustomHeight = false;
                            slws.RowProperties[pixlenpt] = rp.Clone();
                        }
                    }
                    else
                    {
                        rp = new SLRowProperties(SimpleTheme.ThemeRowHeight);
                        rp.Height = fRowHeight;
                        rp.CustomHeight = false;
                        slws.RowProperties[pixlenpt] = rp.Clone();
                    }
                }
                else
                {
                    // else we set autoheight. Meaning we set the default height for any
                    // existing rows.

                    if (slws.RowProperties.ContainsKey(pixlenpt))
                    {
                        rp = slws.RowProperties[pixlenpt];
                        rp.Height = SimpleTheme.ThemeRowHeight;
                        rp.CustomHeight = false;
                        slws.RowProperties[pixlenpt] = rp.Clone();
                    }
                }
            }
        }
        /// <summary>
        /// Collapse a group of rows.
        /// </summary>
        /// <param name="RowIndex">The row index of the row just after the group of rows you want to collapse. For example, this will be row 5 if rows 2 to 4 are grouped.</param>
        public void CollapseRows(int RowIndex)
        {
            if (RowIndex < 1 || RowIndex > SLConstants.RowLimit) return;

            // the following algorithm is not guaranteed to work in all cases.
            // The data is sort of loosely linked together with no guarantee that they
            // all make sense together. If you use Excel, then the internal data is sort of
            // guaranteed to make sense together, but anyone can make an Open XML spreadsheet
            // with possibly invalid-looking data. Maybe Excel will accept it, maybe not.

            SLRowProperties rp;
            byte byCurrentOutlineLevel = 0;
            if (slws.RowProperties.ContainsKey(RowIndex))
            {
                rp = slws.RowProperties[RowIndex];
                byCurrentOutlineLevel = rp.OutlineLevel;
            }

            bool bFound = false;
            int i;

            for (i = RowIndex - 1; i >= 1; --i)
            {
                if (slws.RowProperties.ContainsKey(i))
                {
                    rp = slws.RowProperties[i];
                    if (rp.OutlineLevel > byCurrentOutlineLevel)
                    {
                        bFound = true;
                        rp.Hidden = true;
                        slws.RowProperties[i] = rp.Clone();
                    }
                    else break;
                }
                else break;
            }

            if (bFound)
            {
                if (slws.RowProperties.ContainsKey(RowIndex))
                {
                    rp = slws.RowProperties[RowIndex];
                    rp.Collapsed = true;
                    slws.RowProperties[RowIndex] = rp.Clone();
                }
                else
                {
                    rp = new SLRowProperties(SimpleTheme.ThemeRowHeight);
                    rp.Collapsed = true;
                    slws.RowProperties[RowIndex] = rp.Clone();
                }
            }
        }
        /// <summary>
        /// Group rows.
        /// </summary>
        /// <param name="StartRowIndex">The row index of the start row.</param>
        /// <param name="EndRowIndex">The row index of the end row.</param>
        public void GroupRows(int StartRowIndex, int EndRowIndex)
        {
            int iStartRowIndex = 1, iEndRowIndex = 1;
            if (StartRowIndex < EndRowIndex)
            {
                iStartRowIndex = StartRowIndex;
                iEndRowIndex = EndRowIndex;
            }
            else
            {
                iStartRowIndex = EndRowIndex;
                iEndRowIndex = StartRowIndex;
            }

            // I haven't personally checked this, but there's a collapsing -/+ box on the row
            // just below the grouped rows. This implies the very very last row that can be
            // grouped is the (row limit - 1)th row, because (row limit)th row will have that
            // collapsing box.
            if (iEndRowIndex >= SLConstants.RowLimit) iEndRowIndex = SLConstants.RowLimit - 1;
            // there's nothing to group...
            if (iStartRowIndex > iEndRowIndex) return;

            if (iStartRowIndex >= 1 && iStartRowIndex <= SLConstants.RowLimit && iEndRowIndex >= 1 && iEndRowIndex <= SLConstants.RowLimit)
            {
                int i = 0;
                SLRowProperties rp;
                for (i = iStartRowIndex; i <= iEndRowIndex; ++i)
                {
                    if (slws.RowProperties.ContainsKey(i))
                    {
                        rp = slws.RowProperties[i];
                        // Excel supports only 8 levels
                        if (rp.OutlineLevel < 8) ++rp.OutlineLevel;
                        slws.RowProperties[i] = rp.Clone();
                    }
                    else
                    {
                        rp = new SLRowProperties(SimpleTheme.ThemeRowHeight);
                        rp.OutlineLevel = 1;
                        slws.RowProperties[i] = rp.Clone();
                    }
                }
            }
        }