Экспорт пакета в excel

This commit is contained in:
2023-12-07 00:09:10 +03:00
parent 9b46d395df
commit 540c041408
9 changed files with 182 additions and 9 deletions

View File

@@ -1,5 +1,7 @@
package Visual_DVM_2021.Passes.All;
import Common.Utils.Utils;
import Visual_DVM_2021.Passes.Pass_2021;
import org.apache.commons.io.FileUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
@@ -13,7 +15,7 @@ public class TestPass extends Pass_2021 {
}
@Override
protected void body() throws Exception {
File file = new File("kek.xls");
File file = Utils.getTempFileName("table");
//--
Workbook book = new HSSFWorkbook();
Sheet sheet = book.createSheet("Birthdays");
@@ -42,7 +44,15 @@ public class TestPass extends Pass_2021 {
sheet.autoSizeColumn(1);
// Записываем всё в файл
book.write(new FileOutputStream(file));
FileOutputStream stream = new FileOutputStream(file);
book.write(stream);
book.close();
stream.close();
///--
File res = new File("kek.xls");
FileUtils.copyFile(file, res);
book= null;
stream = null;
file = null;
}
}