Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
How To Create And Apply Border (Color, Width) Style In An Excel Comment Using EPPlus Library .Net C# Application
WhatsApp
Rajdip Sarkar
6y
29.3
k
0
5
25
Blog
LineBorder_Style__Excel Comment_EPP
Suggested video -
EPPLUS Library - Beginners Guide Part-8
Suggested video -
EPPLUS Library - Beginners Guide Part-9(A)
Suggested video -
EPPLUS Library - Beginners Guide Part-10(B)
Suggested video -
EPPLUS Library - Beginners Guide Part-11(C)
Suggested video
-
EPPLUS Library - Beginners Guide Part-12(D)
Source Code -
Click to download
[673 KB]
Different types of Format for Excel Comment?
Add. Move, Hide & Remove Comment to an Excel Sheet cell (We already discussed in
Part 8
)
Resize/Auto fit of Comment. (We already discussed in
Part 9(A)
)
Add Text a Background Color in Comment. (We already discussed in
Part 9(A)
)
Set Text Alignments in Comment. (We already discussed in
Part 10(B)
)
Set Font Style in Excel Comment (We already discussed in
Part 10(B)
)
Add Rich Text in Excel Comment. (We already discussed in
Part 11(C)
)
Add Multiple Rich Text in Excel Comment. (We already discussed in
Part 11(C)
)
Remove Rich Text in Excel Comment. (We already discussed in
Part 11(C)
)
Multi Style Excel Cell & Comment Text using
ExcelRichTextCollection
Class. (We already discussed in
Part 12(D)
)
Set Line/Border Style in a Comment.
How to Create & Apply Line/Border Style in an Excel Comment?
We need to attach one more namespace OfficeOpenXml.Drawing.Vml, because in this code we can see LineWidth, LineColor, LineStyle properties. These properties belong to ExcelVmlDrawingComment class & ExcelComment class is inherited from
ExcelVmlDrawingComment class so, that's why the object of ExcelComment class gets those properties from his base class.
Please see this below code.
using(ExcelRange Rng = wsSheet1.Cells[
"B15"
]) {
ExcelComment cmd = Rng.AddComment(
"Comment Text"
,
"Rajdip"
);
cmd.Font.Bold =
true
;
cmd.Font.Color = Color.Blue;
//Apply Line or Border Style in Excel Comment.
cmd.LineWidth = 3;
Color GreenHexCode = ColorTranslator.FromHtml(
"#008000"
);
cmd.LineColor = GreenHexCode;
//Color.Green;
cmd.LineStyle = eLineStyleVml.DashDot;
cmd.Visible =
true
;
}
We can use custom color code by using ColorTranslator static class methods,
FromHtml (string htmlColor)
,
FromOle (int oleColor)
,
FromWin32 (int win32Color)
.
return type of these methods are
Color
struct object.
There is another enum eLineStyleVml is used in this above code. This enum has eight enumerator list. These are
Here, I am using
DashDot
, that means
4
within enumerator list.
The output of Code,
Full Source Code
using OfficeOpenXml;
using System.IO;
using System.Drawing;
using OfficeOpenXml.Drawing.Vml;
namespace EpplusDemo {
class
Program {
static
void
Main(string[] args) {
//Code download from: https://everyday-be-coding.blogspot.in/p/epplus-library-part-13.html
//Author: Rajdip Sarkar.
//Date : 29th July 2017.
//My YouTube Channel Link : https://www.youtube.com/channel/UCpGuQx5rDbWnc7i_qKDTRSQ
ExcelPackage ExcelPkg =
new
ExcelPackage();
ExcelWorksheet wsSheet1 = ExcelPkg.Workbook.Worksheets.Add(
"Sheet1"
);
using(ExcelRange Rng = wsSheet1.Cells[2, 2, 2, 2]) {
Rng.Value =
"Everyday Be Coding - Excel COMMENTS Formatting using EPPlus .Net Library - Part 13(E)"
;
Rng.Style.Font.Size = 16;
Rng.Style.Font.Bold =
true
;
Rng.Style.Font.Italic =
true
;
}
using(ExcelRange Rng = wsSheet1.Cells[
"B5"
]) {
Rng.Style.Font.Size = 20;
Rng.Value =
"Excel Comment Border Style"
;
ExcelComment cmd = Rng.AddComment(
"Comment Text"
,
"Rajdip"
);
cmd.Font.Bold =
true
;
cmd.Font.Color = Color.Blue;
//Apply Line or Border Style in Excel Comment.
cmd.LineWidth = 3;
Color GreenHexCode = ColorTranslator.FromHtml(
"#008000"
);
cmd.LineColor = GreenHexCode;
//Color.Green;
cmd.LineStyle = eLineStyleVml.DashDot;
cmd.Visible =
true
;
}
wsSheet1.Cells[wsSheet1.Dimension.Address].AutoFitColumns();
ExcelPkg.SaveAs(
new
FileInfo(@
"D:\FormatComments.xlsx"
));
}
}
}
Now build & execute this code. The file is (FormatComments.xlsx) store on D: drive of the computer.
Thank you for reading this article.
EPPlus Library
.Net
C# Application
Up Next
How To Create An Excel File (Development) Using EPPlus .NET Library (C#) - Part One
Ebook Download
View all
LINQ Quick Reference with C#
Read by 44.7k people
Download Now!
Learn
View all
Membership not found