промежуточный. создание таблицы excel
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
package Visual_DVM_2021.Passes.All;
|
||||
import Visual_DVM_2021.Passes.Pass_2021;
|
||||
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;
|
||||
public class TestPass extends Pass_2021 {
|
||||
@Override
|
||||
protected boolean needsAnimation() {
|
||||
@@ -7,6 +13,36 @@ public class TestPass extends Pass_2021 {
|
||||
}
|
||||
@Override
|
||||
protected void body() throws Exception {
|
||||
File file = new File("kek.xls");
|
||||
//--
|
||||
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);
|
||||
|
||||
// Записываем всё в файл
|
||||
book.write(new FileOutputStream(file));
|
||||
book.close();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user