Java 추가,수정,읽 기,복사,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 주석 삭제 내용 을 추가 합 니 다.이전 글 을 검색 하거나 아래 글 을 계속 찾 아 보 세 요.앞으로 도 많은 응원 부 탁 드 리 겠 습 니 다!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
JPA + QueryDSL 계층형 댓글, 대댓글 구현(2)이번엔 전편에 이어서 계층형 댓글, 대댓글을 다시 리팩토링해볼 예정이다. 이전 게시글에서는 계층형 댓글, 대댓글을 구현은 되었지만 N+1 문제가 있었다. 이번에는 그 N+1 문제를 해결해 볼 것이다. 위의 로직은 이...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.