Java 추가,수정,읽 기,복사,Excel 주석 삭제 실현

주석 은 작성 자 나 심사 자가 문서 에 추가 한 주석 이나 주석 입 니 다.주석 을 보면 어떤 문자 의 배경 을 더욱 상세 하 게 알 수 있다.텍스트 정 보 를 직접 추가 하 는 것 외 에 텍스트 정보 에 배경 그림 을 채 워 더욱 풍부 하고 아름 답 게 할 수 있다.이 글 은 Excel 문서 에 주석 을 추가,수정,읽 기,복사,삭제 하 는 방법 을 자바 프로그램 으로 보 여 줍 니 다.
사용 도구:Free Spire.XLS for Java(무료 버 전)
Jar 파일 가 져 오기 및 가 져 오기:
방법 1:공식 사이트다운 로드 를 통 해 jar 가방 을 얻 을 수 있 습 니 다.압축 을 풀 고 lib 폴 더 에 있 는 Spire.XLs.jar 파일 을 자바 프로그램 으로 가 져 옵 니 다.(이 그림

방법 2:maven 창 고 를 통 해 설치 하여 가 져 옵 니 다.구체 적 인 설치 상세 설명 참조이 페이지.
[예시 1]주석 추가

import com.spire.xls.*;
import java.awt.*;
public class AddComments {
 public static void main(String[] args) {

  //  Excel  
  Workbook wb = new Workbook();
  wb.loadFromFile("D:\\Desktop\\Sample.xlsx");

  //     
  Worksheet sheet = wb.getWorksheets().get(0);

  //    
  ExcelFont font = wb.createFont();
  font.setFontName("Arial");
  font.setSize(11);
  font.setKnownColor(ExcelColors.Orange);
  ExcelFont fontBlue = wb.createFont();
  fontBlue.setKnownColor(ExcelColors.LightBlue);
  ExcelFont fontGreen = wb.createFont();
  fontGreen.setKnownColor(ExcelColors.LightGreen);

  //    Excel         
  CellRange range = sheet.getCellRange("G3");
  range.getComment().setText("    ");
  range.getComment().setTextRotation(TextRotationType.TopToBottom);
  range.autoFitColumns();
  range.getComment().setVisible(true);//        
  range.getComment().getFill().customPicture("D:\\Desktop\\Image.jpg");//      
  //range.getComment().getFill().setForeColor(new Color(255,228,225));//    

  //     Excel          
  range = sheet.getCellRange("G7");
  range.getRichText().setFont(0, 8, font);
  range.autoFitColumns();
  range.getComment().getRichText().setText("    ");
  range.getComment().getRichText().setFont(0, 4, fontGreen);
  range.getComment().getRichText().setFont(3, 4, fontBlue);

  //      
  wb.saveToFile("output/AddComments.xlsx", ExcelVersion.Version2013);
  wb.dispose();

 }
}
주석 추가 효과:

[예시 2]주석 수정

import com.spire.xls.*;
public class ModifyComments {
 public static void main(String[] args) {
  //  excel  
  Workbook wb = new Workbook();
  wb.loadFromFile("D:\\Desktop\\AddComments.xlsx");
  //     
  Worksheet sheet = wb.getWorksheets().get(0);
  //           ,        、   
  sheet.getRange().get("G3").getComment().setText("    ");
  sheet.getRange().get("G7").getComment().setText("    ");
  //    
  wb.saveToFile("output/ModifyComment.xlsx",ExcelVersion.Version2013);
  wb.dispose();
 }
}
주석 수정 효과:

[예시 3]주석 읽 기

import com.spire.xls.*;
import javax.imageio.ImageIO;
import java.awt.*;import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class ReadComments {
 public static void main(String[] args) throws IOException {
  //  excel  
  Workbook wb = new Workbook();
  wb.loadFromFile("D:\\Desktop\\AddComments.xlsx");
  //     
  Worksheet sheet = wb.getWorksheets().get(0);
  //              
  System.out.println("G3       = " + sheet.getCellRange("G3").getComment().getText());
  System.out.println("G7       = " + sheet.getCellRange("G7").getComment().getRichText().getRtfText());
  //              
  Color color = sheet.getRange().get("G3").getComment().getFill().getForeColor();
  System.out.print(color);
  //               
  BufferedImage image = sheet.getRange().get("G3").getComment().getFill().getPicture();
  ImageIO.write(image,"png",new File("output/ExtractedImage.png"));
 }
}
주석 읽 기 효과:

[예시 4]주석 복사

import com.spire.xls.*;
import java.awt.*;
import java.awt.image.BufferedImage;

public class CopyComments {
 public static void main(String[] args) {

  //  Excel  
  Workbook wb = new Workbook();
  wb.loadFromFile("D:\\Desktop\\AddComments.xlsx");

  //       
  Worksheet sheet = wb.getWorksheets().get(0);

  //          
  CellRange range = sheet.getRange().get("G3");//       
  String commenttext = range.getComment().getText();//      
  BufferedImage image = range.getComment().getFill().getPicture();//        
  // Object object = range.getComment().getFill().getForeColor();//       

  //        ,         (  )  
  CellRange range1 = sheet.getRange().get("G12");
  range1.getComment().setText(commenttext);
  range1.getComment().getFill().customPicture(image," ");
  //range1.getComment().getFill().setForeColor((Color) object);

  //     
  wb.saveToFile("output/CopyComment.xlsx",ExcelVersion.Version2013);
  wb.dispose();
 }
}
주석 복사 효과:

[예시 5]주석 삭제

import com.spire.xls.ExcelVersion;
import com.spire.xls.FileFormat;
import com.spire.xls.Workbook;
import com.spire.xls.Worksheet;

public class DeleteComments {
 public static void main(String[] args) {
  //  Excel  
  Workbook wb = new Workbook();
  wb.loadFromFile("D:\\Desktop\\AddComments.xlsx");
  //     
  Worksheet sheet = wb.getWorksheets().get(0);
  //           ,   
  sheet.getRange().get("G3").getComment().remove();
  //    
  wb.saveToFile("output/DeleteComment.xlsx", ExcelVersion.Version2013);
  wb.dispose();
 }
}
주석 삭제 효과:

Java POI 설정 Excel 지정 셀 에 주석,배경 색 추가

Cell cell = worksheet.getRow(row).getCell(column);
Drawing draw = worksheet.createDrawingPatriarch();
Comment comment = draw.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, row, column, 9, 7));
comment.setString(new XSSFRichTextString(message));//      
cell.setCellComment(comment);
CellStyle cellStyle=workbook.createCellStyle();
cellStyle.setFillForegroundColor(IndexedColors.YELLOW.getIndex()); //    
cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
cell.setCellStyle(cellStyle);
자바 추가,수정,읽 기,복사,엑셀 주석 삭제 실현 에 관 한 이 글 은 여기까지 소개 되 었 습 니 다.  Excel 주석 삭제 내용 을 추가 합 니 다.이전 글 을 검색 하거나 아래 글 을 계속 찾 아 보 세 요.앞으로 도 많은 응원 부 탁 드 리 겠 습 니 다!

좋은 웹페이지 즐겨찾기