Files
VisualSapfor/src/Visual_DVM_2021/Passes/All/TestPass.java

59 lines
1.8 KiB
Java
Raw Normal View History

package Visual_DVM_2021.Passes.All;
2023-12-07 00:09:10 +03:00
import Common.Utils.Utils;
import Visual_DVM_2021.Passes.Pass_2021;
2023-12-07 00:09:10 +03:00
import org.apache.commons.io.FileUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import java.io.File;
import java.io.FileOutputStream;
import java.util.Date;
2023-09-17 22:13:42 +03:00
public class TestPass extends Pass_2021 {
2023-11-08 23:13:16 +03:00
@Override
protected boolean needsAnimation() {
return super.needsAnimation();
}
@Override
protected void body() throws Exception {
2023-12-07 00:09:10 +03:00
File file = Utils.getTempFileName("table");
2023-12-06 18:52:05 +03:00
//--
Workbook book = new HSSFWorkbook();
Sheet sheet = book.createSheet("Birthdays");
// Нумерация начинается с нуля
Row row = sheet.createRow(0);
// Мы запишем имя и дату в два столбца
// имя будет String, а дата рождения --- Date,
// формата dd.mm.yyyy
Cell name = row.createCell(0);
name.setCellValue("John");
Cell birthdate = row.createCell(1);
DataFormat format = book.createDataFormat();
CellStyle dateStyle = book.createCellStyle();
dateStyle.setDataFormat(format.getFormat("dd.mm.yyyy"));
birthdate.setCellStyle(dateStyle);
// Нумерация лет начинается с 1900-го
birthdate.setCellValue(new Date(110, 10, 10));
// Меняем размер столбца
sheet.autoSizeColumn(1);
// Записываем всё в файл
2023-12-07 00:09:10 +03:00
FileOutputStream stream = new FileOutputStream(file);
book.write(stream);
book.close();
2023-12-07 00:09:10 +03:00
stream.close();
///--
File res = new File("kek.xls");
FileUtils.copyFile(file, res);
book= null;
stream = null;
file = null;
2023-11-08 23:13:16 +03:00
}
2023-09-17 22:13:42 +03:00
}