Excel annotations are often used to add gaze to individual cells. The reader can obtain additional information from the gaze.
Annotations can be hidden, and only the red triangle appears at the top right of the cell. When added, the contents of the cell are not distracting. In daily programming Excel, it is also necessary to add notes to individual cells. This post focuses on using the free version of Spire.xls to add notes to cells in C # and set the 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 directory 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 join the set font. Used when setting the 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 gave the program ape different language of 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 comment 2 as a comparison.
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 gave the program ape different language of 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 everyone to read the use of, 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.
C # Excel Annotate "which development language is best"