Skip to main content

EPPlus Library Part-13

EPPLUS Library - Beginners Guide Part-13(E)

How to Create & Apply Line/Border Color, Width & Style in an Excel Comment Using EPPlus Library?                                         

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.Vmlbecause in this code we can see LineWidthLineColorLineStyle 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 
a) FromHtml (string htmlColor), 
b) FromOle (int oleColor)
c) 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

eLineStyleVml

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. 
Please subscribe my YouTube Channel & don't forget to like and share. 

YouTube :https://goo.gl/rt4tHH
Facebook :https://goo.gl/m2skDb
Twitter :https://goo.gl/nUwGnf

Comments

Popular posts from this blog

Cloud Storage Access through API  - Advanced Developer Guide - C#  1. Google Drive API - Enable & Get Client Credentials for Application 2. Google Drive API - Uploading, Viewing, Downloading & Deleting Files 3. Google Drive API - Create folder, Upload file to folder, Show folder Content. 4. Google Drive API - How to Move & Copy Files Between Folders. 5. Google Drive API - How to Share & Set Permission of File/Folders. 6. Google Drive API - View Share Users Permission Details. 7. Google Picker API - Viewing, Uploading, Downloading, Sharing. ASP.NET  MVC Tutorial - Advanced Developer Guide - C#  How to Export Razor View to Excel file (Without using Third-Party Library). Excel Development using EPPlus Library Beginners Guide - C# 1. Create an Excel File using EPPlus .Net Library. 2. Apply Cell text and Background Color in Excel Sheet. 3. Apply Cell Border Style in Excel Sheet. 4. Apply Cell Text Alignment, Row Height, Column Width in Excel Sheet

Google Drive API using JavaScript | Full Project - Overview

Setup Google Developer Console for Google Drive API Applications using J...