C# 插入批注到Excel

 时间:2024-11-09 12:48:47

此经验将介绍C#如何插入批注到Excel中的方法。

工具/原料

Spire.XLS for .NET 8.0

Visual Studio

dll引用

1、下载安装Spire.XLS后,注意在程序中添加引用Spire.Xls.dll。dll文件可在安装路径下的Bin文件夹中获取。

C# 插入批注到Excel

C# 代码示例(供参考)

1、添加如下using指令using System;using Spire.Xls;using System.Drawing;

2、实例化一个Workbook类实例并加载Excel文档Workbook workbook = new Workbook ();workbook.LoadFromFile("test.xlsx");

3、获取第一个工作表Worksheet sheet = workbook.Worksheets[0];

4、插入文本批注string comment = "注意:\n 责任人兼设备维护人";//设置批注文本ExcelFont 熠硒勘唏font = workbook.CreateFont();//设置批注字体格式font.FontName = "Calibri";font.Color = Color.Black;font.IsBold = true;CellRange range = sheet.Range["I3"];//添加批注到指定单元格range.Comment.RichText.Text = comment;range.Comment.Width = 200;range.Comment.Height = 50;range.Comment.RichText.SetFont(10, 10, font);

5、插入图片批注//加载图片,将图片插入到依宏氽墓指定单元格的批注Image image = Image.FromFile(媪青怍牙"logo.png");sheet.Range["B2"].Comment.Fill.CustomPicture(image, "logo.png");sheet.Range["B2"].Comment.Height = image.Height;sheet.Range["B2"].Comment.Width = image.Width;

6、保存文档workbook.SaveToFile("AddComment.xlsx&孥恶膈茯quot;, ExcelVersion.蕺清寤凯Version2013);System.Diagnostics.Process.Start("AddComment.xlsx");

7、调试运行程序后,生成文档。批注插入效果(如下图):

C# 插入批注到Excel
  • excel 如何插入批注
  • excel 插入批注方法
  • Excel怎么插入批注、编辑批注、删除批注
  • C# 编辑、修改、删除Excel批注
  • EXCEL插入批注、删除批注
  • 热门搜索
    红小豆的功效与作用 运动轿车 维生素c什么牌子好 淘宝知识产权投诉 幼儿园安全小知识 莲子的功效与作用 蛋白粉的功效与作用 初一上册数学知识点 说明文文体知识 edta的作用