Excel annotations are often used to annotate individual cells, and readers can get additional information from comments. Annotations can be hidden, only the red triangle is displayed in the upper right of the cell, and the contents of the cell are not distracting when added. It is also necessary to add note information to individual cells in daily programming excel. This post focuses on using the free version of Spire.xls to add notes to cells in C # and to set location, size, rich text, and text alignment.
Friends who want to try can download the free Spire.xls:e-iceblue website from the following three addresses, nuget;csdn download. After downloading, add the. dll in the Bin folder as a reference to vs.
Step One: create a new workbook and form.
Workbook workbook = new Workbook(); Worksheet sheet = workbook.Worksheets[0];
Step Two: Enable class Excelfont to add set fonts, which are used when setting up comment text.
Excelfont font1 = Workbook. CreateFont();Font1. FontName="Imitation";Font1. Color= Color. Red;Font1. IsBold= True;Font1. Size= A;Excelfont Font2 = Workbook. CreateFont();Font2. FontName="Imitation";Font2. Color= Color. Blue;Font2. Size= A;Font2. IsBold= True;Excelfont font3 = Workbook. CreateFont();Font3. FontName="Calibri";Font3. Color= Color. Blue;Font3. Size= A;Font3. IsBold= True;
Step Three: add annotation 1 to cell F5, set its size, position, text, and text alignment.
Excelcomment Comment1 = Sheet. Range["F5"]. Comment;Comment1. IsVisible= True;Set the annotation height and width Comment1. Height= Max;Comment1. Width= -;Set the annotation position Comment1. Top= -;Comment1. Left= +;Set text content, alignment, text rotation Comment1. RichText. Text="to prevent humans from working together to develop artificial intelligence, God has given programmers different language for development. But which language is the best? ";Comment1. RichText. SetFont(0, +, Font2);Comment1. RichText. SetFont( -, -, Font1);Comment1. Textrotation= Textrotationtype. LeftToRight;Comment1. Valignment= Commentvaligntype. Center;Comment1. HAlignment= Commenthaligntype. Justified;
Step four: add annotation 2 as a control.
Excelcomment comment2= Sheet. Range["F14"]. Comment;Comment2. IsVisible= True;Comment2. Height= Max;Comment2. Width= -;Comment2. RichText. Text="About E-iceblue: \ne-iceblue focuses in providing excellent Office components for developers to operate Word, Excel, PDF, and PowerPoint documents. ";Comment2. Textrotation= Textrotationtype. LeftToRight;Comment2. RichText. SetFont(0, -, Font2);Comment2. Top= the;Comment2. Left= the;Comment2. Valignment= Commentvaligntype. Top;Comment2. HAlignment= Commenthaligntype. Justified;
Step Five: Save the document and start the viewing effect.
workbook.SaveToFile("S3.xlsx", ExcelVersion.Version2010); System.Diagnostics.Process.Start("S3.xlsx");
:
All code:
Using System;Using System. Collections. Generic;Using System. Linq;Using System. Text;Using Spire. Xls;Using System. Drawing;Namespace how_to_set_excel_margin_to_print{class Program {static void Main (string[] args) { Workbook Workbook = new Workbook ();Worksheet sheet = Workbook. Worksheets[0];Excelfont font1 = Workbook. CreateFont();Font1. FontName="Imitation";Font1. Color= Color. Red;Font1. IsBold= True;Font1. Size= A;Excelfont Font2 = Workbook. CreateFont();Font2. FontName="Imitation";Font2. Color= Color. Blue;Font2. Size= A;Font2. IsBold= True;Excelfont font3 = Workbook. CreateFont();Font3. FontName="Calibri";Font3. Color= Color. Blue;Font3. Size= A;Font3. IsBold= True;Excelcomment Comment1 = Sheet. Range["F5"]. Comment;Comment1. IsVisible= True;Comment1. Height= Max;Comment1. Width= -;Comment1. Top= -;Comment1. Left= +;Comment1. RichText. Text="to prevent humans from working together to develop artificial intelligence, God has given programmers different language for development. But which language is the best? ";Comment1. RichText. SetFont(0, +, Font2);Comment1. RichText. SetFont( -, -, Font1);Comment1. Textrotation= Textrotationtype. LeftToRight;Comment1. Valignment= Commentvaligntype. Center;Comment1. HAlignment= Commenthaligntype. Justified;Excelcomment comment2= Sheet. Range["F14"]. Comment;Comment2. IsVisible= True;Comment2. Height= Max;Comment2. Width= -;Comment2. RichText. Text="About E-iceblue: \ne-iceblue focuses in providing excellent Office components for developers to operate Word, Excel, PDF, and PowerPoint documents. ";Comment2. Textrotation= Textrotationtype. LeftToRight;Comment2. RichText. SetFont(0, -, Font2);Comment2. Top= the;Comment2. Left= the;Comment2. Valignment= Commentvaligntype. Top;Comment2. HAlignment= Commenthaligntype. Justified;Workbook. SaveToFile("S3.xlsx", excelversion. Version2010);System. Diagnostics. Process. Start("S3.xlsx");} }}
For the convenience of reference reading use, Bo will be a succession of Chinese e-iceblue control of the use of the tutorial. Interested friends please pay attention to the collection of this blog.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
C # Excel Annotate "which development language is best"