Skip to content

Commit 77a930b

Browse files
authored
Merge pull request #1974 from syncfusion-content/991689-Cellstyle
Need to move the changes for new hotfix
2 parents 953b2b4 + fd9c27a commit 77a930b

5 files changed

+382
-0
lines changed

Document-Processing-toc.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6074,6 +6074,18 @@
60746074
<li>
60756075
<a href="/document-processing/excel/excel-library/net/faqs/how-to-apply-number-formatting-to-an-entire-column-in-Excel">How to apply number formatting to an entire column in Excel?</a>
60766076
</li>
6077+
<li>
6078+
<a href="/document-processing/excel/excel-library/net/faqs/how-to-apply-border-styles-for-merged-cells">How to apply border styles for merged cells?</a>
6079+
</li>
6080+
<li>
6081+
<a href="/document-processing/excel/excel-library/net/faqs/how-to-apply-a-number-format-to-an-entire-row-in-Excel">How to apply a number format to an entire row in Excel?</a>
6082+
</li>
6083+
<li>
6084+
<a href="/document-processing/excel/excel-library/net/faqs/how-to-apply-superscript-for-certain-text-in-the-cell">How to apply superscript to certain text in a cell?</a>
6085+
</li>
6086+
<li>
6087+
<a href="/document-processing/excel/excel-library/net/faqs/how-to-set-the-first-item-in-a-list-as-the-default-selected-value-in-an-Excel-file">How to set the first item in a list as the default value in an Excel?</a>
6088+
</li>
60776089
</ul>
60786090
</li>
60796091
</ul>
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
title: Apply a number format to an entire row in Excel | Syncfusion
3+
description: Learn how to apply a number format to an entire row in Excel using the Syncfusion .NET Excel (XlsIO) library.
4+
platform: document-processing
5+
control: XlsIO
6+
documentation: UG
7+
---
8+
9+
# How to apply a number format to an entire row in Excel?
10+
11+
The following examples illustrate how to apply a number format to an entire row in Excel in C# (cross-platform and Windows-specific) and VB.NET.
12+
13+
{% tabs %}
14+
{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/XlsIO-Examples/master/FAQ/Number%20format%20for%20entire%20row/.NET/Numberformatforentirerow/Numberformatforentirerow/Program.cs,180" %}
15+
using (ExcelEngine excelEngine = new ExcelEngine())
16+
{
17+
IApplication application = excelEngine.Excel;
18+
application.DefaultVersion = ExcelVersion.Xlsx;
19+
IWorkbook workbook = application.Workbooks.Create(1);
20+
IWorksheet worksheet = workbook.Worksheets[0];
21+
22+
worksheet["A1"].Number = 1000.500;
23+
worksheet["B1"].Number = 1234;
24+
worksheet["C1"].Number = 54321.500;
25+
worksheet["D1"].Number = .500;
26+
27+
worksheet["A1"].EntireRow.NumberFormat = "#,##0.0000";
28+
29+
workbook.SaveAs("../../../Output/NumberFormats.xlsx");
30+
}
31+
{% endhighlight %}
32+
33+
{% highlight c# tabtitle="C# [Windows-specific]" %}
34+
using (ExcelEngine excelEngine = new ExcelEngine())
35+
{
36+
IApplication application = excelEngine.Excel;
37+
application.DefaultVersion = ExcelVersion.Xlsx;
38+
IWorkbook workbook = application.Workbooks.Create(1);
39+
IWorksheet worksheet = workbook.Worksheets[0];
40+
41+
worksheet["A1"].Number = 1000.500;
42+
worksheet["B1"].Number = 1234;
43+
worksheet["C1"].Number = 54321.500;
44+
worksheet["D1"].Number = .500;
45+
46+
worksheet["A1"].EntireRow.NumberFormat = "#,##0.0000";
47+
48+
workbook.SaveAs("../../Output/NumberFormats.xlsx");
49+
}
50+
{% endhighlight %}
51+
52+
{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
53+
Using excelEngine As New ExcelEngine()
54+
Dim application As IApplication = excelEngine.Excel
55+
application.DefaultVersion = ExcelVersion.Xlsx
56+
57+
Dim workbook As IWorkbook = application.Workbooks.Create(1)
58+
Dim worksheet As IWorksheet = workbook.Worksheets(0)
59+
60+
worksheet("A1").Number = 1000.5
61+
worksheet("B1").Number = 1234
62+
worksheet("C1").Number = 54321.5
63+
worksheet("D1").Number = 0.5
64+
65+
worksheet("A1").EntireRow.NumberFormat = "#,##0.0000"
66+
67+
workbook.SaveAs("../../Output/NumberFormats.xlsx")
68+
End Using
69+
{% endhighlight %}
70+
{% endtabs %}
71+
72+
A complete working example to demonstrate how to apply a number format to an entire row in Excel using C# is present on <a href="https://github.com/SyncfusionExamples/XlsIO-Examples/tree/master/FAQ/Number%20format%20for%20entire%20row/.NET/Numberformatforentirerow">this GitHub page</a>.
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
---
2+
title: Apply border styles to merged cells in Excel | Syncfusion
3+
description: Learn how to apply border styles to merged cells in Excel using the Syncfusion .NET Excel (XlsIO) library.
4+
platform: document-processing
5+
control: XlsIO
6+
documentation: UG
7+
---
8+
9+
# How to apply border styles for merged cells?
10+
11+
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.
12+
13+
The following examples show how to apply border styles for merged cells in C# (cross-platform and Windows-specific) and VB.NET.
14+
15+
{% tabs %}
16+
{% 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" %}
17+
using (ExcelEngine excelEngine = new ExcelEngine())
18+
{
19+
IApplication application = excelEngine.Excel;
20+
application.DefaultVersion = ExcelVersion.Xlsx;
21+
IWorkbook workbook = application.Workbooks.Open("../../../Data/Input.xlsx");
22+
IWorksheet worksheet = workbook.Worksheets[0];
23+
24+
# region Creating a new style
25+
IStyle style = workbook.Styles.Add("NewStyle");
26+
27+
style.Borders[ExcelBordersIndex.EdgeLeft].LineStyle = ExcelLineStyle.Thick;
28+
style.Borders[ExcelBordersIndex.EdgeRight].LineStyle = ExcelLineStyle.Thick;
29+
style.Borders[ExcelBordersIndex.EdgeTop].LineStyle = ExcelLineStyle.Thick;
30+
style.Borders[ExcelBordersIndex.EdgeBottom].LineStyle = ExcelLineStyle.Thick;
31+
style.Borders.Color = ExcelKnownColors.Red;
32+
33+
style.Font.Bold = true;
34+
style.Font.Color = ExcelKnownColors.Green;
35+
style.Font.Size = 24;
36+
#endregion
37+
38+
//Applying style for merged region
39+
worksheet.Range[2, 1].MergeArea.CellStyle = style;
40+
41+
workbook.SaveAs("../../../Output/MergeArea_Style.xlsx");
42+
}
43+
{% endhighlight %}
44+
45+
{% highlight c# tabtitle="C# [Windows-specific]" %}
46+
using (ExcelEngine excelEngine = new ExcelEngine())
47+
{
48+
IApplication application = excelEngine.Excel;
49+
application.DefaultVersion = ExcelVersion.Xlsx;
50+
IWorkbook workbook = application.Workbooks.Open("../../Data/Input.xlsx");
51+
IWorksheet worksheet = workbook.Worksheets[0];
52+
53+
# region Creating a new style
54+
IStyle style = workbook.Styles.Add("NewStyle");
55+
56+
style.Borders[ExcelBordersIndex.EdgeLeft].LineStyle = ExcelLineStyle.Thick;
57+
style.Borders[ExcelBordersIndex.EdgeRight].LineStyle = ExcelLineStyle.Thick;
58+
style.Borders[ExcelBordersIndex.EdgeTop].LineStyle = ExcelLineStyle.Thick;
59+
style.Borders[ExcelBordersIndex.EdgeBottom].LineStyle = ExcelLineStyle.Thick;
60+
style.Borders.Color = ExcelKnownColors.Red;
61+
62+
style.Font.Bold = true;
63+
style.Font.Color = ExcelKnownColors.Green;
64+
style.Font.Size = 24;
65+
#endregion
66+
67+
//Applying style for merged region
68+
worksheet.Range[2,1].MergeArea.CellStyle = style;
69+
70+
workbook.SaveAs("../../Output/MergeArea_Style.xlsx");
71+
}
72+
{% endhighlight %}
73+
74+
{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
75+
Using excelEngine As New ExcelEngine()
76+
Dim application As IApplication = excelEngine.Excel
77+
application.DefaultVersion = ExcelVersion.Xlsx
78+
79+
Dim workbook As IWorkbook = application.Workbooks.Open("../../Data/Input.xlsx")
80+
Dim worksheet As IWorksheet = workbook.Worksheets(0)
81+
82+
' Creating a new style
83+
Dim style As IStyle = workbook.Styles.Add("NewStyle")
84+
style.Borders(ExcelBordersIndex.EdgeLeft).LineStyle = ExcelLineStyle.Thick
85+
style.Borders(ExcelBordersIndex.EdgeRight).LineStyle = ExcelLineStyle.Thick
86+
style.Borders(ExcelBordersIndex.EdgeTop).LineStyle = ExcelLineStyle.Thick
87+
style.Borders(ExcelBordersIndex.EdgeBottom).LineStyle = ExcelLineStyle.Thick
88+
style.Borders.Color = ExcelKnownColors.Red
89+
style.Font.Bold = True
90+
style.Font.Color = ExcelKnownColors.Green
91+
style.Font.Size = 24
92+
93+
' Applying style for merged region
94+
worksheet.Range(2, 1).MergeArea.CellStyle = style
95+
96+
workbook.SaveAs("../../Output/MergeArea_Style.xlsx")
97+
End Using
98+
{% endhighlight %}
99+
{% endtabs %}
100+
101+
A complete working example to apply border styles for merged cells using C# is present on <a href="https://github.com/SyncfusionExamples/XlsIO-Examples/tree/master/FAQ/Border%20styles%20for%20merged%20cells/.NET/Borderstylesformergedcells">this GitHub page</a>.
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
---
2+
title: Apply Superscript to Text in an Excel Cell | Syncfusion
3+
description: Learn how to apply superscript to specific text in an Excel cell without affecting existing styles using the Syncfusion .NET Excel library (XlsIO).
4+
platform: document-processing
5+
control: XlsIO
6+
documentation: UG
7+
---
8+
9+
# How to apply superscript to certain text in a cell?
10+
11+
The following code example illustrates how to apply superscript to certain text in a cell without affecting the existing style in C# (cross-platform and Windows-specific) and VB.NET.
12+
{% tabs %}
13+
{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/XlsIO-Examples/master/FAQ/Superscript/.NET/Superscript%20for%20certain%20texts/SuperscriptForCertainTexts/Program.cs,180" %}
14+
using (ExcelEngine excelEngine = new ExcelEngine())
15+
{
16+
IApplication application = excelEngine.Excel;
17+
application.DefaultVersion = ExcelVersion.Xlsx;
18+
//Create a workbook
19+
IWorkbook workbook = application.Workbooks.Open("../../../Data/Sample.xlsx");
20+
IWorksheet worksheet = workbook.Worksheets[0];
21+
22+
//Add Text
23+
IRange range = worksheet.Range["A1"];
24+
IRichTextString richText = range.RichText;
25+
26+
IFont superScript = workbook.CreateFont();
27+
superScript.Size = richText.GetFont(6).Size;
28+
superScript.FontName = richText.GetFont(6).FontName;
29+
superScript.Color = richText.GetFont(6).Color;
30+
superScript.Superscript = true;
31+
richText.SetFont(6, 6, superScript);
32+
33+
34+
//Save the workbook to disk in xlsx format
35+
workbook.SaveAs("../../../Output/Output.xlsx");
36+
}
37+
{% endhighlight %}
38+
39+
{% highlight c# tabtitle="C# [Windows-specific]" %}
40+
using (ExcelEngine excelEngine = new ExcelEngine())
41+
{
42+
IApplication application = excelEngine.Excel;
43+
application.DefaultVersion = ExcelVersion.Xlsx;
44+
//Create a workbook
45+
IWorkbook workbook = application.Workbooks.Open("../../Data/Sample.xlsx");
46+
IWorksheet worksheet = workbook.Worksheets[0];
47+
48+
//Add Text
49+
IRange range = worksheet.Range["A1"];
50+
IRichTextString richText = range.RichText;
51+
52+
IFont superScript = workbook.CreateFont();
53+
superScript.Size = richText.GetFont(6).Size;
54+
superScript.FontName = richText.GetFont(6).FontName;
55+
superScript.Color = richText.GetFont(6).Color;
56+
superScript.Superscript = true;
57+
richText.SetFont(6, 6, superScript);
58+
59+
60+
//Save the workbook to disk in xlsx format
61+
workbook.SaveAs("../../Output/Output.xlsx");
62+
}
63+
{% endhighlight %}
64+
65+
{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
66+
Using excelEngine As New ExcelEngine()
67+
Dim application As IApplication = excelEngine.Excel
68+
application.DefaultVersion = ExcelVersion.Xlsx
69+
'Create a workbook
70+
Dim workbook As IWorkbook = application.Workbooks.Open("../../Data/Sample.xlsx")
71+
Dim worksheet As IWorksheet = workbook.Worksheets(0)
72+
73+
'Add Text
74+
Dim range As IRange = worksheet.Range("A1")
75+
Dim richText As IRichTextString = range.RichText
76+
77+
Dim superScript As IFont = workbook.CreateFont()
78+
superScript.Size = richText.GetFont(6).Size
79+
superScript.FontName = richText.GetFont(6).FontName
80+
superScript.Color = richText.GetFont(6).Color
81+
superScript.Superscript = True
82+
richText.SetFont(6, 6, superScript)
83+
84+
'Save the workbook to disk in xlsx format
85+
workbook.SaveAs("../../Output/Output.xlsx")
86+
End Using
87+
{% endhighlight %}
88+
{% endtabs %}
89+
90+
A complete working example to apply superscript to certain text in a cell using C# is present on <a href="https://github.com/SyncfusionExamples/XlsIO-Examples/tree/master/FAQ/Superscript/.NET/Superscript%20for%20certain%20texts">this GitHub page</a>.
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
---
2+
title: Set Default List Item in Excel Data Validation | Syncfusion
3+
description: Learn to programmatically select the first item in an Excel data-validation list with Syncfusion’s .NET Excel library (XlsIO) using C# and VB.NET.
4+
platform: document-processing
5+
control: XlsIO
6+
documentation: UG
7+
---
8+
9+
# How to set the first item in a list as the default value in an Excel?
10+
11+
You can programmatically make the first item in a data-validation list the default selection in an Excel file by using Syncfusion XlsIO. The following examples in C# (cross-platform and Windows-specific) and VB.NET demonstrate the process.
12+
13+
{% tabs %}
14+
{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/XlsIO-Examples/master/FAQ/List%20Validation/.NET/List%20Validation/List%20Validation/Program.cs,180" %}
15+
using (ExcelEngine excelEngine = new ExcelEngine())
16+
{
17+
IApplication application = excelEngine.Excel;
18+
application.DefaultVersion = ExcelVersion.Xlsx;
19+
IWorkbook workbook = application.Workbooks.Create(1);
20+
IWorksheet worksheet = workbook.Worksheets[0];
21+
22+
worksheet["A1"].Value = "ListItem1";
23+
worksheet["A2"].Value = "ListItem2";
24+
worksheet["A3"].Value = "ListItem3";
25+
worksheet["A4"].Value = "ListItem4";
26+
27+
worksheet.Range["C1"].Text = "Data Validation List in C3";
28+
worksheet.Range["C1"].AutofitColumns();
29+
30+
//Data validation for the list
31+
IDataValidation listValidation = worksheet.Range["C3"].DataValidation;
32+
listValidation.DataRange = worksheet.Range["A1:A4"];
33+
34+
//Set the first item in the list as default value
35+
worksheet.Range["C3"].Value = worksheet.Range["C3"].DataValidation.DataRange.Cells[0].Value;
36+
37+
38+
#region Save
39+
//Saving the workbook
40+
workbook.SaveAs("../../../Output/ListValidation.xlsx");
41+
#endregion
42+
}
43+
{% endhighlight %}
44+
45+
{% highlight c# tabtitle="C# [Windows-specific]" %}
46+
using (ExcelEngine excelEngine = new ExcelEngine())
47+
{
48+
IApplication application = excelEngine.Excel;
49+
application.DefaultVersion = ExcelVersion.Xlsx;
50+
IWorkbook workbook = application.Workbooks.Create(1);
51+
IWorksheet worksheet = workbook.Worksheets[0];
52+
53+
worksheet["A1"].Value = "ListItem1";
54+
worksheet["A2"].Value = "ListItem2";
55+
worksheet["A3"].Value = "ListItem3";
56+
worksheet["A4"].Value = "ListItem4";
57+
58+
worksheet.Range["C1"].Text = "Data Validation List in C3";
59+
worksheet.Range["C1"].AutofitColumns();
60+
61+
//Data validation for the list
62+
IDataValidation listValidation = worksheet.Range["C3"].DataValidation;
63+
listValidation.DataRange = worksheet.Range["A1:A4"];
64+
65+
//Set the first item in the list as default value
66+
worksheet.Range["C3"].Value = worksheet.Range["C3"].DataValidation.DataRange.Cells[0].Value;
67+
68+
69+
#region Save
70+
//Saving the workbook
71+
workbook.SaveAs("../../Output/ListValidation.xlsx");
72+
#endregion
73+
}
74+
{% endhighlight %}
75+
76+
{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
77+
Using excelEngine As New ExcelEngine()
78+
Dim application As IApplication = excelEngine.Excel
79+
application.DefaultVersion = ExcelVersion.Xlsx
80+
81+
'Create a workbook and access the first worksheet
82+
Dim workbook As IWorkbook = application.Workbooks.Create(1)
83+
Dim worksheet As IWorksheet = workbook.Worksheets(0)
84+
85+
'Populate list items
86+
worksheet("A1").Value = "ListItem1"
87+
worksheet("A2").Value = "ListItem2"
88+
worksheet("A3").Value = "ListItem3"
89+
worksheet("A4").Value = "ListItem4"
90+
91+
'Header for the validation cell
92+
worksheet.Range("C1").Text = "Data Validation List in C3"
93+
worksheet.Range("C1").AutofitColumns()
94+
95+
'Create list‐type data validation for cell C3
96+
Dim listValidation As IDataValidation = worksheet.Range("C3").DataValidation
97+
listValidation.DataRange = worksheet.Range("A1:A4")
98+
99+
'Set the first list item as the default value
100+
worksheet.Range("C3").Value = listValidation.DataRange.Cells(0).Value
101+
102+
'Save the workbook
103+
workbook.SaveAs("../../Output/ListValidation.xlsx")
104+
End Using
105+
{% endhighlight %}
106+
{% endtabs %}
107+
A complete working example to set the first item in a list as the default selected value in an Excel File is available on <a href="https://github.com/SyncfusionExamples/XlsIO-Examples/tree/master/FAQ/List%20Validation/.NET/List%20Validation">this GitHub page</a>.

0 commit comments

Comments
 (0)