void insertBorderData(ExcelBorderData borderData) { Range range = GetRange(borderData.Range); foreach (ExcelBorderItem item in borderData.Borders) { XlLineStyle lineSyle = (XlLineStyle)item.LineStyle; XlBorderWeight weight = (XlBorderWeight)item.Weight; if (item.Index == ExcelBordersIndex.xlAround) { range.BorderAround(lineSyle, weight); } else if (item.Index == ExcelBordersIndex.xlInside) { range.Borders[XlBordersIndex.xlInsideHorizontal].LineStyle = lineSyle; range.Borders[XlBordersIndex.xlInsideVertical].LineStyle = lineSyle; range.Borders[XlBordersIndex.xlInsideHorizontal].Weight = weight; range.Borders[XlBordersIndex.xlInsideVertical].Weight = weight; } else { XlBordersIndex index = (XlBordersIndex)item.Index; range.Borders[index].Weight = weight; range.Borders[index].LineStyle = lineSyle; } } }
public static void FormatBordersInner(Range range, Color color, XlLineStyle style = XlLineStyle.xlContinuous, XlBorderWeight weight = XlBorderWeight.xlThin) { FormatBorder(range, color, XlBordersIndex.xlInsideHorizontal, style, weight); FormatBorder(range, color, XlBordersIndex.xlInsideVertical, style, weight); }
public static void FormatBordersAll(Range range, Color color, XlLineStyle style = XlLineStyle.xlContinuous, XlBorderWeight weight = XlBorderWeight.xlThin) { FormatBordersOuter(range, color, style, weight); FormatBordersInner(range, color, style, weight); }
public void BorderAround(XlLineStyle lineStyle, XlBorderWeight weight, Color color) { object[] paramArray = new object[4]; paramArray[0] = lineStyle; paramArray[1] = weight; paramArray[2] = Missing.Value; paramArray[3] = XlConverter.ToDouble(color); InstanceType.InvokeMember("BorderAround", BindingFlags.InvokeMethod | BindingFlags.OptionalParamBinding, null, ComReference, paramArray, XlLateBindingApiSettings.XlThreadCulture); }
public static void FormatBordersOuter(Range range, Color color, XlLineStyle style = XlLineStyle.xlContinuous, XlBorderWeight weight = XlBorderWeight.xlThin) { FormatBorder(range, color, XlBordersIndex.xlEdgeLeft, style, weight); FormatBorder(range, color, XlBordersIndex.xlEdgeTop, style, weight); FormatBorder(range, color, XlBordersIndex.xlEdgeRight, style, weight); FormatBorder(range, color, XlBordersIndex.xlEdgeBottom, style, weight); }
public static void FormatBorder(Range range, Color color, XlBordersIndex edge, XlLineStyle style = XlLineStyle.xlContinuous, XlBorderWeight weight = XlBorderWeight.xlThin) { var borders = range.Borders[edge]; borders.LineStyle = style; borders.Color = XlColor(color); borders.TintAndShade = 0; borders.Weight = weight; }
private void CellBorderStyle(Range range, XlLineStyle style, XlBordersIndex?border = null) { if (border == null) { range.Borders.LineStyle = style; } else { range.Borders[(XlBordersIndex)border].LineStyle = style; } }
// Установка одной границы ячейки public void SetCellBorder(string address, XlBordersIndex index, XlLineStyle lineStyle, XlBorderWeight weight) { object fRange = _sheet.GetType().InvokeMember( "Range", BindingFlags.GetProperty, null, _sheet, new object[] { address }); object border = fRange.GetType().InvokeMember( "Borders", BindingFlags.GetProperty, null, fRange, new object[] { index }); border.GetType().InvokeMember( "LineStyle", BindingFlags.SetProperty, null, border, new object[] { lineStyle }); border.GetType().InvokeMember( "Weight", BindingFlags.SetProperty, null, border, new object[] { weight }); border = null; }
/// <summary> /// Dar formato de tabla a los valores de la hoja. /// </summary> /// <param name="bordes_internos">Valor que indica si se deben mostrar los bordes internos</param> public override void formatoTabla(bool bordes_internos) { XlLineStyle estilo = XlLineStyle.xlContinuous; XlBorderWeight ancho = XlBorderWeight.xlThin; XlColorIndex color = XlColorIndex.xlColorIndexAutomatic; if (bordes_internos) { _seleccionado.Borders[XlBordersIndex.xlInsideHorizontal].LineStyle = estilo; _seleccionado.Borders[XlBordersIndex.xlInsideHorizontal].Weight = ancho; _seleccionado.Borders[XlBordersIndex.xlInsideVertical].LineStyle = estilo; _seleccionado.Borders[XlBordersIndex.xlInsideVertical].Weight = ancho; } _seleccionado.BorderAround(estilo, ancho, color, Color.Black.ToArgb()); }
public void SetBorder(Range range, XlLineStyle lineStyle, XlBorderWeight weight, bool top, bool bottom, bool left, bool right) { if (top) { SetBorder(range, XlBordersIndex.xlEdgeTop, lineStyle, weight); } if (bottom) { SetBorder(range, XlBordersIndex.xlEdgeBottom, lineStyle, weight); } if (left) { SetBorder(range, XlBordersIndex.xlEdgeLeft, lineStyle, weight); } if (right) { SetBorder(range, XlBordersIndex.xlEdgeRight, lineStyle, weight); } }
public async Task SetTable(int sheet, string range, bool currentRegion, XlLineStyle insideLineStyle) { await Task.Run(new System.Action(() => { sheets = xlWorkbook.Sheets; setValueSheet = sheets.get_Item(sheet); setValueRange = setValueSheet.Range[range]; if (currentRegion) { range1 = setValueRange.CurrentRegion; borders = range1.Borders; } else { borders = setValueRange.Borders; } borders.Color = System.Drawing.Color.Black; borders[XlBordersIndex.xlInsideHorizontal].LineStyle = insideLineStyle; borders[XlBordersIndex.xlInsideHorizontal].Weight = XlBorderWeight.xlThin; borders[XlBordersIndex.xlInsideVertical].LineStyle = insideLineStyle; borders[XlBordersIndex.xlInsideVertical].Weight = XlBorderWeight.xlThin; } )); }
public void cellBorderLine(int i, int j, XlLineStyle line, XlBorderWeight weight) { sheet.get_Range(sheet.Cells[i, j], sheet.Cells[i, j]).Borders.LineStyle = line; sheet.get_Range(sheet.Cells[i, j], sheet.Cells[i, j]).Borders.Weight = weight; }
public static void Border_cell(string first_cell, string last_cell, string style, int Weight) { XlLineStyle xlL_style = new XlLineStyle(); // draw back color and border the range explicitly switch (style.ToUpper()) { case "CONTINUOUS": xlL_style = XlLineStyle.xlContinuous; break; case "DASH": xlL_style = XlLineStyle.xlDash; break; case "DASHDOT": xlL_style = XlLineStyle.xlDashDot; break; case "DASHDOTDOT": xlL_style = XlLineStyle.xlDashDotDot; break; case "DOT": xlL_style = XlLineStyle.xlDot; break; case "DOUBLE": xlL_style = XlLineStyle.xlDouble; break; case "NONE": xlL_style = XlLineStyle.xlLineStyleNone; break; case "SLANTDASHDOT": xlL_style = XlLineStyle.xlSlantDashDot; break; default: xlL_style = XlLineStyle.xlLineStyleNone; break; } workSheet.Range(first_cell + ":" + last_cell).Borders[XlBordersIndex.xlInsideHorizontal].LineStyle = xlL_style; workSheet.Range(first_cell + ":" + last_cell).Borders[XlBordersIndex.xlInsideHorizontal].Weight = Weight; workSheet.Range(first_cell + ":" + last_cell).Borders[XlBordersIndex.xlInsideHorizontal].Color = ToDouble(Color.Black); }
public static void Cell_Border(string cell, string direction, string style, string colour) { XlLineStyle xlstyle = new XlLineStyle(); XlBordersIndex xldirection = new XlBordersIndex(); Color xlcolour = new Color(); switch (colour) { case "Black": xlcolour = Color.Black; break; case "Blue": xlcolour = Color.Blue; break; case "Orange": xlcolour = Color.Orange; break; case "Red": xlcolour = Color.Red; break; } switch (direction) { case "InsideHorizontal": xldirection = XlBordersIndex.xlInsideHorizontal; break; case "InsideVertical": xldirection = XlBordersIndex.xlInsideVertical; break; case "Bottom": xldirection = XlBordersIndex.xlEdgeBottom; break; case "Left": xldirection = XlBordersIndex.xlEdgeLeft; break; case "Right": xldirection = XlBordersIndex.xlEdgeRight; break; case "Top": xldirection = XlBordersIndex.xlEdgeTop; break; } switch (style) { case "Continuous": xlstyle = XlLineStyle.xlContinuous; break; case "Dot": xlstyle = XlLineStyle.xlDot; break; case "Double": xlstyle = XlLineStyle.xlDouble; break; } workSheet.Range(cell).Borders[xldirection].LineStyle = xlstyle; workSheet.Range(cell).Borders[xldirection].Color = ToDouble(xlcolour); }
/// <summary> /// Toggles a border of the specified cells and applies the settings if it is toggled on. /// </summary> /// <param name="workbookName">The stored index of the workbook.</param> /// <param name="sheetIndex">The sheet number you wish to alter (note: excel sheets begin with number 1, not 0).</param> /// <param name="cellSelection">Indicates the cells to be changed. Works just like Excel. Example: "A:A,1:1,A2:B3,F4,F5"</param> /// <param name="borderToToggle">Indicates the border that will be toggled.</param> /// <param name="weightToSet">Indicates the weight the border will be set to if it is being toggled on.</param> /// <param name="styleToSet">Indicates the line style the border will be set to if it is being toggled on.</param> public void SetBorders(string workbookName, int sheetIndex, string cellSelection, XlBordersIndex borderToToggle, Microsoft.Office.Interop.Excel.XlBorderWeight weightToSet, XlLineStyle styleToSet) { List <Range> rangesToAlter = GetRanges(workbookName, sheetIndex, cellSelection); foreach (Range rangeToAlter in rangesToAlter) { if ((XlLineStyle)rangeToAlter.Borders[borderToToggle].LineStyle != XlLineStyle.xlLineStyleNone) { rangeToAlter.Borders[borderToToggle].LineStyle = XlLineStyle.xlLineStyleNone; } else { rangeToAlter.Borders[borderToToggle].LineStyle = styleToSet; rangeToAlter.Borders[borderToToggle].Weight = weightToSet; } } }
/// <summary>向单元格区域添加边框,并设置该新边框的 Color、LineStyle 和 Weight 属性。Variant 类型。 /// </summary> /// <param name="LineStyle">用于指定边框线样式的 XlLineStyle 常量之一。</param> /// <param name="Weight">边框粗细。</param> /// <param name="ColorIndex">边框颜色,作为当前调色板的索引或作为 XlColorIndex 常量。</param> /// <param name="Color">边框颜色,以 RGB 值表示。</param> public dynamic BorderAround(XlLineStyle? LineStyle = null, XlBorderWeight Weight = XlBorderWeight.xlThin, XlColorIndex ColorIndex = XlColorIndex.xlColorIndexAutomatic, int? Color = null) { _objaParameters = new object[4] { LineStyle == null ? System.Type.Missing : LineStyle, Weight, ColorIndex, Color == null ? System.Type.Missing : Color }; return _objRange.GetType().InvokeMember("BorderAround", BindingFlags.InvokeMethod, null, _objRange, _objaParameters); }
/// <summary> /// 指定された範囲を枠として罫線を引きます。 /// </summary> /// <param name="startRow">開始行インデックス</param> /// <param name="startColumn">開始列インデックス</param> /// <param name="endRow">終了行インデックス</param> /// <param name="endColumn">終了列インデックス</param> /// <param name="top">上罫線</param> /// <param name="left">左罫線</param> /// <param name="right">右罫線</param> /// <param name="bottom">下罫線</param> /// <remarks> /// 罫線に<see cref="Microsoft.Office.Interop.Excel.XlLineStyle#xlLineStyleNone"/>を定義するとその位置に罫線は引きません。 /// </remarks> public void DrowLines(int startRow, int startColumn, int endRow, int endColumn, XlLineStyle top = XlLineStyle.xlLineStyleNone, XlLineStyle left = XlLineStyle.xlLineStyleNone, XlLineStyle right = XlLineStyle.xlLineStyleNone, XlLineStyle bottom = XlLineStyle.xlLineStyleNone) { // オブジェクト参照カウンタの解放の為、使い回しは行わない Range range1 = null; Range range2 = null; try { this.sheet = workbook.Sheets[currentSheetIndex] as Worksheet; range1 = this.sheet.Cells[startRow, startColumn] as Range; range2 = this.sheet.Cells[endRow, endColumn] as Range; if (range1 == null) return; DrowLines(range1, range2, top, left, right, bottom); } finally { // COMオブジェクトを削除し参照カウンタをデクリメントする ReleaseComObject(range1); ReleaseComObject(range2); } }
/// <summary> /// 指定された範囲を枠として罫線を引きます。 /// </summary> /// <param name="startCell">セル名<c>A1</c>など</param> /// <param name="endCell">セル名<c>A1</c>など</param> /// <param name="top">上罫線</param> /// <param name="left">左罫線</param> /// <param name="right">右罫線</param> /// <param name="bottom">下罫線</param> /// <remarks> /// 罫線に<see cref="Microsoft.Office.Interop.Excel.XlLineStyle#xlLineStyleNone"/>を定義するとその位置に罫線は引きません。 /// </remarks> public void DrowLines(string startCell, string endCell, XlLineStyle top = XlLineStyle.xlLineStyleNone, XlLineStyle left = XlLineStyle.xlLineStyleNone, XlLineStyle right = XlLineStyle.xlLineStyleNone, XlLineStyle bottom = XlLineStyle.xlLineStyleNone) { // オブジェクト参照カウンタの解放の為、使い回しは行わない Range range1 = null; Range range2 = null; try { this.sheet = workbook.Sheets[currentSheetIndex] as Worksheet; range1 = this.sheet.Cells.get_Range(startCell, Type.Missing); range2 = this.sheet.Cells.get_Range(endCell, Type.Missing); if (range1 == null) return; DrowLines(range1, range2, top, left, right, bottom); } finally { // COMオブジェクトを削除し参照カウンタをデクリメントする ReleaseComObject(range1); ReleaseComObject(range2); } }
/// <summary> /// 指定された範囲を枠として罫線を引きます。 /// </summary> /// <param name="startRange">開始範囲</param> /// <param name="endRange">終了範囲</param> /// <param name="endRow">終了行インデックス</param> /// <param name="endColumn">終了列インデックス</param> /// <param name="top">上罫線</param> /// <param name="left">左罫線</param> /// <param name="right">右罫線</param> /// <param name="bottom">下罫線</param> /// <remarks> /// 罫線に<see cref="Microsoft.Office.Interop.Excel.XlLineStyle#xlLineStyleNone"/>を定義するとその位置に罫線は引きません。 /// </remarks> private void DrowLines(Range startRange, Range endRange, XlLineStyle top = XlLineStyle.xlLineStyleNone, XlLineStyle left = XlLineStyle.xlLineStyleNone, XlLineStyle right = XlLineStyle.xlLineStyleNone, XlLineStyle bottom = XlLineStyle.xlLineStyleNone) { // オブジェクト参照カウンタの解放の為、使い回しは行わない Range range1 = null; try { // 終了範囲が存在しない場合は自分で開始範囲として処理する。 if (endRange == null) endRange = startRange; this.sheet = workbook.Sheets[currentSheetIndex] as Worksheet; range1 = this.sheet.Cells.get_Range(startRange, endRange); if (range1 == null) return; if (top != XlLineStyle.xlLineStyleNone) range1.Borders.get_Item(XlBordersIndex.xlEdgeTop).LineStyle = top; if (left != XlLineStyle.xlLineStyleNone) range1.Borders.get_Item(XlBordersIndex.xlEdgeLeft).LineStyle = left; if (right != XlLineStyle.xlLineStyleNone) range1.Borders.get_Item(XlBordersIndex.xlEdgeRight).LineStyle = right; if (bottom != XlLineStyle.xlLineStyleNone) range1.Borders.get_Item(XlBordersIndex.xlEdgeBottom).LineStyle = bottom; } finally { // COMオブジェクトを削除し参照カウンタをデクリメントする ReleaseComObject(range1); } }
public void SetChartSeriesCollectionBorderLineStyle(Chart chart, int seriesIndex, XlLineStyle lineStyle) { chart.SeriesCollection(seriesIndex).Border.LineStyle = lineStyle; }
public void SetBordersEdge(Range range_0, BordersEdge bordersEdge_0, BordersLineStyle bordersLineStyle_0, BordersWeight bordersWeight_0) { range_0.Select(); Border borders = null; switch (bordersEdge_0) { case BordersEdge.xlLineStyleNone: { range_0.Borders[XlBordersIndex.xlDiagonalDown].LineStyle = XlLineStyle.xlLineStyleNone; range_0.Borders[XlBordersIndex.xlDiagonalUp].LineStyle = XlLineStyle.xlLineStyleNone; range_0.Borders[XlBordersIndex.xlEdgeLeft].LineStyle = XlLineStyle.xlLineStyleNone; range_0.Borders[XlBordersIndex.xlEdgeTop].LineStyle = XlLineStyle.xlLineStyleNone; range_0.Borders[XlBordersIndex.xlEdgeBottom].LineStyle = XlLineStyle.xlLineStyleNone; range_0.Borders[XlBordersIndex.xlEdgeRight].LineStyle = XlLineStyle.xlLineStyleNone; range_0.Borders[XlBordersIndex.xlInsideVertical].LineStyle = XlLineStyle.xlLineStyleNone; range_0.Borders[XlBordersIndex.xlInsideHorizontal].LineStyle = XlLineStyle.xlLineStyleNone; break; } case BordersEdge.xlLeft: { borders = range_0.Borders[XlBordersIndex.xlEdgeLeft]; break; } case BordersEdge.xlRight: { borders = range_0.Borders[XlBordersIndex.xlEdgeRight]; break; } case BordersEdge.xlTop: { borders = range_0.Borders[XlBordersIndex.xlEdgeTop]; break; } case BordersEdge.xlBottom: { borders = range_0.Borders[XlBordersIndex.xlEdgeBottom]; break; } case BordersEdge.xlDiagonalDown: { borders = range_0.Borders[XlBordersIndex.xlDiagonalDown]; break; } case BordersEdge.xlDiagonalUp: { borders = range_0.Borders[XlBordersIndex.xlDiagonalUp]; break; } case BordersEdge.xlInsideHorizontal: { borders = range_0.Borders[XlBordersIndex.xlInsideHorizontal]; break; } case BordersEdge.xlInsideVertical: { borders = range_0.Borders[XlBordersIndex.xlInsideVertical]; break; } } if (borders != null) { XlLineStyle xlLineStyle = XlLineStyle.xlContinuous; switch (bordersLineStyle_0) { case BordersLineStyle.xlContinuous: { xlLineStyle = XlLineStyle.xlContinuous; break; } case BordersLineStyle.xlDash: { xlLineStyle = XlLineStyle.xlDash; break; } case BordersLineStyle.xlDashDot: { xlLineStyle = XlLineStyle.xlDashDot; break; } case BordersLineStyle.xlDashDotDot: { xlLineStyle = XlLineStyle.xlDashDotDot; break; } case BordersLineStyle.xlDot: { xlLineStyle = XlLineStyle.xlDot; break; } case BordersLineStyle.xlDouble: { xlLineStyle = XlLineStyle.xlDouble; break; } case BordersLineStyle.xlLineStyleNone: { xlLineStyle = XlLineStyle.xlLineStyleNone; break; } case BordersLineStyle.xlSlantDashDot: { xlLineStyle = XlLineStyle.xlSlantDashDot; break; } } try { borders.LineStyle = xlLineStyle; } catch { } XlBorderWeight xlBorderWeight = XlBorderWeight.xlThin; switch (bordersWeight_0) { case BordersWeight.xlHairline: { xlBorderWeight = XlBorderWeight.xlHairline; break; } case BordersWeight.xlMedium: { xlBorderWeight = XlBorderWeight.xlMedium; break; } case BordersWeight.xlThick: { xlBorderWeight = XlBorderWeight.xlThick; break; } case BordersWeight.xlThin: { xlBorderWeight = XlBorderWeight.xlThin; break; } } borders.Weight = xlBorderWeight; } }
/// <summary> /// Toggles a border of the specified cells and applies the settings if it is toggled on. /// </summary> /// <param name="cellSelection">Indicates the cells to be changed. Works just like Excel. Example: "A:A,1:1,A2:B3,F4,F5"</param> /// <param name="borderToToggle">Indicates the border that will be toggled.</param> /// <param name="weightToSet">Indicates the weight the border will be set to if it is being toggled on.</param> /// <param name="styleToSet">Indicates the line style the border will be set to if it is being toggled on.</param> public void SetBorders(string cellSelection, XlBordersIndex bordersToToggle, Microsoft.Office.Interop.Excel.XlBorderWeight weightToSet, XlLineStyle styleToSet) { SetBorders(ReportGlobals.defaultWorkbookName, ReportGlobals.defaultSheetIndex, cellSelection, bordersToToggle, weightToSet, styleToSet); }
public void SetBorder(Range range, XlBordersIndex index, XlLineStyle lineStyle, XlBorderWeight weight) { range.Borders[index].LineStyle = lineStyle; range.Borders[index].Weight = weight; }
/// <summary> /// SetBordersEdge 设置指定范围边框(左、顶、右、底、往右下对角线、往右上对角线、内部水平线、内部垂直线、无线)线,并可指定线条的样式(无、虚线、点线等)及线粗细 /// </summary> /// <param name="p_Range">单元格</param> /// <param name="p_BordersEdge">边框枚举</param> /// <param name="p_BordersLineStyle">边框样式</param> /// <param name="p_BordersWeight">线条宽度</param> protected void SetBordersEdge(Range p_Range, BordersEdge p_BordersEdge, BordersLineStyle p_BordersLineStyle, BordersWeight p_BordersWeight) { p_Range.Select(); Border border = null; switch (p_BordersEdge) { //左右顶底的线 case BordersEdge.xlLeft: border = p_Range.Borders[XlBordersIndex.xlEdgeLeft]; break; case BordersEdge.xlRight: border = p_Range.Borders[XlBordersIndex.xlEdgeRight]; break; case BordersEdge.xlTop: border = p_Range.Borders[XlBordersIndex.xlEdgeTop]; break; case BordersEdge.xlBottom: border = p_Range.Borders[XlBordersIndex.xlEdgeBottom]; break; //对角线 case BordersEdge.xlDiagonalDown: border = p_Range.Borders[XlBordersIndex.xlDiagonalDown]; break; case BordersEdge.xlDiagonalUp: border = p_Range.Borders[XlBordersIndex.xlDiagonalUp]; break; //边框内部是横竖线(不包括边框) case BordersEdge.xlInsideHorizontal: border = p_Range.Borders[XlBordersIndex.xlInsideHorizontal]; break; case BordersEdge.xlInsideVertical: border = p_Range.Borders[XlBordersIndex.xlInsideVertical]; break; case BordersEdge.xlLineStyleNone: //所先范围内所有线都没有 p_Range.Borders[XlBordersIndex.xlDiagonalDown].LineStyle = XlLineStyle.xlLineStyleNone; //xlNone p_Range.Borders[XlBordersIndex.xlDiagonalUp].LineStyle = XlLineStyle.xlLineStyleNone; p_Range.Borders[XlBordersIndex.xlEdgeLeft].LineStyle = XlLineStyle.xlLineStyleNone; p_Range.Borders[XlBordersIndex.xlEdgeTop].LineStyle = XlLineStyle.xlLineStyleNone; p_Range.Borders[XlBordersIndex.xlEdgeBottom].LineStyle = XlLineStyle.xlLineStyleNone; p_Range.Borders[XlBordersIndex.xlEdgeRight].LineStyle = XlLineStyle.xlLineStyleNone; p_Range.Borders[XlBordersIndex.xlInsideVertical].LineStyle = XlLineStyle.xlLineStyleNone; p_Range.Borders[XlBordersIndex.xlInsideHorizontal].LineStyle = XlLineStyle.xlLineStyleNone; break; } if (border != null) { //XlLineStyle XlLineStyle mXlLineStyle = XlLineStyle.xlContinuous; switch (p_BordersLineStyle) { case BordersLineStyle.xlContinuous: mXlLineStyle = XlLineStyle.xlContinuous; break; case BordersLineStyle.xlDash: mXlLineStyle = XlLineStyle.xlDash; break; case BordersLineStyle.xlDashDot: mXlLineStyle = XlLineStyle.xlDashDot; break; case BordersLineStyle.xlDashDotDot: mXlLineStyle = XlLineStyle.xlDashDotDot; break; case BordersLineStyle.xlDot: mXlLineStyle = XlLineStyle.xlDot; break; case BordersLineStyle.xlDouble: mXlLineStyle = XlLineStyle.xlDouble; break; case BordersLineStyle.xlLineStyleNone: mXlLineStyle = XlLineStyle.xlLineStyleNone; break; case BordersLineStyle.xlSlantDashDot: mXlLineStyle = XlLineStyle.xlSlantDashDot; break; } border.LineStyle = mXlLineStyle; //XlBorderWeight XlBorderWeight mXlBorderWeight = XlBorderWeight.xlThin; switch (p_BordersWeight) { case BordersWeight.xlHairline: mXlBorderWeight = XlBorderWeight.xlHairline; break; case BordersWeight.xlMedium: mXlBorderWeight = XlBorderWeight.xlMedium; break; case BordersWeight.xlThick: mXlBorderWeight = XlBorderWeight.xlThick; break; case BordersWeight.xlThin: mXlBorderWeight = XlBorderWeight.xlThin; break; } border.Weight = mXlBorderWeight; }//End IF }
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"); } }