Class Comment

Class Comment

Namespace: Aspose.Cells
Assembly: Aspose.Cells.dll (25.2.0)

封装表示单元格注释的对象。

public class Comment

继承

objectComment

继承的成员

object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

示例

Workbook workbook = new Workbook();
CommentCollection comments = workbook.Worksheets[0].Comments;

//添加注释到单元格 A1
int commentIndex1 = comments.Add(0, 0);
Comment comment1 = comments[commentIndex1];
comment1.Note = "第一条注释。";
comment1.Font.Name = "Times New Roman";

//添加注释到单元格 B2
comments.Add("B2");
Comment comment2 = comments["B2"];
comment2.Note = "第二条注释。";

//进行您的业务

//保存 Excel 文件。
workbook.Save("exmaple.xlsx");
Dim workbook as Workbook = new Workbook()
Dim comments as CommentCollection = workbook.Worksheets(0).Comments

'添加注释到单元格 A1
Dim commentIndex1 as Integer = comments.Add(0, 0)
Dim comment1 as Comment = comments(commentIndex1)
comment1.Note = "第一条注释。"
comment1.Font.Name = "Times New Roman"

'添加注释到单元格 B2
comments.Add("B2")
Dim comment2 As Comment = comments("B2")
comment2.Note = "第二条注释。"

属性

作者

获取和设置原始注释作者的名称

public string Author { get; set; }

属性值

string

示例

comment1.Author = "Carl.Yang";

自动调整大小

指示注释的大小是否根据其内容自动调整。

public bool AutoSize { get; set; }

属性值

bool

示例

if(!comment1.AutoSize)
{
    //注释的大小随内容变化
    comment1.AutoSize = true;
}

获取注释的列索引。

public int Column { get; }

属性值

int

示例

int column = comment1.Column;

注释形状

获取表示附加到指定注释的形状的 Shape 对象。

public CommentShape CommentShape { get; }

属性值

CommentShape

示例

CommentShape shape = comment1.CommentShape;
int w = shape.Width;
int h = shape.Height;

字体

获取注释的字体。

public Font Font { get; }

属性值

Font

示例

Aspose.Cells.Font font = comment1.Font;
font.Size = 12;

高度

表示注释的高度,以像素为单位。

public int Height { get; set; }

属性值

int

示例

comment1.Height = 10;

高度厘米

表示注释的高度,以厘米为单位。

public double HeightCM { get; set; }

属性值

double

示例

comment1.HeightCM = 1.0;

高度英寸

表示注释的高度,以英寸为单位。

public double HeightInch { get; set; }

属性值

double

示例

comment1.HeightInch = 1.0;

Html注释

获取和设置包含数据和某些格式的 HTML 字符串。

public string HtmlNote { get; set; }

属性值

string

示例

comment1.HtmlNote = "<Font Style='FONT-FAMILY: Calibri;FONT-SIZE: 11pt;COLOR: #0000ff;TEXT-ALIGN: left;'>这是一个 <b>测试</b>.</Font>";

备注

如果这是一个线程注释,则无法更改注释,否则 MS Excel 无法将其处理为线程注释。

IsThreadedComment

指示此注释是否为线程注释。

public bool IsThreadedComment { get; }

属性值

bool

示例

if(comment1.IsThreadedComment)
{
    //此注释是一个线程注释。
}

IsVisible

表示注释是否可见。

public bool IsVisible { get; set; }

属性值

bool

示例

if(comment1.IsVisible)
{
    //注释是可见的
}

注释

表示注释的内容。

public string Note { get; set; }

属性值

string

示例

comment1.Note = "第一条注释。";

备注

如果这是一个线程注释,则无法更改注释,否则 MS Excel 无法将其处理为线程注释。

获取注释的行索引。

public int Row { get; }

属性值

int

示例

int row = comment1.Row;

TextHorizontalAlignment

获取和设置注释的文本水平对齐类型。

public TextAlignmentType TextHorizontalAlignment { get; set; }

属性值

TextAlignmentType

示例

if (comment1.TextHorizontalAlignment ==  TextAlignmentType.Fill)
{
    comment1.TextHorizontalAlignment = TextAlignmentType.Center;
}

TextOrientationType

获取和设置注释的文本方向类型。

public TextOrientationType TextOrientationType { get; set; }

属性值

TextOrientationType

示例

if(comment1.TextOrientationType == TextOrientationType.NoRotation)
{
    comment1.TextOrientationType = TextOrientationType.TopToBottom;
}

TextVerticalAlignment

获取和设置注释的文本垂直对齐类型。

public TextAlignmentType TextVerticalAlignment { get; set; }

属性值

TextAlignmentType

示例

if (comment1.TextVerticalAlignment ==  TextAlignmentType.Fill)
{
    comment1.TextVerticalAlignment = TextAlignmentType.Center;
}

ThreadedComments

获取线程注释的列表;

public ThreadedCommentCollection ThreadedComments { get; }

属性值

ThreadedCommentCollection

示例

ThreadedCommentCollection threadedComments = comment1.ThreadedComments;
for (int i = 0; i < threadedComments.Count; ++i)
{
    ThreadedComment tc = threadedComments[i];
    string note = tc.Notes;
}

宽度

表示注释的宽度,以像素为单位。

public int Width { get; set; }

属性值

int

示例

comment1.Width = 10;

宽度厘米

表示注释的宽度,以厘米为单位。

public double WidthCM { get; set; }

属性值

double

示例

comment1.WidthCM = 1.0;

宽度英寸

表示注释的宽度,以英寸为单位。

public double WidthInch { get; set; }

属性值

double

示例

comment1.WidthInch = 1.0;

方法

Characters(int, int)

返回表示注释文本中一系列字符的 Characters 对象。

public FontSetting Characters(int startIndex, int length)

参数

startIndex int

字符开始的索引。

length int

字符的数量。

返回

FontSetting

Characters 对象。

示例

Aspose.Cells.FontSetting fontSetting = comment1.Characters(0, 4);

FormatCharacters(int, int, Font, StyleFlag)

使用字体设置格式化一些字符。

public void FormatCharacters(int startIndex, int length, Font font, StyleFlag flag)

参数

startIndex int

开始索引。

length int

长度。

font Font

字体设置。

flag StyleFlag

字体设置的标志。

GetRichFormattings()

返回所有 Characters 对象 表示注释文本中一系列字符。

public FontSetting[] GetRichFormattings()

返回

FontSetting[]

所有 Characters 对象

示例

FontSetting[] list = comment1.GetRichFormattings();
 中文