Esempio n. 1
0
        void SelectionLocationReceived(object sender, EventArgs e)
        {
            RangePacket packet    = (RangePacket)sender;
            Range       selection = ActiveWorksheet.Range[packet.RangeInfo];
            ExcelUser   user      = packet.User;

            if (lastRange != null)
            {
                Debug.WriteLine(lastLeftColor);
                lastRange.Borders.Item[XlBordersIndex.xlEdgeLeft].Color       = lastLeftColor;
                lastRange.Borders.Item[XlBordersIndex.xlEdgeLeft].Weight      = lastLeftWeight;
                lastRange.Borders.Item[XlBordersIndex.xlEdgeLeft].LineStyle   = lastLeftStyle;
                lastRange.Borders.Item[XlBordersIndex.xlEdgeTop].Color        = lastTopColor;
                lastRange.Borders.Item[XlBordersIndex.xlEdgeTop].Weight       = lastTopWeight;
                lastRange.Borders.Item[XlBordersIndex.xlEdgeTop].LineStyle    = lastTopStyle;
                lastRange.Borders.Item[XlBordersIndex.xlEdgeRight].Color      = lastRightColor;
                lastRange.Borders.Item[XlBordersIndex.xlEdgeRight].Weight     = lastRightWeight;
                lastRange.Borders.Item[XlBordersIndex.xlEdgeRight].LineStyle  = lastRightStyle;
                lastRange.Borders.Item[XlBordersIndex.xlEdgeBottom].Color     = lastBottomColor;
                lastRange.Borders.Item[XlBordersIndex.xlEdgeBottom].Weight    = lastBottomWeight;
                lastRange.Borders.Item[XlBordersIndex.xlEdgeBottom].LineStyle = lastBottomStyle;
                lastRange.ClearComments();
                if (lastComments.Count >= 0)
                {
                    if (lastComments[0] != null)
                    {
                        lastRange.AddComment(lastComments[0]);
                    }
                }


                //all you have to do is .copy!!!!!!!!!!!!!!!!!!!!!!
                //selection.Copy(lastRange);
                //ActiveWorksheet.Range["A1"].Value = "test";
            }
            lastRange = selection;
            Debug.WriteLine("got selection change");
            ActiveRange  = selection;
            lastComments = new List <string>();

            lastLeftColor    = (XlRgbColor)selection.Borders.Item[XlBordersIndex.xlEdgeLeft].Color;
            lastLeftWeight   = (XlBorderWeight)selection.Borders.Item[XlBordersIndex.xlEdgeLeft].Weight;
            lastLeftStyle    = (XlLineStyle)selection.Borders.Item[XlBordersIndex.xlEdgeLeft].LineStyle;
            lastTopColor     = (XlRgbColor)selection.Borders.Item[XlBordersIndex.xlEdgeTop].Color;
            lastTopWeight    = (XlBorderWeight)selection.Borders.Item[XlBordersIndex.xlEdgeTop].Weight;
            lastTopStyle     = (XlLineStyle)selection.Borders.Item[XlBordersIndex.xlEdgeTop].LineStyle;
            lastRightColor   = (XlRgbColor)selection.Borders.Item[XlBordersIndex.xlEdgeRight].Color;
            lastRightWeight  = (XlBorderWeight)selection.Borders.Item[XlBordersIndex.xlEdgeRight].Weight;
            lastRightStyle   = (XlLineStyle)selection.Borders.Item[XlBordersIndex.xlEdgeRight].LineStyle;
            lastBottomColor  = (XlRgbColor)selection.Borders.Item[XlBordersIndex.xlEdgeBottom].Color;
            lastBottomWeight = (XlBorderWeight)selection.Borders.Item[XlBordersIndex.xlEdgeBottom].Weight;
            lastBottomStyle  = (XlLineStyle)selection.Borders.Item[XlBordersIndex.xlEdgeBottom].LineStyle;

            selection.Borders.Item[XlBordersIndex.xlEdgeLeft].Color    = XlRgbColor.rgbBlue;
            selection.Borders.Item[XlBordersIndex.xlEdgeLeft].Weight   = XlBorderWeight.xlMedium;
            selection.Borders.Item[XlBordersIndex.xlEdgeTop].Color     = XlRgbColor.rgbBlue;
            selection.Borders.Item[XlBordersIndex.xlEdgeTop].Weight    = XlBorderWeight.xlMedium;
            selection.Borders.Item[XlBordersIndex.xlEdgeRight].Color   = XlRgbColor.rgbBlue;
            selection.Borders.Item[XlBordersIndex.xlEdgeRight].Weight  = XlBorderWeight.xlMedium;
            selection.Borders.Item[XlBordersIndex.xlEdgeBottom].Color  = XlRgbColor.rgbBlue;
            selection.Borders.Item[XlBordersIndex.xlEdgeBottom].Weight = XlBorderWeight.xlMedium;

            lastComments.Add(selection.Comment?.Text());
            selection.ClearComments();
            Debug.WriteLine("Made it to comment adding");
            if (selection.Count < 2)
            {
                selection.AddComment(user.ToString() + ": Updating this cell at the moment");
            }
            else
            {
                selection[selection.Columns.Count]?.AddComment(user.ToString() + ": Updating these cells at the moment");
            }
        }