EN · DE · RU · FR · ES

#1153: VacationExcelExporter.kt

projectforge-business/src/main/kotlin/org/projectforge/business/vacation/service/VacationExcelExporter.kt Classe Kotlin, projectforge-business/src/main/kotlin/org/projectforge/business/vacation/service/VacationExcelExporter.kt 389 lignes · 331 code · 39 commentaires · 19 vides
Objectif : Fichier source : business/vacation/service/VacationExcelExporter.kt. VacationExcelExporter.kt fait partie de l'application open-source de gestion de projet ProjectForge.

Source (100 premières lignes)

/////////////////////////////////////////////////////////////////////////////
//
// Project ProjectForge Community Edition
//         www.projectforge.org
//
// Copyright (C) 2001-2026 Micromata GmbH, Germany (www.micromata.com)
//
// ProjectForge est sous double licence.
//
// Cette édition communautaire est un logiciel libre ; vous pouvez la redistribuer et/ou
// la modifier selon les termes de la GNU General Public License telle que publiée
// par la Free Software Foundation ; version 3 de la Licence.
//
// Cette édition communautaire est distribuée dans l'espoir qu'elle sera utile,
// mais SANS AUCUNE GARANTIE ; sans même la garantie implicite de
// COMMERCIALISATION ou D'ADÉQUATION À UN USAGE PARTICULIER. Voir la GNU General
// Public License pour plus de détails.
//
// Vous devriez avoir reçu une copie de la GNU General Public License avec
// ce programme ; sinon, consultez http://www.gnu.org/licenses/.
//
/////////////////////////////////////////////////////////////////////////////

package org.projectforge.business.vacation.service

import de.micromata.merlin.excel.ExcelRow
import de.micromata.merlin.excel.ExcelSheet
import de.micromata.merlin.excel.ExcelWorkbook
import mu.KotlinLogging
import org.apache.poi.ss.usermodel.BorderStyle
import org.apache.poi.ss.usermodel.HorizontalAlignment
import org.apache.poi.ss.usermodel.IndexedColors
import org.apache.poi.ss.util.CellRangeAddress
import org.projectforge.business.fibu.EmployeeDO
import org.projectforge.business.vacation.model.VacationDO
import org.projectforge.business.vacation.model.VacationStatus
import org.projectforge.excel.ExcelUtils
import org.projectforge.framework.configuration.ConfigXml
import org.projectforge.framework.i18n.translate
import org.projectforge.framework.persistence.user.api.ThreadLocalUserContext
import org.projectforge.framework.persistence.user.entities.PFUserDO
import org.projectforge.framework.time.DateHelper
import org.projectforge.framework.time.PFDay
import org.projectforge.framework.xmlstream.XmlHelper
import org.springframework.core.io.ByteArrayResource
import org.springframework.http.HttpHeaders
import org.springframework.http.ResponseEntity
import java.io.File
import java.time.LocalDate
import java.time.Month
import java.time.format.TextStyle
import java.util.*

private val log = KotlinLogging.logger {}

/**
 * Exporte les entrées de congés des utilisateurs.
 * @author K. Reinhard (k.reinhard@micromata.de)
 */
object VacationExcelExporter {
  private class Context(val workbook: ExcelWorkbook) {
    lateinit var currentSheet: ExcelSheet
      private set
    val monthSeparatorCols = mutableListOf<Int>()
    val monthSeparationStyle = ExcelUtils.createCellStyle(
      workbook,
      "monthSeparation",
      fillForegroundColor = IndexedColors.BLACK,
    )
    val boldFont = ExcelUtils.createFont(workbook, "bold", bold = true, heightInPoints = 18)
    val monthStyle =
      ExcelUtils.createCellStyle(workbook, "month", font = boldFont, alignment = HorizontalAlignment.CENTER)
    val standardStyle = ExcelUtils.createCellStyle(workbook, "standard", borderStyle = BorderStyle.THIN)
    val standardDayStyle = ExcelUtils.createCellStyle(
      workbook,
      "standardDay",
      alignment = HorizontalAlignment.CENTER,
      borderStyle = BorderStyle.THIN,
    )
    val holidayAndWeekendStyle = ExcelUtils.createCellStyle(
      workbook,
      "holidayWeekendDay",
      alignment = HorizontalAlignment.CENTER,
      fillForegroundColor = IndexedColors.TAN,
      borderStyle = BorderStyle.THIN,
    )
    val vacationStyle = ExcelUtils.createCellStyle(
      workbook,
      "vacationDay",
      fillForegroundColor = IndexedColors.GREEN,
      borderStyle = BorderStyle.THIN,
    )
    val unapprovedVacationStyle = ExcelUtils.createCellStyle(
      workbook,
      "unapprovedVacationDay",
      fillForegroundColor = IndexedColors.GREY_40_PERCENT,
      borderStyle = BorderStyle.THIN,
    )

    fun withSheet(sheet: ExcelSheet) {

Historique Git

868d6abb7 2025 -> 2026
78a38ca8f ExcelUtils.createFont et utilisé par toutes les routines de création de polices Excel.
63081666f En-têtes des fichiers source : 2024 -> 2025.
b6092df09 Copyright 2023 -> 2024
4a4c891d4 VacationExcelExporter : Autofiltre ajouté.

868d6abb7

2025 -> 2026
868d6abb75cd191a892911ac8e45058932cf9074
diff --git a/projectforge-business/src/main/kotlin/org/projectforge/business/vacation/service/VacationExcelExporter.kt b/projectforge-business/src/main/kotlin/org/projectforge/business/vacation/service/VacationExcelExporter.kt
index a245235c2..14fba9917 100644
--- a/projectforge-business/src/main/kotlin/org/projectforge/business/vacation/service/VacationExcelExporter.kt
+++ b/projectforge-business/src/main/kotlin/org/projectforge/business/vacation/service/VacationExcelExporter.kt
@@ -3,7 +3,7 @@
 // Project ProjectForge Community Edition
 //         www.projectforge.org
 //
-// Copyright (C) 2001-2025 Micromata GmbH, Germany (www.micromata.com)
+// Copyright (C) 2001-2026 Micromata GmbH, Germany (www.micromata.com)
 //
 // ProjectForge est sous double licence.
 //

78a38ca8f

ExcelUtils.createFont et utilisé par toutes les routines de création de polices Excel.
78a38ca8fe252bcfd1eddfc95318a6507f33bda2
diff --git a/projectforge-business/src/main/kotlin/org/projectforge/business/vacation/service/VacationExcelExporter.kt b/projectforge-business/src/main/kotlin/org/projectforge/business/vacation/service/VacationExcelExporter.kt
index 1ddbca545..a245235c2 100644
--- a/projectforge-business/src/main/kotlin/org/projectforge/business/vacation/service/VacationExcelExporter.kt
+++ b/projectforge-business/src/main/kotlin/org/projectforge/business/vacation/service/VacationExcelExporter.kt
@@ -67,7 +67,7 @@ object VacationExcelExporter {
       "monthSeparation",
       fillForegroundColor = IndexedColors.BLACK,
     )
-    val boldFont = workbook.createOrGetFont("bold", bold = true, heightInPoints = 18)
+    val boldFont = ExcelUtils.createFont(workbook, "bold", bold = true, heightInPoints = 18)
     val monthStyle =
       ExcelUtils.createCellStyle(workbook, "month", font = boldFont, alignment = HorizontalAlignment.CENTER)
     val standardStyle = ExcelUtils.createCellStyle(workbook, "standard", borderStyle = BorderStyle.THIN)

63081666f

En-têtes des fichiers source : 2024 -> 2025.
63081666f620fb87315f01b817e560e0b2f6a33a
diff --git a/projectforge-business/src/main/kotlin/org/projectforge/business/vacation/service/VacationExcelExporter.kt b/projectforge-business/src/main/kotlin/org/projectforge/business/vacation/service/VacationExcelExporter.kt
index d103929d1..1ddbca545 100644
--- a/projectforge-business/src/main/kotlin/org/projectforge/business/vacation/service/VacationExcelExporter.kt
+++ b/projectforge-business/src/main/kotlin/org/projectforge/business/vacation/service/VacationExcelExporter.kt
@@ -3,7 +3,7 @@
 // Project ProjectForge Community Edition
 //         www.projectforge.org
 //
-// Copyright (C) 2001-2024 Micromata GmbH, Germany (www.micromata.com)
+// Copyright (C) 2001-2025 Micromata GmbH, Germany (www.micromata.com)
 //
 // ProjectForge est sous double licence.
 //

b6092df09

Copyright 2023 -> 2024
b6092df0927c4a3b161e888445f31dcab57493f2
diff --git a/projectforge-business/src/main/kotlin/org/projectforge/business/vacation/service/VacationExcelExporter.kt b/projectforge-business/src/main/kotlin/org/projectforge/business/vacation/service/VacationExcelExporter.kt
index 8a3bef0a8..d103929d1 100644
--- a/projectforge-business/src/main/kotlin/org/projectforge/business/vacation/service/VacationExcelExporter.kt
+++ b/projectforge-business/src/main/kotlin/org/projectforge/business/vacation/service/VacationExcelExporter.kt
@@ -3,7 +3,7 @@
 // Project ProjectForge Community Edition
 //         www.projectforge.org
 //
-// Copyright (C) 2001-2023 Micromata GmbH, Germany (www.micromata.com)
+// Copyright (C) 2001-2024 Micromata GmbH, Germany (www.micromata.com)
 //
 // ProjectForge est sous double licence.
 //

4a4c891d4

VacationExcelExporter : Autofiltre ajouté.
4a4c891d4a0be89b4b329545cd516a7b1c958dcf
diff --git a/projectforge-business/src/main/kotlin/org/projectforge/business/vacation/service/VacationExcelExporter.kt b/projectforge-business/src/main/kotlin/org/projectforge/business/vacation/service/VacationExcelExporter.kt
index 033c555a6..8a3bef0a8 100644
--- a/projectforge-business/src/main/kotlin/org/projectforge/business/vacation/service/VacationExcelExporter.kt
+++ b/projectforge-business/src/main/kotlin/org/projectforge/business/vacation/service/VacationExcelExporter.kt
@@ -30,6 +30,7 @@ import mu.KotlinLogging
 import org.apache.poi.ss.usermodel.BorderStyle
 import org.apache.poi.ss.usermodel.HorizontalAlignment
 import org.apache.poi.ss.usermodel.IndexedColors
+import org.apache.poi.ss.util.CellRangeAddress
 import org.projectforge.business.fibu.EmployeeDO
 import org.projectforge.business.vacation.model.VacationDO
 import org.projectforge.business.vacation.model.VacationStatus
@@ -141,13 +142,16 @@ object VacationExcelExporter {
     sheet.poiSheet.printSetup.landscape = true
     sheet.poiSheet.printSetup.fitWidth = 1.toShort()  // Ne fonctionne pas
     sheet.poiSheet.printSetup.fitHeight = 0.toShort() // Ne fonctionne pas
-    val monthRow = sheet.createRow()
+    val firstRow = sheet.createRow()
     val dateRow = sheet.createRow()
     val weekDayRow = sheet.createRow()
     var currentDate = startDate
     var columnIndex = 0
+    firstRow.getCell(columnIndex).setCellValue(translate("fibu.employees"))
     sheet.setColumnWidth(columnIndex, COL_WIDTH_USER) // Colonne des vacanciers.
-    createMonthSeparationCells(context, ++columnIndex, dateRow, weekDayRow, monthRow)
+    firstRow.getCell(++columnIndex).setCellValue(translate("vacation"))
+    sheet.setColumnWidth(columnIndex, 500) // Colonne si l'employé a des congés ou non.
+    createMonthSeparationCells(context, ++columnIndex, dateRow, weekDayRow, firstRow)
     var paranoiaCounter = 0
     var firstDayOfMonthCol = columnIndex + 1
     val columnIndexMap = mutableMapOf<LocalDate, Int>()
@@ -167,14 +171,14 @@ object VacationExcelExporter {
         // Nouveau mois commencé.
         val monthCell =
           sheet.setMergedRegion(
-            monthRow.rowNum,
-            monthRow.rowNum,
+            firstRow.rowNum,
+            firstRow.rowNum,
             firstDayOfMonthCol,
             columnIndex,
             getMonthString(currentDate.minusMonths(1)),
           )
         monthCell.setCellStyle(context.monthStyle)
-        createMonthSeparationCells(context, ++columnIndex, dateRow, weekDayRow, monthRow)
+        createMonthSeparationCells(context, ++columnIndex, dateRow, weekDayRow, firstRow)
         firstDayOfMonthCol = columnIndex + 1 // Stocke la colonne pour setMergedRegion du nom du mois.
       }
     }
@@ -195,6 +199,7 @@ object VacationExcelExporter {
         }
         currentDate = currentDate.plusDays(1)
       }
+      var firstRowWritten = false
       entry.vacations.forEach { vacation ->
         val vacationStart = PFDay.fromOrNull(vacation.startDate)
         val vacationEnd = PFDay.fromOrNull(vacation.endDate)
@@ -208,6 +213,11 @@ object VacationExcelExporter {
           var current: PFDay = vacationStart