国产Excel开发组件Spire.XLS教程:在Java中以编程方式在Excel中添加和阅读注释

本文演示了如何将常规注释和富文本注释添加到Excel文件,以及如何使用Spire.XLS for Java阅读注释。

*这么优秀的国产工具怎能错过呢!在线下单专享“一口价”,立即购买!想要获取更多福利的朋友可以咨询在线客服哦~


添加评论

import com.spire.xls.*;public class InsertComments {    public static void main(String[] args){        //Create a Workbook instance        Workbook workbook = new Workbook();        //Get the first worksheet        Worksheet sheet = workbook.getWorksheets().get(0);        //Create fonts        ExcelFont font = workbook.createFont();        font.setFontName("Arial");        font.setSize(11);        font.setKnownColor(ExcelColors.Orange);        ExcelFont fontBlue = workbook.createFont();        fontBlue.setKnownColor(ExcelColors.LightBlue);        ExcelFont fontGreen = workbook.createFont();        fontGreen.setKnownColor(ExcelColors.LightGreen);        //Add regular comment to specific cell range        CellRange range = sheet.getCellRange("A1");        range.setText("Regular comment");        range.getComment().setText("Regular comment");        range.autoFitColumns();        //Add rich text comment to specific cell range        range = sheet.getCellRange("A2");        range.setText("Rich text comment");        range.getRichText().setFont(0, 16, font);        range.autoFitColumns();        range.getComment().getRichText().setText("Rich text comment");        range.getComment().getRichText().setFont(0, 4, fontGreen);        range.getComment().getRichText().setFont(5, 9, fontBlue);        //Save the resultant file        workbook.saveToFile("AddComments.xlsx", ExcelVersion.Version2013);    }}

常规评论

Excel开发组件Spire.XLS教程:在Java中以编程方式在Excel中添加和阅读注释

富文本评论

Excel开发组件Spire.XLS教程:在Java中以编程方式在Excel中添加和阅读注释

阅读评论

import com.spire.xls.Workbook;import com.spire.xls.Worksheet;public class ReadComments {    public static void main(String[] args){        //Load Excel file        Workbook workbook = new Workbook();        workbook.loadFromFile("AddComments.xlsx");        //Get the first worksheet        Worksheet sheet = workbook.getWorksheets().get(0);        //Print out the comment        System.out.println("A1 Comment = " + sheet.getCellRange("A1").getComment().getText());        System.out.println("A2 Comment = " + sheet.getCellRange("A2").getComment().getRichText().getRtfText());    }}

Excel开发组件Spire.XLS教程:在Java中以编程方式在Excel中添加和阅读注释


是E-iceblue官方友好合作伙伴,如果您对spire.xls可以联系在线客服了解具体授权价格和使用机制

标签:

来源:慧都

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2021年4月7日
下一篇 2021年4月7日

相关推荐

发表回复

登录后才能评论