简体   繁体   English

在Excel C#上的多个单元格周围添加边框

[英]add borders around multiple cells on excel c#

I am currently using Microsoft.Office.Core; 我当前正在使用Microsoft.Office.Core; and using Excel = Microsoft.Office.Interop.Excel; 并使用Excel = Microsoft.Office.Interop.Excel; to export my data from windows form to excel to export data from windows form c# to excel 从Windows窗体将数据导出到excel从Windows窗体C#导出数据到excel

Is there any chance to add a border on selected cells like How i need it to be 有没有机会在所选单元格上添加边框,例如我需要

Sure, heres a function I made for the same thing 当然,这是我为同一件事所做的功能

/// <summary>
/// Puts a border around range
/// </summary>
/// <param name="ws">Excel worksheet</param>
/// <param name="r1">First Row</param>
/// <param name="c1">First Column</param>
/// <param name="r2">Last Row</param>
/// <param name="c2">Last Column</param>
/// <param name="weight">Border Brush Weight</param>
public void BorderRange(Worksheet ws, int r1, int c1, int r2, int c2, XlBorderWeight weight = XlBorderWeight.xlThin)
{
    Range r = ws.Range[ws.Cells[r1, c1], ws.Cells[r2, c2]];
    r.BorderAround2(Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous, weight);
}

You'll need to call it a few times to put the borders round the ranges you need. 您需要多次调用它才能使边界围绕所需的范围。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM