Sub btnCreateXLS_Action
#If TestAll
Dim Send As Button
Send = Sender
LogDebug("Button " & Send.Text & "_Action")
#End if
'User alert if items are not ready to be exported :
'No user data defined, that's same start and end dates for the search period,
'The field columns are bad configured or are left with the default values.
#Region VerifyIfAllPArametersToCreateExcelDoc
If txtNomCandPDF.Text="" Or txtIdentifiantPDF.Text="" Or txtCPVillePDF.Text="" Or _
tblViewPdf.GetColumnHeader(0).StartsWith("Colonne") Or tblViewPdf.GetColumnHeader(1).StartsWith("Colonne") Or _
tblViewPdf.GetColumnHeader(2).StartsWith("Colonne") Or (boxDateStartPdf.DateTicks = boxDateEndPdf.DateTicks) Then
'Test user data
If txtNomCandPDF.Text="" Or txtIdentifiantPDF.Text="" Or txtCPVillePDF.Text="" Then
fx.Msgbox2(MainForm, "Vous n'avez pas renseigné vos Nom, prénom ou" & _
CRLF & "Identifiant ou ville et code postal." & _
CRLF & "Dans les champs prévus à cet effet.", _
MainForm.Title & "-Export desdonnées","Ok","","",fx.MSGBOX_INFORMATION)
'Test the start and end dates for the search
Else If boxDateStartPdf.DateTicks = boxDateEndPdf.DateTicks Then
fx.Msgbox2(MainForm, "Vous avez choisi, ou laissé, des dates identiques de début" & _
CRLF & "et de fin de période. Il y a de fortes chances pour qu'il" & _
CRLF & "n'y ait aucune données à afficher. Choississez au minimum" & _
CRLF & "une exportation sur 2 ou 3 jours.", _
MainForm.Title & "-Export des données","Ok","","",fx.MSGBOX_INFORMATION)
'Test if the columns stay with default values
Else If (tblViewPdf.GetColumnHeader(0).StartsWith("Colonne") Or _
tblViewPdf.GetColumnHeader(1).StartsWith("Colonne") Or _
tblViewPdf.GetColumnHeader(2).StartsWith("Colonne")) Then
fx.Msgbox2(MainForm, "Vous n'avez pas choisi de champs à exporter hormis les 3" & _
CRLF & "colonnes prédéfinies. Au minimum vous devez choisir 3" & _
CRLF & "champs et remplacer les colonnes prédéfinies par des" & _
CRLF & "champs proposés dans la liste au dessus." & _
CRLF & "Utilisez le glisser-déplacer pour cela.", _
MainForm.Title & "-Export des données","Ok","","",fx.MSGBOX_INFORMATION)
End If
'In all of these cases return to the application and don't do data extraction
Return
End If
#End Region
Dim Table As List
Table.Initialize
'Compute the datas from table in the list
Table = ComputeDatasForExport
'If there are data to export
If Table.Size > 0 Then
#Region CreateWorkbook
'Create workbook
Dim wb As PoiWorkbook
'(ndp: Voir par la suite si on ajoute au meme classeur les feuilles mois par mois)
wb.InitializeNew(True) 'create new xlsx workbook (False for xls, True for xlsx)
'Ajoute le mois en cours avec pour nom de feuille Mois de xxxx
Dim sheet1 As PoiSheet = wb.AddSheet("Mois " & DateTime.GetMonth(boxDateStartPdf.DateTicks), 0)
'Fusionne x cellules sur la première ligne, de 0 à x sur ligne 0
sheet1.AddMergedRegion(0, 0, tblViewPdf.ColumnsCount - 1, 0)
'Créé la première ligne, 0
Dim row As PoiRow = sheet1.CreateRow(0)
'Créé la première cellule et son contenu sur 6 cellules,
'Nom, prénom du candidat, identifiant pole emploi, code postal et ville
Dim cell As PoiCell = row.CreateCellString(0, txtNomCandPDF.Text & " - Identifiant: " & _
txtIdentifiantPDF.Text & " - " & _
txtCPVillePDF.Text)
'Créé la seconde ligne, 1
Dim row As PoiRow = sheet1.CreateRow(1)
row.CreateCellString(1," ")
row.Height = 30
Dim cs As PoiCellStyle
cs.Initialize(wb)
cs.HorizontalAlignment = cs.HORIZONTAL_CENTER
Dim headfont As PoiFont
headfont.Initialize(wb)
headfont.Bold = True
headfont.Size = 12
cs.SetFont(headfont)
cell.CellStyle = cs
Dim titleStyle As PoiCellStyle
titleStyle.Initialize(wb)
titleStyle.BorderLeft = titleStyle.BORDER_THIN
titleStyle.BorderTop = titleStyle.BORDER_THIN
titleStyle.BorderRight = titleStyle.BORDER_THIN
titleStyle.BorderBottom = titleStyle.BORDER_THIN
titleStyle.ForegroundColor = fx.Colors.LightGray
titleStyle.HorizontalAlignment = titleStyle.HORIZONTAL_CENTER
Dim font As PoiFont
font.Initialize(wb)
font.Bold = True
font.Size = 13
titleStyle.SetFont(font)
Dim titleRow As PoiRow = sheet1.CreateRow(2) 'third row with the name of fields
'Fills all cells with each field name of SQL request and adjust their width depends the name long
Dim xz As Int
For xz = 0 To tblViewPdf.ColumnsCount - 1
titleRow.CreateCellString(xz, tblViewPdf.GetColumnHeader(xz))
sheet1.SetColumnWidth(xz, (256 * (tblViewPdf.GetColumnHeader(xz).Length*1.5)))
Next
'Put the style for the fields row
SetStyleToRowCells(titleRow, titleStyle)
'Declare a style for the date field
Dim dateStyle As PoiCellStyle
dateStyle.Initialize(wb)
dateStyle.SetDataFormat(wb, "d/M/yyyy")
dateStyle.HorizontalAlignment = dateStyle.HORIZONTAL_CENTER
dateStyle.VerticalAlignment = dateStyle.VERTICAL_CENTER
'Fills the data in rows now
Dim classicStyle As PoiCellStyle
classicStyle.Initialize(wb)
classicStyle.HorizontalAlignment = classicStyle.HORIZONTAL_LEFT
classicStyle.VerticalAlignment = classicStyle.VERTICAL_CENTER
Dim saveFormatDate As String
saveFormatDate = DateTime.DateFormat
DateTime.DateFormat = "dd/MM/yyyy"
Dim i As Int
For i = 0 To Table.Size - 1
Dim row As PoiRow = sheet1.CreateRow(i + 3) 'i+3 parce que nous sommes à la 4ème ligne
Dim tmpStrFields() As String
tmpStrFields = Table.Get(i)
For xz = 0 To tblViewPdf.ColumnsCount - 1
'Put in each cell the data if it's not hull
If Not(tmpStrFields(xz)=Null) Then
'If data is date put the good string instead a long
If tblViewPdf.GetColumnHeader(xz).ToLowerCase.Contains("date") Then
Dim tmpLong As Long
tmpLong = tmpStrFields(xz)
row.CreateCellString(xz, DateTime.Date(tmpLong))
Else
If tmpStrFields(xz)="YES" Then
row.CreateCellString(xz, "Oui")
Else if tmpStrFields(xz) = "NO" Then
row.CreateCellString(xz, "Non")
Else
row.CreateCellString(xz, tmpStrFields(xz))
End If
End If
'If data is date put the good format
If tblViewPdf.GetColumnHeader(xz).ToLowerCase.Contains("date") Then
row.GetCell(xz).CellStyle = dateStyle
Else
row.GetCell(xz).CellStyle = classicStyle
End If
End If
Next
Next
DateTime.DateFormat = saveFormatDate
'Verfify if the folder to save is set or not and ask user to do it
If UserPathExport = "" Then
Dim retDlg As Int
retDlg = fx.Msgbox2(MainForm, "Vous n'avez pas précisé un chemin d'accès dans" & CRLF & _
"le dossier utilisateur pour le fichier Excel." & CRLF & _
"Voulez-vous l'enregistrer à l'emplacement par défaut :" & CRLF & _
File.DirData("TrackingJobSearch") & " ?", _
MainForm.Title & "-Dossier d'export", _
"Oui", "", "Non", fx.MSGBOX_CONFIRMATION)
If retDlg = fx.DialogResponse.POSITIVE Then
UserPathExport = File.DirData("TrackingJobSearch")
Else
btnCallDlgPath_Action
End If
End If
wb.Save(UserPathExport, "JobSF-SuiviMois-" & _
DateTime.GetMonth(boxDateStartPdf.DateTicks) & _
"-" & _
DateTime.GetYear(boxDateStartPdf.DateTicks) & _
".xlsx")
wb.Close
fx.Msgbox2(MainForm, "Fichier Excel :" & CRLF & _
"JobSF-SuiviMois-" & DateTime.GetMonth(boxDateStartPdf.DateTicks) & _
"-" & DateTime.GetYear(boxDateEndPdf.DateTicks) & ".xlsx" & CRLF & _
"créé avec succès.", _
MainForm.Title & "-Exportation Excel", "Ok", "", "", fx.MSGBOX_INFORMATION)
#End Region
Else
#Region NoDataToExport
fx.Msgbox2(MainForm, "Il n'y a aucune donnée retrouvé pour le fichier Excel." & CRLF & _
"Vérifier les bornes de dates ou la base de données.", _
MainForm.Title & "-Exportation Excel", "Ok", "", "", fx.MSGBOX_WARNING)
#End Region
End If
End Sub