首页 > 编程语言 >C# Excel批注“哪种开发语言最好”

C# Excel批注“哪种开发语言最好”

时间:2022-12-30 12:04:07浏览次数:79  
标签:批注 C# Excel font2 Comment1 Comment2 Color font1 workbook


Excel批注常用于为个别的单元格添加注释,读者能够从注释中获取额外的信息。批注可隐藏,只会在单元格右上方显示红色三角,添加后不会对单元格的内容喧宾夺主。在日常编程处理Excel中,为个别单元格添加备注信息,也有必要。这篇博文主要介绍使用免费版的Spire.XLS在C#中为单元格添加备注,并设置位置,大小,富文本及文本对齐方式。

想尝试的朋友可以从以下三个地址下载Free Spire.XLS: ​​E-iceblue官网下载​​​;​​Nuget​​;​​下载​​。下载之后,请将bin 文件夹里的.dll添加为VS的引用。

步骤一: 创建一个新的工作薄和表单。

Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];

步骤二:启用类ExcelFont添加设置字体,在设置comment文本时会用到。

ExcelFont font1 = workbook.CreateFont();
font1.FontName = "仿宋";
font1.Color = Color.Red;
font1.IsBold = true;
font1.Size = 12;
ExcelFont font2 = workbook.CreateFont();
font2.FontName = "仿宋";
font2.Color = Color.Blue;
font2.Size = 12;
font2.IsBold = true;
ExcelFont font3 = workbook.CreateFont();
font3.FontName = "Calibri";
font3.Color = Color.Blue;
font3.Size = 12;
font3.IsBold = true;

步骤三:为单元格F5添加批注1,设置其大小,位置,文本,文本对齐方式。

ExcelComment Comment1 = sheet.Range["F5"].Comment;
Comment1.IsVisible = true;
//设置批注高度和宽度
Comment1.Height = 150;
Comment1.Width = 300;
//设置批注位置
Comment1.Top = 20;
Comment1.Left = 40;
//设置文本内容,对齐方式,文本旋转
Comment1.RichText.Text = "为了防止人类齐心协力开发出人工智能,上帝给了程序员不同的开发语言。但哪种语言才是最好的呢?";
Comment1.RichText.SetFont(0, 32, font2);
Comment1.RichText.SetFont(33, 44, font1);
Comment1.TextRotation = TextRotationType.LeftToRight;
Comment1.VAlignment = CommentVAlignType.Center;
Comment1.HAlignment = CommentHAlignType.Justified;

步骤四:添加批注2作为对照。

ExcelComment Comment2= sheet.Range["F14"].Comment;
Comment2.IsVisible = true;
Comment2.Height = 150;
Comment2.Width = 300;
Comment2.RichText.Text = "About E-iceblue: \nE-iceblue focuses on providing excellent office components for developers to operate Word, Excel, PDF, and PowerPoint documents.";
Comment2.TextRotation = TextRotationType.LeftToRight;
Comment2.RichText.SetFont(0, 16, font2);
Comment2.Top = 170;
Comment2.Left = 450;
Comment2.VAlignment = CommentVAlignType.Top;
Comment2.HAlignment = CommentHAlignType.Justified;

步骤五:保存文档,并启动查看效果。

workbook.SaveToFile("S3.xlsx", ExcelVersion.Version2010);
System.Diagnostics.Process.Start("S3.xlsx");

效果图:

C# Excel批注“哪种开发语言最好”_单元格

全部代码:

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 = "仿宋";
font1.Color = Color.Red;
font1.IsBold = true;
font1.Size = 12;
ExcelFont font2 = workbook.CreateFont();
font2.FontName = "仿宋";
font2.Color = Color.Blue;
font2.Size = 12;
font2.IsBold = true;
ExcelFont font3 = workbook.CreateFont();
font3.FontName = "Calibri";
font3.Color = Color.Blue;
font3.Size = 12;
font3.IsBold = true;

ExcelComment Comment1 = sheet.Range["F5"].Comment;
Comment1.IsVisible = true;
Comment1.Height = 150;
Comment1.Width = 300;
Comment1.Top = 20;
Comment1.Left = 40;
Comment1.RichText.Text = "为了防止人类齐心协力开发出人工智能,上帝给了程序员不同的开发语言。但哪种语言才是最好的呢?";
Comment1.RichText.SetFont(0, 32, font2);
Comment1.RichText.SetFont(33, 44, font1);
Comment1.TextRotation = TextRotationType.LeftToRight;
Comment1.VAlignment = CommentVAlignType.Center;
Comment1.HAlignment = CommentHAlignType.Justified;

ExcelComment Comment2= sheet.Range["F14"].Comment;
Comment2.IsVisible = true;
Comment2.Height = 150;
Comment2.Width = 300;
Comment2.RichText.Text = "About E-iceblue: \nE-iceblue focuses on providing excellent office components for developers to operate Word, Excel, PDF, and PowerPoint documents.";
Comment2.TextRotation = TextRotationType.LeftToRight;
Comment2.RichText.SetFont(0, 16, font2);
Comment2.Top = 170;
Comment2.Left = 450;
Comment2.VAlignment = CommentVAlignType.Top;
Comment2.HAlignment = CommentHAlignType.Justified;

workbook.SaveToFile("S3.xlsx", ExcelVersion.Version2010);
System.Diagnostics.Process.Start("S3.xlsx");
}
}
}

为方便大家参考阅读使用,博主将陆续汉化E-iceblue控件的使用教程。感兴趣的朋友请关注收藏此博客。


标签:批注,C#,Excel,font2,Comment1,Comment2,Color,font1,workbook
From: https://blog.51cto.com/u_15656056/5979840

相关文章

  • C# Excel 生成图表,添加趋势线、误差线
    Excel图表能够将数据可视化,在图表中另行添加趋势线和误差线,可对数据进行进一步的数据分析和统计的可视化处理。Excel中的趋势线可用于趋势预测/回归分析,共6中类型:指数(X),线性(L......
  • C#/VB.NET 在PDF表格中添加条形码
    条码的应用已深入生活和工作的方方面面。在处理条码时,常需要和各种文档格式相结合。当需要在文档中插入、编辑或者删除条码时,可借助于一些专业的类库工具来实现。本文,以操作......
  • C# Powerpoint 禁止或允许修改形状
    在设定形状属性后,可禁止对形状某些属性的编辑,以达到保护形状格式的目的。常用方法有:锁定形状禁止选择,和禁止对形状的具体属性进行修改。前者保护形状的所有格式,无法选取,无......
  • C# Excel 条件格式
    Excel中条件格式是指:根据条件使用数据条、色阶和图标集,以突出显示相关单元格,强调异常值,以及实现数据的可视化效果。条件格式功能是进阶版的筛选,即先设置条件选出符合某些条......
  • C# 原样复制excel工作表
    在Excel中,工作表是工作薄的组成部分,一个工作薄可以由一个或多个工作表组成,一个工作薄也可以说是一个Excel文档,正因为如此,Excel工作表的复制也就分为两种类型:在同一文档之内......
  • 在Excel表里面插入背景图
    工作中我们会经常用到MSExcel,通常我们打开MSExcel,里面的工作表都是空白单调的背景。当然了,MSExcel可以在工作簿里面插入背景图片。那么问题来了,如果你没有安装Microsoft......
  • Appscan扫描的web网站有验证码导致登录失败,解决方式:使用固定的cookie、token值进行登
    Appscan扫描的web网站有验证码导致登录失败,解决方式:使用固定的cookie、token值进行登录扫描 步骤:1、登录方式选择‘无’  2、添加cookie方式一:  2)cookie名在......
  • 在C#中实现Word页眉页脚的所有功能
    页眉页脚常用于文章排版,在Word工具栏里,我们可以添加页眉,页脚,页码,日期和时间,图片等信息和内容。页眉/页脚有两个额外选项:首页不同,奇偶页不同。有时在不同的节(section)里插入不......
  • 阿里IM技术分享(九):深度揭密RocketMQ在钉钉IM系统中的应用实践
    本文由钉钉技术专家尹启绣分享,有修订和重新排版。1、引言短短的几年时间,钉钉便迅速成为一款国民级应用,发展速度堪称迅猛。IM作为钉钉最核心的功能,每天需要支持海量企业......
  • C# 打印PDF文件之使用不同打印机打印所有页面或部分页面
    最近在逛国外各大编程社区论坛的时候,发现很多人都在问一个关于PDF文件打印的问题:打印时如何选择非默认打印机并设置打印页面的范围。而一般情况下,打印时选择的打印机是默认......