C# Excel批注“哪种开发语言最好”
Excel批注经常使用于为个别的单元格加入凝视。读者可以从凝视中获取额外的信息。
批注可隐藏,仅仅会在单元格右上方显示红色三角。加入后不会对单元格的内容喧宾夺主。在日常编程处理Excel中,为个别单元格加入备注信息,也有必要。这篇博文主要介绍使用免费版的Spire.XLS在C#中为单元格加入备注,并设置位置。大小。富文本及文本对齐方式。
想尝试的朋友可以从下面三个地址下载Free Spire.XLS: E-iceblue官网下载;Nuget;CSDN下载。下载之后,请将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");
效果图:
所有代码:
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批注“哪种开发语言最好”的更多相关文章
- php有几种开发语言
php有几种开发语言? php的启发语言有五种,分别是C.Perl.Java.C++.Python. PHP(全称:PHP:Hypertext Preprocessor,即“PHP:超文本预处理器”) ...
- 10.app后端选择什么开发语言
在qq上,经常看到有创业团队的创始人一直都招不到技术人员,除了项目的因素外,很大的原因就是所需要掌握的开发语言偏门.通过阅读本文,详细了解选择开发语言的核心原则,使各位心里对开发语言的选择更加有数. ...
- 软件测试人员需要精通的开发语言(1)--- VBScript
软件测试不局限于点点点的纯黑盒测试,提升自身的代码能力也是事关重要的.软件测试的发展,越来越多的公司对于测试人员的要求也日益提高,测试人员必备开发能力的优势也凸显出来.简单的介绍下部分开发语言的学习及 ...
- 个人永久性免费-Excel催化剂功能第55波-Excel批注相关的批量删除作者、提取所有批注信息等
Excel里的批注,许多人很喜欢用,但批注真的值得我们大量使用吗?批注的使用场景在哪里?这些问题可能更值得花时间来思考下.同样因为不规范地使用批注,也带出了一大堆的后续擦屁股的事情来,从批注中找回有价 ...
- KOTLIN开发语言文档(官方文档) -- 2.基本概念
网页链接:https://kotlinlang.org/docs/reference/basic-types.html 2. 基本概念 2.1. 基本类型 从可以在任何变量处理调用成员函数和属性 ...
- java web学习总结(二十九) -------------------JavaBean的两种开发模式
SUN公司推出JSP技术后,同时也推荐了两种web应用程序的开发模式,一种是JSP+JavaBean模式,一种是Servlet+JSP+JavaBean模式. 一.JSP+JavaBean开发模式 1 ...
- 【夔堂】:程序血泪史之——有一种垃圾语言叫做JavaScript
"Prototype"机制是个半成品OOP,有些文章说这玩意当初为了"简单(编写).容易(学习)"而发明的,但web前端技术发展到今天我们看到,JS显然是需要O ...
- 【转载】谷歌酝酿将苹果Swift作为安卓APP主要开发语言
TNW中文站 4月8日报道 安卓操作系统的软件开发语言是Java,而在过去几年中,有关Java的版权,谷歌(微博)和甲骨文之间发生了长期的诉讼.最新外媒消息称,谷歌正在考虑将苹果开发的Swift作为未 ...
- Java在Web开发语言上败给了PHP
PHP的主要语言开发者之一.Zend公司的创始人之一Andi Gutmans最近在blog中直言不讳地批评了Java语言.他指出,目前Java厂商试图在JVM上提供动态语言实现的路子根本不对,Java ...
随机推荐
- [android开发篇] android apidemo 学习网址
http://www.2cto.com/special/ApiDemos/ApiDemos/type-160-10.html
- 九度oj 题目1491:求1和2的个数
题目描述: 给定正整数N,函数F(N)表示小于等于N的自然数中1和2的个数之和,例如:1,2,3,4,5,6,7,8,9,10序列中1和2的个数之和为3,因此F(10)=3.输入N,求F(N)的值,1 ...
- nginx报错504
Nginx 504错误(Gateway time-out 网关超时)的含义是所请求的网关没有请求到,简单来说就是没有请求到可以执行的PHP-CGI. 一般看来, 这种情况可能是由于nginx默认的f ...
- 阐述struts2的执行流程。
Struts 2框架本身大致可以分为3个部分:核心控制器FilterDispatcher.业务控制器Action和用户实现的企业业务逻辑组件. 核心控制器FilterDispatcher是Struts ...
- 【(最小权点基)tarjan强连通分量缩点+tarjan模板】HDU 5934 Bomb
[AC] #include<bits/stdc++.h> using namespace std; typedef long long ll; int n; ; ; const int i ...
- wsgi 简介
原文博客地址 http://blog.csdn.net/on_1y/article/details/18803563
- CI(CodeIgniter)框架中的增删改查操作
我们创建一个模型( 项目目录/models/),请注意:模型名与文件名相同且必须继承数据核心类CI_Model,同时重载父类中的构造方法 CodeIgniter的数据函数类在 \models\User ...
- 欧拉函数(codevs 4939)
题目描述 Description 输入一个数n,输出小于n且与n互素的整数个数 输入描述 Input Description 包含多组数据,n=0时结束 测试数据组数不会很多,不必先打表后输出 输出描 ...
- 品酒大会 BZOJ 4199
品酒大会 [问题描述] [输入格式] [输出格式] [样例输入] 10ponoiiipoi 2 1 4 7 4 8 3 6 4 7 [样例输出] 45 56 10 56 3 32 0 0 0 0 0 ...
- 关于事件委托和时间冒泡(以及apply和call的事项)
搜索事件委托和事件冒泡,网上一大堆乱七八糟的解释,当然意思都对,没毛病. but,真的无聊. 事件冒泡:事件会从点击的元素开始依次向上流出,直到html,遇见事件监听则执行. 事件委托:原因——父元素 ...