04-17.eri-test 在Java中的Excel中添加,读取和删除注释

注释是富文本注释,我们经常使用它为特定的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]细胞范围 范围 = 得到细胞范围11);范围setText“处理评论:”);//将文本添加到单元格[5,1]细胞范围 范围1 = 得到细胞范围5 1);范围1setText“评论”);//在单元格[5,1]中添加评论范围1得到Comment()。setText“这是一条注释。\多行,\不可见和\未格式化。”);//显示评论范围1得到Comment()。setVisible真正);//设置评论高范围1得到Comment()。setHeight100);//创建字体并设置字体颜色Excel字体 fontBlue = 工作簿createFont();fontBluesetKnownColorExcelColors浅蓝);Excel字体 fontGreen = 工作簿createFont();fontGreensetKnownColorExcelColors浅绿色);//设置注释文本中各个字符的字体范围1得到Comment()。得到RichText()。setFont0 4 fontGreen);范围1得到Comment()。getRichText()。setFont5 6 fontBlue);范围1getComment()。getRichText()。setFont7 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()。get0);//Pr整型 出 all of the comments in the work片for整型 i = 0; i < getComments()。getCount(); i ++){ comment = getComments()。geti)。getText();系统打印comment);}
//打印与指定单元格关联的注释//系统。out。打印(片。getCellRange(5,1)。getComment()。getText());}
}

Alt Text

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()。get0);//删除所有评论for整型 i = 0; i < .getComments()。getCount(); i ++){.getComments()。geti)。去掉();}
//删除与指定单元格关联的注释.getCellRange51)。getComment()。去掉();
工作簿.saveToFile“ 删除评论.xlsx” Excel版本.2013版);}
}

Alt Text

from: https://dev.to//eiceblue/add-read-and-delete-comments-in-excel-in-java-1jof

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值