이 간결한 자습서는 Excel 시트를 Java의 다른 통합 문서에 복사하는 방법에 대한 세부 정보를 제공합니다. 입력된 Excel 파일을 XLSX 또는 XLS 파일 확장자로 로드한 후 Java copy excel worksheet 기능을 사용할 수 있습니다. 요구 사항에 따라 인덱스 번호 또는 시트 이름을 사용하여 시트를 복사할 수 있습니다.
Excel 시트를 Java의 다른 통합 문서로 복사하는 단계
- Maven 리포지토리에서 Aspose.Cells에 대한 참조를 추가하여 Excel 시트 복사
- 입력 데이터를 복사하기 위해 원본 Excel 파일을 Workbook 클래스 개체에 로드합니다.
- 출력 Excel 파일의 시트에 액세스
- 시트의 색인 번호를 사용하여 Excel 시트를 다른 통합 문서로 Copy
- 복사된 워크시트와 함께 출력 Excel 통합 문서 저장
Java Excel 시트 복사 기능을 사용하려면 몇 번의 API 호출만 하면 됩니다. 워크시트의 색인을 변경하여 워크시트 복사 프로세스를 사용자 정의할 수 있습니다. 예를 들어 원본 워크시트에서 워크시트를 복사하고 색인 번호만 변경하여 출력 Excel 통합 문서의 모든 색인에 붙여넣을 수 있습니다.
Excel 시트를 Java의 다른 통합 문서로 복사하는 코드
import com.aspose.cells.License; | |
import com.aspose.cells.Workbook; | |
import com.aspose.cells.WorksheetCollection; | |
public class CopyExcelSheetToAnotherWorkbookInJava { | |
public static void main(String[] args) throws Exception { | |
// main method to copy Excel sheet to another workbook using Java | |
// Use Aspose.Cells license to remove watermark in the | |
// output Excel file after copying the sheet | |
License licenseForSheetCopy = new License(); | |
licenseForSheetCopy.setLicense("Aspose.Cells.lic"); | |
//Load input and create a new Workbook to copy Excel worksheet | |
Workbook input = new Workbook("input.xlsx"); | |
Workbook output = new Workbook(); | |
//Create a WorksheetCollection object to access the sheets | |
// of output file | |
WorksheetCollection sheets = output.getWorksheets(); | |
//Copy input sheet to a new sheet in the other file | |
sheets.get(0).copy(input.getWorksheets().get(0)); | |
//Save output Excel worksheet with the copied sheet in it | |
output.save("workbook.xlsx"); | |
} | |
} |
이 자습서에서는 Java Excel 시트를 다른 통합 문서에 복사 기능을 사용하여 통합할 수 있는 방법을 살펴보았습니다. 수식이 대상 시트에 유효하지 않은 경우에만 값 복사를 지원하는 copy() 함수의 CopyOptions 클래스 개체, 이름 복사 옵션, 매크로 유지 옵션 및 기타 여러 기능을 사용하여 복사 작업을 제어할 수 있습니다. 잘.
이 문서에서는 Excel 워크시트 간에 데이터를 복사하여 붙여넣는 방법에 대해 설명했습니다. 단, 세포 합치기에 대해 알고 싶다면 Java를 사용하여 Excel에서 셀을 병합하는 방법 글을 참고하세요.