7465育婴网

您现在的位置是:首页>百家杂谈

百家杂谈

java删除制定文件(完全卸载java和注册表)

74652024-04-25 13:03:43百家杂谈80来源:7465育婴网

批注是一种富文本注释,常用来为指定的 Excel 单元格添加提示或附加消息。 Free Spire.XLS for Java 为研究人员不要钱提供了在 Java 应用应用程序中对 Excel 文件添加和操作批注的功能。 本文将讲解怎么样使用Free Spire.XLS for Java在 Excel 文档中添加,读取和删除批注。

安装 首先你需要安装Spire.XLS JAR并将其作为依赖项添加到您的 Java 程序中。如果您使用的是 maven,您需要将以下依赖项添加到您的 pom.xml 文件中。

 

com.e-iceblue

e-iceblue

http://repo.e-iceblue.com/nexus/content/groups/public/

 

   

  e-iceblue

  spire.xls.free

  2.2.0

   

添加批注

下面的示例将演示怎么样使用不要钱的 Free Spire.XLS for Java 将批注添加到 Excel 文件中,并为批注文本中各个字符设置不一样的字体颜色。

import com.spire.xls.*;

public class AddComments {

    public static void main(String[] args){

  //新建 Excel 文档

  Workbook workbook = new Workbook();

  //获取第一张事件表

  Worksheet sheet = workbook.getWorksheets().get(0);

  //设置事件表名称

  sheet.setName(“批注”);

  //添加文本到单元格[1,1]

  CellRange range = sheet.getCellRange(1,1);

  range.setText(“添加批注:”);

  //添加文本到单元格 [5,1]

  CellRange range1 = sheet.getCellRange(5, 1);

  range1.setText(“批注”);

  //添加批注到单元格 [5,1]

  range1.getComment().setText(“这是一个批注n 它应该是多行的。”);

  //展示批注

  range1.getComment().setVisible(true);

  //设置批注高度

  range1.getComment().setHeight(100);

  //创建字体并设置字体颜色

  ExcelFont fontBlue = workbook.createFont();

  fontBlue.setKnownColor(ExcelColors.LightBlue);

  ExcelFont fontGreen = workbook.createFont();

  fontGreen.setKnownColor(ExcelColors.LightGreen);

  //设置批注文本中各个字符的字体

  range1.getComment().getRichText().setFont(0, 1, fontGreen);

  range1.getComment().getRichText().setFont(2, 3, fontBlue);

  range1.getComment().getRichText().setFont(4, 5, fontGreen);

  //保存结果文档

  workbook.saveToFile(“添加批注.xlsx”, ExcelVersion.Version2013);

    }

}

读取批注 Free Spire.XLS for Java 支持读取全部批注以及与 Excel 事件表中指定单元格有关联的特殊批注。

import com.spire.xls.*;

public class ReadComments {

    public static void main(String[] args){

  //加载 Excel 文档

  Workbook workbook = new Workbook();

  workbook.loadFromFile(“添加批注.xlsx”);

  //获取第一张事件表

  Worksheet sheet = workbook.getWorksheets().get(0);

  //打印事件表中全部的批注

  for(int i = 0; i < sheet.getComments().getCount(); i ++){

String comment = sheet.getComments().get(i).getText();

System.out.println(comment);

  }

  //打印与指定单元格有关联的批注

 //System.out.println(sheet.getCellRange(5,1).getComment().getText());

  }

}

删除批注 通过使用 Free Spire.XLS for Java 我们应该删除全部注释,也应该删除与 Excel 事件表中指定单元格有关联的特殊批注。

import com.spire.xls.*;

public class DeleteComments {

    public static void main(String[] args){

  //加载 Excel 文档

  Workbook workbook = new Workbook();

  workbook.loadFromFile(“添加批注.xlsx”);

  //获取第一张事件表

  Worksheet sheet = workbook.getWorksheets().get(0);

  //删除事件表中全部批注

  for(int i = 0; i < sheet.getComments().getCount(); i ++){

sheet.getComments().get(i).remove();

  }

  //删除与指定单元格有关联的批注

  sheet.getCellRange(5,1).getComment().remove();

  workbook.saveToFile(“删除批注.xlsx”, ExcelVersion.Version2013);

  }

    }