注释是富文本注释,我们经常使用它为特定的ExcËl单元格添加提示或其他信息。。自由尖顶。XLS对于Java库使Java开发人员能够在Java应用程序内的ExcËl文件中添加和处理注释。。Inth一世sart一世clË,wËw一世ll整型roducehowtoadd,readanddelete评论s一世nExcelus一世ngFreeSp一世re。XLSJava库。
Installat一世on
F一世rstofall,youneedtodownload尖塔。xls。jarandadd一世ttoyourprojectas依赖。如果使用maven,则需要将以下依赖项添加到pom中。xml文件。
<仓库><资料库><ID>com。e-冰蓝</ID><名称>e-冰蓝</名称><网址>http://repo。e-冰蓝。com/nexus/content/groups/上市/</网址></资料库></仓库><依存关系><依赖><groupId>e-冰蓝</groupId><artifactId>尖塔。xls。free</artifactId><版>2。2。0</版></依赖></依存关系>
AddComments
下面的示例演示如何使用免费的JavaSpire。XLS将注释添加到Excel文件,并以不同的颜色设置注释文本中各个字符的格式。
进口com。spire。xls。*;上市class添加评论{上市静态的虚空主要(串[] args){//创建工作簿实例工作簿 工作簿 = 新 工作簿();//获取第一个工作表工作表 片 = 工作簿。得到Work片s()。得到(0);//设置工作表名称 片。setName(“注释”);//将文本添加到单元格[1,1]细胞范围 范围 = 片。得到细胞范围(1,1);范围。setText(“处理评论:”);//将文本添加到单元格[5,1]细胞范围 范围1 = 片。得到细胞范围(5, 1);范围1。setText(“评论”);//在单元格[5,1]中添加评论范围1。得到Comment()。setText(“这是一条注释。\多行,\不可见和\未格式化。”);//显示评论范围1。得到Comment()。setVisible(真正);//设置评论高范围1。得到Comment()。setHeight(100);//创建字体并设置字体颜色Excel字体 fontBlue = 工作簿。createFont();fontBlue。setKnownColor(ExcelColors。浅蓝);Excel字体 fontGreen = 工作簿。createFont();fontGreen。setKnownColor(ExcelColors。浅绿色);//设置注释文本中各个字符的字体范围1。得到Comment()。得到RichText()。setFont(0, 4, fontGreen);范围1。得到Comment()。getRichText()。setFont(5, 6, fontBlue);范围1。getComment()。getRichText()。setFont(7, 15, fontGreen);//保存文件工作簿。saveToFile(“ 添加评论。xlsx”, Excel版本。2013版);}}
Read Comments
Free Spire。XLS 对于 Java supports reading all of the comments as well as reading a particular comment associated with a specified cell in an Excel work片。
进口 com。spire。xls。*;
上市 class 阅读评论 {上市 静态的 虚空 主要(串[] args){//加载Excel文件工作簿 工作簿 = 新 工作簿();工作簿。loadFromFile(“ AddComments。xlsx”);//获取第一个工作表工作表 片 = 工作簿。getWork片s()。get(0);//Pr整型 出 all of the comments in the work片for(整型 i = 0; i < 片。getComments()。getCount(); i ++){串 comment = 片。getComments()。get(i)。getText();系统。出。打印(comment);}
//打印与指定单元格关联的注释//系统。out。打印(片。getCellRange(5,1)。getComment()。getText());}
}
Delete Comments
We can either delete all of the comments or delete a particular comment associated with a specified cell in an Excel work片.
进口 com.spire.xls。*;
上市 class 删除评论 {上市 静态的 虚空 主要(串[] args){//加载Excel文件工作簿 工作簿 = 新 工作簿();工作簿.loadFromFile(“ AddComments.xlsx”);//获取第一个工作表工作表 片 = 工作簿.get工作表s()。get(0);//删除所有评论for(整型 i = 0; i < 片.getComments()。getCount(); i ++){片.getComments()。get(i)。去掉();}
//删除与指定单元格关联的注释片.getCellRange(5,1)。getComment()。去掉();
工作簿.saveToFile(“ 删除评论.xlsx”, Excel版本.2013版);}
}
from: https://dev.to//eiceblue/add-read-and-delete-comments-in-excel-in-java-1jof