From eb21d243dc3ba114cb2cc2a69d8635f4689f073c Mon Sep 17 00:00:00 2001 From: Ramya Sivakumar Date: Mon, 1 Dec 2025 12:18:16 +0530 Subject: [PATCH 1/2] 991689-Merged-Cellstyle --- Document-Processing-toc.html | 3 + ...to-apply-border-styles-for-merged-cells.md | 101 ++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 Document-Processing/Excel/Excel-Library/NET/faqs/how-to-apply-border-styles-for-merged-cells.md diff --git a/Document-Processing-toc.html b/Document-Processing-toc.html index 60a088ae2..60b187ed8 100644 --- a/Document-Processing-toc.html +++ b/Document-Processing-toc.html @@ -5891,6 +5891,9 @@
  • How to extract embedded OLE files from an Excel workbook as streams?
  • +
  • + How to apply border styles for merged cells? +
  • diff --git a/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-apply-border-styles-for-merged-cells.md b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-apply-border-styles-for-merged-cells.md new file mode 100644 index 000000000..9242fa8d5 --- /dev/null +++ b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-apply-border-styles-for-merged-cells.md @@ -0,0 +1,101 @@ +--- +title: Apply border styles to merged cells in Excel | XlsIO +description: Learn how to apply border styles to merged cells in Excel using the Syncfusion .NET Excel (XlsIO) library. +platform: document-processing +control: XlsIO +documentation: UG +--- + +# How to apply border styles for merged cells? + +As per the MS Excel UI Behavior, while applying the styles to the single cell in the merged region, then it will apply only to that single cell. So please use the **MergeArea** property to apply the styles to the entire merged region. + +The following examples show how to apply border styles for merged cells in C# (cross-platform and Windows-specific) and VB.NET. + +{% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/XlsIO-Examples/master/FAQ/Border%20styles%20for%20merged%20cells/.NET/Borderstylesformergedcells/Borderstylesformergedcells/Program.cs,180" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + IWorkbook workbook = application.Workbooks.Open("../../../Data/Input.xlsx"); + IWorksheet worksheet = workbook.Worksheets[0]; + + # region Creating a new style + IStyle style = workbook.Styles.Add("NewStyle"); + + style.Borders[ExcelBordersIndex.EdgeLeft].LineStyle = ExcelLineStyle.Thick; + style.Borders[ExcelBordersIndex.EdgeRight].LineStyle = ExcelLineStyle.Thick; + style.Borders[ExcelBordersIndex.EdgeTop].LineStyle = ExcelLineStyle.Thick; + style.Borders[ExcelBordersIndex.EdgeBottom].LineStyle = ExcelLineStyle.Thick; + style.Borders.Color = ExcelKnownColors.Red; + + style.Font.Bold = true; + style.Font.Color = ExcelKnownColors.Green; + style.Font.Size = 24; + #endregion + + //Applying style for merged region + worksheet.Range[2, 1].MergeArea.CellStyle = style; + + workbook.SaveAs("../../../Output/MergeArea_Style.xlsx"); +} +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + IWorkbook workbook = application.Workbooks.Open("../../Data/Input.xlsx"); + IWorksheet worksheet = workbook.Worksheets[0]; + + # region Creating a new style + IStyle style = workbook.Styles.Add("NewStyle"); + + style.Borders[ExcelBordersIndex.EdgeLeft].LineStyle = ExcelLineStyle.Thick; + style.Borders[ExcelBordersIndex.EdgeRight].LineStyle = ExcelLineStyle.Thick; + style.Borders[ExcelBordersIndex.EdgeTop].LineStyle = ExcelLineStyle.Thick; + style.Borders[ExcelBordersIndex.EdgeBottom].LineStyle = ExcelLineStyle.Thick; + style.Borders.Color = ExcelKnownColors.Red; + + style.Font.Bold = true; + style.Font.Color = ExcelKnownColors.Green; + style.Font.Size = 24; + #endregion + + //Applying style for merged region + worksheet.Range[2,1].MergeArea.CellStyle = style; + + workbook.SaveAs("../../Output/MergeArea_Style.xlsx"); +} +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} + Using excelEngine As New ExcelEngine() + Dim application As IApplication = excelEngine.Excel + application.DefaultVersion = ExcelVersion.Xlsx + + Dim workbook As IWorkbook = application.Workbooks.Open("../../Data/Input.xlsx") + Dim worksheet As IWorksheet = workbook.Worksheets(0) + + ' Creating a new style + Dim style As IStyle = workbook.Styles.Add("NewStyle") + style.Borders(ExcelBordersIndex.EdgeLeft).LineStyle = ExcelLineStyle.Thick + style.Borders(ExcelBordersIndex.EdgeRight).LineStyle = ExcelLineStyle.Thick + style.Borders(ExcelBordersIndex.EdgeTop).LineStyle = ExcelLineStyle.Thick + style.Borders(ExcelBordersIndex.EdgeBottom).LineStyle = ExcelLineStyle.Thick + style.Borders.Color = ExcelKnownColors.Red + style.Font.Bold = True + style.Font.Color = ExcelKnownColors.Green + style.Font.Size = 24 + + ' Applying style for merged region + worksheet.Range(2, 1).MergeArea.CellStyle = style + + workbook.SaveAs("../../Output/MergeArea_Style.xlsx") + End Using +{% endhighlight %} +{% endtabs %} + +A complete working example to apply border styles for merged cells using C# is present on this GitHub page. From e8d7881743ae865a818c2493af18f157325ac2b7 Mon Sep 17 00:00:00 2001 From: Ramya Sivakumar Date: Mon, 1 Dec 2025 12:53:15 +0530 Subject: [PATCH 2/2] 991689-Merged-Cellstyle --- .../NET/faqs/how-to-apply-border-styles-for-merged-cells.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-apply-border-styles-for-merged-cells.md b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-apply-border-styles-for-merged-cells.md index 9242fa8d5..690d0f630 100644 --- a/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-apply-border-styles-for-merged-cells.md +++ b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-apply-border-styles-for-merged-cells.md @@ -1,5 +1,5 @@ --- -title: Apply border styles to merged cells in Excel | XlsIO +title: Apply border styles to merged cells in Excel | Syncfusion description: Learn how to apply border styles to merged cells in Excel using the Syncfusion .NET Excel (XlsIO) library. platform: document-processing control: XlsIO @@ -8,7 +8,7 @@ documentation: UG # How to apply border styles for merged cells? -As per the MS Excel UI Behavior, while applying the styles to the single cell in the merged region, then it will apply only to that single cell. So please use the **MergeArea** property to apply the styles to the entire merged region. +As per the Microsoft Excel UI Behavior, while applying the styles to the single cell in the merged region, then it will apply only to that single cell. So please use the **MergeArea** property to apply the styles to the entire merged region. The following examples show how to apply border styles for merged cells in C# (cross-platform and Windows-specific) and VB.NET.