public static void main(String[] args) {
String sourcePath = "L:\\下载文件\\202312011_20231201170318.xlsx";
String targetPath = "L:\\下载文件\\1514-1100-租赁的计量(新租赁准则)–租赁条款&租赁付款额.xlsx";
FileOutputStream fos = null;
try {
// Create a new workbook
Workbook workbook = new Workbook(targetPath);
Workbook workbookSource = new Workbook(sourcePath);
int count = workbookSource.getWorksheets().getCount();
for (int i = 0; i < count; i++) {
IWorksheet iWorksheet = workbook.getWorksheets().get(workbook.getWorksheets().getCount() - 1);
workbookSource.getWorksheets().get(i).copyAfter(iWorksheet);
}
fos = new FileOutputStream(targetPath);
workbook.save(fos);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (null != fos) {
try {
fos.close();
} catch (Exception var2) {
}
}
}
}
使用GC的copyAfter
将源文件的sheet复制到目标文件中后,sheet的字体样式会变
|
|