EPPLUS Library - Beginners Guide Part-9(A)
-------------------------------------------------------------------------
How to Format Comment in Excel Worksheet Using EPPlus library?
-------------------------------------------------------------------------
Hindi Video link : • How to Change Text, Background Color ...
-------------------------------------------------------------------------
Blog : https://everyday-be-coding.blogspot.c...
-----------------------------------------------------------------------
Twitter : / everydaycoding
-----------------------------------------------------------------------
Facebook: / everydaybecoding
---------------------------------------------------------------------------------
Source code download link : https://goo.gl/kTYbMn
---------------------------------------------------------------------------------
Resize/Auto fit of Comment Box.
-----------------------------------------------------------
Add Text a Background color in Comment Box.
Set Text Alignments in Comment Box. (We will be discuss in Part-10(B))
Set Font Style in Comment Box (We will be discuss in Part-10(B))
Add Rich Text in Comment box. (We will be discuss in Part-11(C))
Add Multi Color Rich Text in Excel Cell & Comment Box.
(We will be discuss in Part-11(C))
Set Line or Border Style in Comment box. (We will be discuss in Part-12(C))
First, How to apply Resize/Autofit in Excel Comment Box using EPPlus?
When we are apply a long text as a Comments in a Excel Comment Box, By default Excel sheet set a static default size of comment box. As you can see in this below picture.
After Resizing or Autofit the Comments box is look like. Please see this below picture.
So, Next Question in our mind, How to resize the comment box. Please see the below code.
String LongText = "We are offering very easy level beginner tutorials\n on Microsoft .NET base platform, basically for fresher\n as well as experience candidates & also we are focusing\n on very uncommon & specific topics those are extremely\n useful on real life software development.";
using (ExcelRange Rng = wsSheet1.Cells["B4"])
{
Rng.Value = "Everyday Be Coding";
ExcelComment cmd = Rng.AddComment(LongText, "Rajdip");
cmd.AutoFit = true;
cmd.Visible = true;
}
In this code AutoFit is the property of ExcelRange class. It's responsible for auto adjusting text within comment box, but AutoFit adjust the whole text within a single line. So next question is how to show multiple and complete text within a comment box. We used \n new line character or use Environment.NewLine for line breaking. Here Environment is a static class & NewLine is the property of the class.
Set Text & Background color in Excel Comments box using EPPlus
----------------------------------------------------------------------------------------------------------
using (ExcelRange Rng = wsSheet1.Cells["B10"])
{
Rng.Value = " / everydaybecoding ";
ExcelComment cmd = wsSheet1.Comments.Add(Rng, "This a facebook page URL of my YouTube Channel", "Rajdip");
cmd.Visible = true;
cmd.BackgroundColor = Color.Green;
cmd.Font.Color = Color.White;
cmd.Visible = true;
}
In this code Font is the property of ExcelComment class and the type of this property is ExcelRichText class. This class has Color (structure) type color property. So that why we are assign
Color structure property green to the ExcelRichText class property color.
For setting the background color in Excel comment box, we need to assign Color structure property to BackgroundColor property of ExcelComment class.
Now build & execute this code. File is (FormatComments.xlsx) store on D: drive of computer.
Thank you for reading this article.
Please subscribe my YouTube Channel & don't forget to like and share.