IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

ASP.NET MVC Discussion :

Problème concernant la saisie des dates


Sujet :

ASP.NET MVC

  1. #1
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Septembre 2010
    Messages
    67
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 33
    Localisation : Canada

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2010
    Messages : 67
    Points : 61
    Points
    61
    Par défaut Problème concernant la saisie des dates
    Bonjour les experts,

    Permettez moi d'expliquer mon problem , j'ai fait des fonctions qui permettent de crée un rapport en format Excel (.xls) en ASP.NET MVC qui permet de saisir certaines DATA de la base de donner .

    Toutes les data se saisie correctement sauf les dates ( champs vide dans les rapports)

    J'aimerais savoir en avantage pourquoi et qu'es ce que je peux faire pour afficher les dates inscrit dans la BD dans mon rapport ...

    C'est ici ou je crois avoir fait une erreur....dans la generation du rapport

    Mercie en avance pour tout le monde!
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
      public ActionResult GenererRapport(int? cmbClient, int? cmbProjet, int? cmbProbill)
            {
                string fichier;
                //les clients concernes
                var cl = (from a in db.Clients where a.ID_Client == cmbClient select new { Nom = a.Nom, Prenom = a.Prenom }).ToArray();
     
                //les projets concernes
                var pr = (from a in db.Projects where a.ID_Projet == cmbProjet select new { Nom = a.NomProjet, Adresa = a.Ville + "," + a.NoCivique + " " + a.NomRue }).ToArray();
                //les factures idprobill >=0
          var list1 = (from a in db.DetailFDTs
                             where a.Facture == cmbProbill && a.ID_Projet == cmbProjet
                                orderby a.Facture,a.ID_Statut ascending
                                join b in db.VracFournisseurs on a.IdVrac equals b.ID
                                join c in db.Vracs on b.IdVrac equals c.IdVrac
                                join d in db.Fournisseurs on a.ID_Fournisseur equals d.ID_Fournisseur
                                join e in db.Equipements on a.ID_Equipement equals e.ID_Equipement
                                join f in db.FDTs on a.IDFDT  equals f.IDFDT
                                join em in db.Employees on f.ID_Employee  equals em.ID_Employee
                                select new { a.Facture, a.IDFDT, a.Description, a.Duree, c.Materiau, d.NomLegal, e.NomEquipement, a.No_Voyage, a.No_Tonnes,a.ID_Projet_out, a.Doc_in,a.Date,a.Prix_UM,em.Nom,em.Prenom }).ToArray();
     
                    //les factures idprobill <0
                var list2 = (from a in db.DetailFDTs
                                where a.ID_Projet==cmbProjet
                                orderby a.Facture,a.ID_Statut ascending
                                join b in db.VracFournisseurs on a.IdVrac equals b.ID
                                join c in db.Vracs on b.IdVrac equals c.IdVrac
                                join d in db.Fournisseurs on a.ID_Fournisseur equals d.ID_Fournisseur
                                join e in db.Equipements on a.ID_Equipement equals e.ID_Equipement
                                join f in db.FDTs on a.IDFDT  equals f.IDFDT
                                join em in db.Employees on f.ID_Employee  equals em.ID_Employee
                                select new { a.Facture, a.IDFDT, a.Description, a.Duree, c.Materiau, d.NomLegal, e.NomEquipement, a.No_Voyage, a.No_Tonnes, a.ID_Projet_out, a.Doc_in, a.Date,a.Prix_UM, em.Nom, em.Prenom }).ToArray();
     
     
                fichier = Server.MapPath(@"\Content\Rapport\rapport.xls");
                #region on vérifie si le fichier existe bien;
                //Si le fichier n'existe pas, erreur
                FileInfo fi = new FileInfo(fichier);
    Et voici le code de la page pour vous permettre a mieux comprendre et s'orienter

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Entity;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using ESA.Models;
    using System.IO;
    using System.Text;
     
    using NPOI.HSSF.UserModel;
    using OfficeOpenXml;
     
    using System.Globalization;
     
    namespace ESA.Controllers
    {
        public class RapportsController : Controller
        {
            private ESADBContext db = new ESADBContext();
            //
            // GET: /Rapports/
     
           public ActionResult Index()
           {
                 return View();
           }
     
     
            public PartialViewResult faitTonChoix()
            {
                List<Object> options = new List<Object>();
                options.Add(new{ID="1",option="Client"});
               // options.Add(new { ID = "2", option = "Projet" });
               // options.Add(new { ID = "3", option = "Probill" });
                ViewBag.options =new SelectList(options,"ID","option");
                return PartialView();
            }
            [HttpPost]
            public JsonResult takeClient()
            {
                var l_client = (from a in db.Clients orderby a.NomCompagnie select new { ID = a.ID_Client, Nom = a.NomCompagnie }).ToArray();
                return Json(l_client);
            }
     
            [HttpPost]
            public JsonResult takeProjet(int searchedValue)
            {
                 var l_proj = (from a in db.Projects orderby a.NomProjet where a.ID_Client == searchedValue select new { ID = a.ID_Projet, Nom = a.NomProjet }).ToArray();
                 return Json(l_proj);
            }
            [HttpPost]
            public JsonResult takeProbill(int searchedValue)
            {
                var l_proB = (from a in db.DetailFDTs orderby a.Facture where a.ID_Projet == searchedValue select new { ID = a.Facture, Nom = a.Facture }).Distinct().ToArray();
                return Json(l_proB);
            }
            [HttpPost]
            public JsonResult getClient(int id)
            {
                var cl = (from a in db.Clients where a.ID_Client == id select new { Nom = a.Nom, Prenom = a.Prenom }).ToArray();
                return Json(cl);
            }
            [HttpPost]
            public JsonResult getProjet(int id)
            {
                var cl = (from a in db.Projects where a.ID_Projet == id select new { Nom = a.NomProjet, Adresa = a.Ville+","+a.NoCivique+" "+a.NomRue }).ToArray();
                return Json(cl);
            }
            [HttpPost]
            public JsonResult getProbill(int id,int id_projet)
            {
                if (id >= 0)
                {
                    var list = (from a in db.DetailFDTs
                                where a.Facture == id&&a.ID_Projet==id_projet
                                orderby a.Facture,a.ID_Statut ascending
                                join b in db.VracFournisseurs on a.IdVrac equals b.ID
                                join c in db.Vracs on b.IdVrac equals c.IdVrac
                                join d in db.Fournisseurs on a.ID_Fournisseur equals d.ID_Fournisseur
                                join e in db.Equipements on a.ID_Equipement equals e.ID_Equipement
                                select new { a.Facture, a.IDFDT, a.Description, a.Duree, c.Materiau, d.NomLegal, e.NomEquipement, a.No_Voyage, a.No_Tonnes, a.Prix_UM, a.Prix_Total, a.Doc_in }).ToArray();
                    return Json(list);
                }
                else
                {
                    var list = (from a in db.DetailFDTs
                                where a.ID_Projet==id_projet
                                orderby a.Facture,a.ID_Statut ascending
                                join b in db.VracFournisseurs on a.IdVrac equals b.ID
                                join c in db.Vracs on b.IdVrac equals c.IdVrac
                                join d in db.Fournisseurs on a.ID_Fournisseur equals d.ID_Fournisseur
                                join e in db.Equipements on a.ID_Equipement equals e.ID_Equipement
                                select new { a.Facture, a.IDFDT, a.Description, a.Duree, c.Materiau, d.NomLegal, e.NomEquipement, a.No_Voyage, a.No_Tonnes, a.Prix_UM, a.Prix_Total, a.Doc_in }).ToArray();
                    return Json(list);
                }
     
            }
     
     
     
            public ActionResult GenererRapport(int? cmbClient, int? cmbProjet, int? cmbProbill)
            {
                string fichier;
                //les clients concernes
                var cl = (from a in db.Clients where a.ID_Client == cmbClient select new { Nom = a.Nom, Prenom = a.Prenom }).ToArray();
     
                //les projets concernes
                var pr = (from a in db.Projects where a.ID_Projet == cmbProjet select new { Nom = a.NomProjet, Adresa = a.Ville + "," + a.NoCivique + " " + a.NomRue }).ToArray();
                //les factures idprobill >=0
          var list1 = (from a in db.DetailFDTs
                             where a.Facture == cmbProbill && a.ID_Projet == cmbProjet
                                orderby a.Facture,a.ID_Statut ascending
                                join b in db.VracFournisseurs on a.IdVrac equals b.ID
                                join c in db.Vracs on b.IdVrac equals c.IdVrac
                                join d in db.Fournisseurs on a.ID_Fournisseur equals d.ID_Fournisseur
                                join e in db.Equipements on a.ID_Equipement equals e.ID_Equipement
                                join f in db.FDTs on a.IDFDT  equals f.IDFDT
                                join em in db.Employees on f.ID_Employee  equals em.ID_Employee
                                select new { a.Facture, a.IDFDT, a.Description, a.Duree, c.Materiau, d.NomLegal, e.NomEquipement, a.No_Voyage, a.No_Tonnes,a.ID_Projet_out, a.Doc_in,a.Date,a.Prix_UM,em.Nom,em.Prenom }).ToArray();
     
                    //les factures idprobill <0
                var list2 = (from a in db.DetailFDTs
                                where a.ID_Projet==cmbProjet
                                orderby a.Facture,a.ID_Statut ascending
                                join b in db.VracFournisseurs on a.IdVrac equals b.ID
                                join c in db.Vracs on b.IdVrac equals c.IdVrac
                                join d in db.Fournisseurs on a.ID_Fournisseur equals d.ID_Fournisseur
                                join e in db.Equipements on a.ID_Equipement equals e.ID_Equipement
                                join f in db.FDTs on a.IDFDT  equals f.IDFDT
                                join em in db.Employees on f.ID_Employee  equals em.ID_Employee
                                select new { a.Facture, a.IDFDT, a.Description, a.Duree, c.Materiau, d.NomLegal, e.NomEquipement, a.No_Voyage, a.No_Tonnes, a.ID_Projet_out, a.Doc_in, a.Date,a.Prix_UM, em.Nom, em.Prenom }).ToArray();
     
     
                fichier = Server.MapPath(@"\Content\Rapport\rapport.xls");
                #region on vérifie si le fichier existe bien;
                //Si le fichier n'existe pas, erreur
                FileInfo fi = new FileInfo(fichier);
     
                if (!fi.Exists)
                {
                    //c'est pas ça qu'il faut vérifier mais la dm
                    ViewBag.Message = "Oops! Problème avec le fichier";
     
                    return View("Erreur");
                }
                #endregion
                try
                    {
                        // Opening the Excel template...
                        FileStream fs =new FileStream(fichier, FileMode.Open, FileAccess.ReadWrite);
     
                        // Getting the complete workbook...
                        HSSFWorkbook templateWorkbook = new HSSFWorkbook(fs, true);
     
                        // Getting the worksheet by its name...
                        HSSFSheet sheet = templateWorkbook.GetSheet("Feuil1");
     
                        //afficher client
                        HSSFRow clientCell = sheet.GetRow(1);
                        clientCell.GetCell(1).SetCellValue(cl[0].Nom +"  "+ cl[0].Prenom);
     
                        // projet
                        if (cmbProjet!=-1)
                        {
                            HSSFRow projetCell = sheet.GetRow(2);
                            projetCell.GetCell(1).SetCellValue(pr[0].Nom + "  " + pr[0].Adresa);
     
                        }
                        int row = 5;
                        //affichage ligne par ligne
                        if (cmbProbill>=0)
                        {
                            foreach (var item in list1)
                            {
                                row++;
                                HSSFRow valueDateCell = sheet.GetRow(row);
                                valueDateCell.GetCell(0).SetCellValue(item.Date.ToString());
     
                                HSSFRow valuePrenomCell = sheet.GetRow(row);
                                valuePrenomCell.GetCell(1).SetCellValue(item.Nom +" "+ item.Prenom);
     
                                HSSFRow valueEquiCell = sheet.GetRow(row);
                                valueEquiCell.GetCell(2).SetCellValue(item.NomEquipement);
     
                                HSSFRow valueTacheCell = sheet.GetRow(row);
                                valueTacheCell.GetCell(3).SetCellValue(item.Description);
     
                                HSSFRow valueVracCell = sheet.GetRow(row);
                                valueVracCell.GetCell(4).SetCellValue(item.Materiau);
     
                                HSSFRow valueTonneCell = sheet.GetRow(row);
                                valueTonneCell.GetCell(5).SetCellValue(item.No_Tonnes);
     
                                HSSFRow valueVoyageCell = sheet.GetRow(row);
                                valueVoyageCell.GetCell(6).SetCellValue(item.No_Voyage);
     
                                HSSFRow valueSortieCell = sheet.GetRow(row);
                                valueSortieCell.GetCell(7).SetCellValue(item.ID_Projet_out);
     
                                HSSFRow valueFournisseurCell = sheet.GetRow(row);
                                valueFournisseurCell.GetCell(8).SetCellValue(item.NomLegal);
     
                                HSSFRow valueFactureCell = sheet.GetRow(row);
                                valueFactureCell.GetCell(9).SetCellValue(item.Facture);
     
                                HSSFRow valuePrixCell = sheet.GetRow(row);
                                valuePrixCell.GetCell(10).SetCellValue(item.Prix_UM);
                            }
                       }
                    else
                       {
                            foreach (var item in list2)
                            {
                                row++;
                                HSSFRow valueDateCell = sheet.GetRow(row);
                                valueDateCell.GetCell(0).SetCellValue(item.Date.ToString());
     
                                HSSFRow valuePrenomCell = sheet.GetRow(row);
                                valuePrenomCell.GetCell(1).SetCellValue(item.Nom +"  "+ item.Prenom);
     
                                HSSFRow valueEquiCell = sheet.GetRow(row);
                                valueEquiCell.GetCell(2).SetCellValue(item.NomEquipement);
     
                                HSSFRow valueTacheCell = sheet.GetRow(row);
                                valueTacheCell.GetCell(3).SetCellValue(item.Description);
     
                                HSSFRow valueVracCell = sheet.GetRow(row);
                                valueVracCell.GetCell(4).SetCellValue(item.Materiau);
     
                                HSSFRow valueTonneCell = sheet.GetRow(row);
                                valueTonneCell.GetCell(5).SetCellValue(item.No_Tonnes);
     
                                HSSFRow valueVoyageCell = sheet.GetRow(row);
                                valueVoyageCell.GetCell(6).SetCellValue(item.No_Voyage);
     
                                HSSFRow valueSortieCell = sheet.GetRow(row);
                                valueSortieCell.GetCell(7).SetCellValue(item.ID_Projet_out);
     
                                HSSFRow valueFournisseurCell = sheet.GetRow(row);
                                valueFournisseurCell.GetCell(8).SetCellValue(item.NomLegal);
     
                             HSSFRow valueFactureCell = sheet.GetRow(row);
                       valueFactureCell.GetCell(9).SetCellValue(item.Facture);
     
                                HSSFRow valuePrixCell = sheet.GetRow(row);
                                valuePrixCell.GetCell(10).SetCellValue(item.Prix_UM);
                            }
                        }
                        if (cmbProjet==-1)
                        {
                            var l_proj = (from a in db.Projects orderby a.NomProjet where a.ID_Client == cmbClient select new { ID = a.ID_Projet, Nom = a.NomProjet }).ToArray();
                            foreach (var item1 in l_proj)
                            {
                                var list3 = (from a in db.DetailFDTs
                                             where a.ID_Projet == item1.ID
                                             orderby a.Facture, a.ID_Statut ascending
                                             join b in db.VracFournisseurs on a.IdVrac equals b.ID
                                             join c in db.Vracs on b.IdVrac equals c.IdVrac
                                             join d in db.Fournisseurs on a.ID_Fournisseur equals d.ID_Fournisseur
                                             join e in db.Equipements on a.ID_Equipement equals e.ID_Equipement
                                             join f in db.FDTs on a.IDFDT equals f.IDFDT
                                             join em in db.Employees on f.ID_Employee equals em.ID_Employee
                                             select new { a.Facture, a.IDFDT, a.Description, a.Duree, c.Materiau, d.NomLegal, e.NomEquipement, a.No_Voyage, a.No_Tonnes, a.ID_Projet_out, a.Doc_in, a.Date, a.Prix_UM, em.Nom, em.Prenom }).ToArray();
                                foreach (var item in list3)
                                {
                                    row++;
                                    HSSFRow valueDateCell = sheet.GetRow(row);
                                    valueDateCell.GetCell(0).SetCellValue(item.Date.ToString());
     
                                    HSSFRow valuePrenomCell = sheet.GetRow(row);
                                    valuePrenomCell.GetCell(1).SetCellValue(item.Nom + "  " + item.Prenom);
     
                                    HSSFRow valueEquiCell = sheet.GetRow(row);
                                    valueEquiCell.GetCell(2).SetCellValue(item.NomEquipement);
     
                                    HSSFRow valueTacheCell = sheet.GetRow(row);
                                    valueTacheCell.GetCell(3).SetCellValue(item.Description);
     
                                    HSSFRow valueVracCell = sheet.GetRow(row);
                                    valueVracCell.GetCell(4).SetCellValue(item.Materiau);
     
                                    HSSFRow valueTonneCell = sheet.GetRow(row);
                                    valueTonneCell.GetCell(5).SetCellValue(item.No_Tonnes);
     
                                    HSSFRow valueVoyageCell = sheet.GetRow(row);
                                    valueVoyageCell.GetCell(6).SetCellValue(item.No_Voyage);
     
                                    HSSFRow valueSortieCell = sheet.GetRow(row);
                                    valueSortieCell.GetCell(7).SetCellValue(item.ID_Projet_out);
     
                                    HSSFRow valueFournisseurCell = sheet.GetRow(row);
                                    valueFournisseurCell.GetCell(8).SetCellValue(item.NomLegal);
     
       HSSFRow valueFactureCell = sheet.GetRow(row);
                                     valueFactureCell.GetCell(9).SetCellValue(item.Facture);
     
                                    HSSFRow valuePrixCell = sheet.GetRow(row);
                                    valuePrixCell.GetCell(10).SetCellValue(item.Prix_UM);
                                }
                            }
     
                        }
                      // Forcing formula recalculation...
                      //sheet.ForceFormulaRecalculation = true;
     
                      MemoryStream ms = new MemoryStream();
     
                       // Writing the workbook content to the FileStream...
                      templateWorkbook.Write(ms);
                      return File(ms.ToArray(), "application/vnd.ms-excel", Server.HtmlEncode("Rapport.xls"));
     
                    }
                    catch (Exception ex)
                    {
                        ViewBag.Message = "Oops! Problème avec le fichier";
     
                        return View("Erreur");
                    }
            }
     
     
     
     
            // GET: /Rapports/Details/5
     
            public ActionResult Details(int id)
            {
                return View();
            }
     
            //
            // GET: /Rapports/Create
     
            public ActionResult Create()
            {
                return View();
            } 
     
            //
            // POST: /Rapports/Create
     
            [HttpPost]
            public ActionResult Create(FormCollection collection)
            {
                try
                {
                    // TODO: Add insert logic here
     
                    return RedirectToAction("Index");
                }
                catch
                {
                    return View();
                }
            }
     
            //
            // GET: /Rapports/Edit/5
     
            public ActionResult Edit(int id)
            {
                return View();
            }
     
            //
            // POST: /Rapports/Edit/5
     
            [HttpPost]
            public ActionResult Edit(int id, FormCollection collection)
            {
                try
                {
                    // TODO: Add update logic here
     
                    return RedirectToAction("Index");
                }
                catch
                {
                    return View();
                }
            }
     
            //
            // GET: /Rapports/Delete/5
     
            public ActionResult Delete(int id)
            {
                return View();
            }
     
            //
            // POST: /Rapports/Delete/5
     
            [HttpPost]
            public ActionResult Delete(int id, FormCollection collection)
            {
                try
                {
                    // TODO: Add delete logic here
     
                    return RedirectToAction("Index");
                }
                catch
                {
                    return View();
                }
            }
     
        }
    }
    Bassel EL-BIZRI

  2. #2
    Membre habitué
    Homme Profil pro
    Inscrit en
    Avril 2013
    Messages
    76
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations forums :
    Inscription : Avril 2013
    Messages : 76
    Points : 143
    Points
    143
    Par défaut
    Pourquoi tu ne passes pas directement ta date en paramètre?
    D'ailleurs pourquoi tu récupère la ligne à chaque fois que tu définit la valeur d'une cellule?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    row++;
                                HSSFRow valueDateCell = sheet.GetRow(row);
                                valueDateCell.GetCell(0).SetCellValue(item.Date.ToString());
     
                                HSSFRow valuePrenomCell = sheet.GetRow(row);
                                valuePrenomCell.GetCell(1).SetCellValue(item.Nom +" "+ item.Prenom);
     
                                HSSFRow valueEquiCell = sheet.GetRow(row);
                                valueEquiCell.GetCell(2).SetCellValue(item.NomEquipement);
    Les GetRow, ne te renvoie pas la même ligne à chaque fois?

    Sinon, c'est bien NPOI que tu utilises ?

    Car, je n'ai pas vu de CreateCell ou CreateRow, alors qu'il sont présent dans les exemples que je trouve.

  3. #3
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Septembre 2010
    Messages
    67
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 33
    Localisation : Canada

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2010
    Messages : 67
    Points : 61
    Points
    61
    Par défaut
    Citation Envoyé par g.Arnaud Voir le message
    Pourquoi tu ne passes pas directement ta date en paramètre?




    Les GetRow, ne te renvoie pas la même ligne à chaque fois?

    Sinon, c'est bien NPOI que tu utilises ?
    .
    Bonjour Monsieur Arnaud ,

    Les dates sont bien inserer dans la Base de donner , mais je ne sais pas comment les extraire a partir de la bas....comment passer directement en parametre?

    Les GetRow, me renvoie la même ligne à chaque fois! C'est exactement ca le problem , je recois des date un peu bizarre ou sinon je recois rien dans la colonne

    C'est bien le NPOI que j'utilise

    Avez vous des suggestions que je peux faire pour afficher les date correctement?

    Merci
    Bassel EL-BIZRI

  4. #4
    Membre habitué
    Homme Profil pro
    Inscrit en
    Avril 2013
    Messages
    76
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations forums :
    Inscription : Avril 2013
    Messages : 76
    Points : 143
    Points
    143
    Par défaut
    Les dates un peu bizarre, c'est pas des dates sous forme d'entier?

    Sinon, ta requête Linq devrait les récupérer sans soucis.
    Sinon, question con, tu n'as pas de propriété de navigation?
    (tu utilise Linq to SQL ou Entity Framework?)


    De ce que j'ai compris de ton code, tu met la date, le nom prénom, les nom d'équipement, etc... sur la même ligne côte à côte.

    Si tu as un doute sur la date que tu récupère, met un point d'arrêt et regarde le contenu de item.Date.

    Sinon, je te propose un code comme ceci.

    Création d'un style de cellules pour les dates

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    HSSFCellStyle dateStyle = templateWorkbook.CreateCellStyle();
    dateStyle.SetDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy h:mm"));
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    row++;
    HSSFRow xRow = sheet.CreateRow(row);  //On crée une ligne excel à laquel on ajoutera des cellules avec leur valeurs
     
    HSSFCell dateCell = xRow.CreateCell(0);
    dateCell.SetCellStyle(dateStyle);                 //On définit le style pour l'affichage de la date
    dateCell.SetCellValue(item.Date);                 //On met directement la date en paramètre
     
    xRow.CreateCell(1).SetCellValue(item.Nom +" "+ item.Prenom); // Champs nom prénom
    Je pense que ça devrait aller comme ça si je me fie à la doc.
    N'ayant jamais utiliser NPOI, je ne garantit pas le résultat.

  5. #5
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Septembre 2010
    Messages
    67
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 33
    Localisation : Canada

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2010
    Messages : 67
    Points : 61
    Points
    61
    Par défaut
    Bonjour et encore Merci ,

    Les dates bizarre ressemble fortement a une forme entier....les dates s'affichent comme sa :" 1/1/3000" ce qui ressemble a un format des entiers

    Et j'utilise Entity framework sans avoir le droit de modifier

    je remercie votre suggestion mais VS m'indique que NPOI.HSSF.UserModel ne contient aucune definition pour les fonctions SetDataFormat et SetCellStyle

    J'ai essayer de faire un
    using NPOI.HSSF.Model;
    using NPOI.HSSF.Record;
    using NPOI.HSSF.Util;
    using NPOI.HSSF.UserModel;
    Sans succes , faut il que je fais une reference a une autre entiter?

    Merci encore


    Citation Envoyé par g.Arnaud Voir le message
    Les dates un peu bizarre, c'est pas des dates sous forme d'entier?

    Sinon, ta requête Linq devrait les récupérer sans soucis.
    Sinon, question con, tu n'as pas de propriété de navigation?
    (tu utilise Linq to SQL ou Entity Framework?)



    Sinon, je te propose un code comme ceci.

    Création d'un style de cellules pour les dates

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    HSSFCellStyle dateStyle = templateWorkbook.CreateCellStyle();
    dateStyle.SetDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy h:mm"));
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    row++;
    HSSFRow xRow = sheet.CreateRow(row);  //On crée une ligne excel à laquel on ajoutera des cellules avec leur valeurs
     
    HSSFCell dateCell = xRow.CreateCell(0);
    dateCell.SetCellStyle(dateStyle);                 //On définit le style pour l'affichage de la date
    dateCell.SetCellValue(item.Date);                 //On met directement la date en paramètre
     
    xRow.CreateCell(1).SetCellValue(item.Nom +" "+ item.Prenom); // Champs nom prénom
    Je pense que ça devrait aller comme ça si je me fie à la doc.
    N'ayant jamais utiliser NPOI, je ne garantit pas le résultat.
    Bassel EL-BIZRI

  6. #6
    Membre habitué
    Homme Profil pro
    Inscrit en
    Avril 2013
    Messages
    76
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations forums :
    Inscription : Avril 2013
    Messages : 76
    Points : 143
    Points
    143
    Par défaut
    Il y a eu une certaines confusion sur la doc que j'ai lu, c'était pas la dernière version. (NPOI est sur google code, codeplex et github avec la dernière version sur github apparemment).

    Dans la version que j'avais vu, l'utilisation était plus proche de POI (sans les propriété).

    La création du style deviendrait :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    HSSFDataFormat format;
                        format = templateWorkbook.CreateDataFormat();
                        HSSFCellStyle dateStyle;
                        dateStyle = templateWorkbook.CreateCellStyle();
                        dateStyle.DataFormat = format.GetFormat(System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern + " HH:mm:ss"); //Pour avoir l'heure avec et au format de date localiser.
    Et pour l'utiliser :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    row++;
    HSSFRow xRow = sheet.CreateRow(row);  //On crée une ligne excel à laquel on ajoutera des cellules avec leur valeurs
     
    HSSFCell dateCell = xRow.CreateCell(0);
    dateCell.CellStyle = dateStyle;                 //On définit le style pour l'affichage de la date
    dateCell.SetCellValue(item.Date);                 //On met directement la date en paramètre
     
    xRow.CreateCell(1).SetCellValue(item.Nom +" "+ item.Prenom); // Champs nom prénom
    Ceci dit, ce que tu obtient pour tes dates est un peu bizarre.
    Tu peux mettre un point d'arrêt sur la ligne :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    dateCell.SetCellValue(item.Date);
    Dans ta version originale, c'est

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    valueDateCell.GetCell(0).SetCellValue(item.Date.ToString());
    Ensuite, tu regarde la valeur et le type de "item.Date".

  7. #7
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Septembre 2010
    Messages
    67
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 33
    Localisation : Canada

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2010
    Messages : 67
    Points : 61
    Points
    61
    Par défaut
    Citation Envoyé par g.Arnaud Voir le message



    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    dateCell.SetCellValue(item.Date);


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    valueDateCell.GetCell(0).SetCellValue(item.Date.ToString());
    .

    Bonjour, et encore une fois mille merci pour vos reponse et suggestion

    Donc, apres plusieurs analyse je me persuade que le problem surgit avec le "item.Date". Et non pas Le POI ou le fichier xls


    En effet, lorsque j'ecris
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    dateCell.SetCellValue(item.Date);
    Je recois une erreur de VS qui me dit que le parametre est invalide

    Alors que , lorsque j'ecris
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    dateCell.SetCellValue(item.Date.ToString());
    VS prend le parametre comme argument valide

    Donc, d'apres vous , es ce que je dois modifier l'entiter ? ou pensez vous que le problem est dans la selection de la liste ici ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
     public ActionResult GenererRapport(int? cmbClient, int? cmbProjet, int? cmbProbill)
            {
                string fichier;
                //les clients concernes
                var cl = (from a in db.Clients where a.ID_Client == cmbClient select new { Nom = a.Nom, Prenom = a.Prenom }).ToArray();
     
                //les projets concernes
                var pr = (from a in db.Projects where a.ID_Projet == cmbProjet select new { Nom = a.NomProjet, Adresa = a.Ville + "," + a.NoCivique + " " + a.NomRue }).ToArray();
                //les factures idprobill >=0
          var list1 = (from a in db.DetailFDTs
                             where a.Facture == cmbProbill && a.ID_Projet == cmbProjet
                                orderby a.Facture,a.ID_Statut ascending
                                join b in db.VracFournisseurs on a.IdVrac equals b.ID
                                join c in db.Vracs on b.IdVrac equals c.IdVrac
                                join d in db.Fournisseurs on a.ID_Fournisseur equals d.ID_Fournisseur
                                join e in db.Equipements on a.ID_Equipement equals e.ID_Equipement
                                join f in db.FDTs on a.IDFDT  equals f.IDFDT
                                join em in db.Employees on f.ID_Employee  equals em.ID_Employee
                                select new { a.Facture, a.IDFDT, a.Description, a.Duree, c.Materiau, d.NomLegal, e.NomEquipement, a.No_Voyage, a.No_Tonnes,a.ID_Projet_out, a.Doc_in,a.Date,a.Prix_UM,em.Nom,em.Prenom }).ToArray();
     
                    //les factures idprobill <0
                var list2 = (from a in db.DetailFDTs
                                where a.ID_Projet==cmbProjet
                                orderby a.Facture,a.ID_Statut ascending
                                join b in db.VracFournisseurs on a.IdVrac equals b.ID
                                join c in db.Vracs on b.IdVrac equals c.IdVrac
                                join d in db.Fournisseurs on a.ID_Fournisseur equals d.ID_Fournisseur
                                join e in db.Equipements on a.ID_Equipement equals e.ID_Equipement
                                join f in db.FDTs on a.IDFDT  equals f.IDFDT
                                join em in db.Employees on f.ID_Employee  equals em.ID_Employee
                                select new { a.Facture, a.IDFDT, a.Description, a.Duree, c.Materiau, d.NomLegal, e.NomEquipement, a.No_Voyage, a.No_Tonnes, a.ID_Projet_out, a.Doc_in, a.Date,a.Prix_UM, em.Nom, em.Prenom }).ToArray();

    Merci encore
    Bassel EL-BIZRI

  8. #8
    Membre habitué
    Homme Profil pro
    Inscrit en
    Avril 2013
    Messages
    76
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations forums :
    Inscription : Avril 2013
    Messages : 76
    Points : 143
    Points
    143
    Par défaut
    Bon, il y a une surcharge SetCellValue qui prends un DateTime en paramètre.
    Donc la propriété Date de ton item n'est pas un DateTime.

    De quel type est la propriété "Date"?

  9. #9
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Septembre 2010
    Messages
    67
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 33
    Localisation : Canada

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2010
    Messages : 67
    Points : 61
    Points
    61
    Par défaut
    Citation Envoyé par g.Arnaud Voir le message
    Bon, il y a une surcharge SetCellValue qui prends un DateTime en paramètre.
    Donc la propriété Date de ton item n'est pas un DateTime.

    De quel type est la propriété "Date"?

    Date est declarer de cette maniere

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
     [DataType(DataType.Date)]
       [Display(Name = "Date")]
      public DateTime? Date { get; set; }

    Dans mon model de "DetaillsFDT" qui est le suivant

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.ComponentModel.DataAnnotations;
     
    namespace ESA.Models
    {
        public class DetailFDT
        {
            [Display(Name = "IdFDTD"),Key]
            public int IdFDTD { get; set; }
     
            [Display(Name = "IDFDT")]
            public int IDFDT { get; set; }
     
            [Display(Name = "ID_Projet")]
            public int ID_Projet { get; set; }
     
            [Display(Name = "Projet sortant")]
            public int ID_Projet_out { get; set; }
     
            [Display(Name = "Vrac")]
            public int IdVrac { get; set; }
     
            [Display(Name = "Equipement")]
            public int ID_Equipement { get; set; }
     
            [Display(Name = "Fournisseur")]
            public int ID_Fournisseur { get; set; }
     
            [Display(Name = "Statut")]
            public float ID_Statut { get; set; }
     
            [DataType(DataType.Date)]
            [Display(Name = "Date")]
            public DateTime? Date { get; set; }
     
            [Display(Name = "Description")]
            public string Description { get; set; }
     
            [Display(Name = "Document")]
            public string Doc_in { get; set; } //Doc de intrare in gestiune
     
            [Display(Name = "Voyages")]
            public float No_Voyage { get; set; }
     
            [Display(Name = "Tonnes")]
            public float No_Tonnes { get; set; }
     
            [Display(Name = "Duree")]
            public float Duree { get; set; }
     
            [Display(Name = "UM")]
            public string UM { get; set; }
     
            [Display(Name = "Prix/UM")]
            public float Prix_UM { get; set; }
     
            [Display(Name = "Prix Total")]
            public float Prix_Total { get; set; }
     
            [Display(Name = "Facture")]
            public int Facture { get; set; }
     
        }
    }
    Es ce que je dois faire un convert ?

    Encore Merci de votre assistance
    Bassel EL-BIZRI

  10. #10
    Membre habitué
    Homme Profil pro
    Inscrit en
    Avril 2013
    Messages
    76
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations forums :
    Inscription : Avril 2013
    Messages : 76
    Points : 143
    Points
    143
    Par défaut
    Pour la sortie dans ton excel, essaie ça:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    if(item.Date.HasValue)
    {
       dateCell.SetCellValue(item.Date.Value);
    }

  11. #11
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Septembre 2010
    Messages
    67
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 33
    Localisation : Canada

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2010
    Messages : 67
    Points : 61
    Points
    61
    Par défaut
    Re-Bonjour ,

    J'ai essayer de faire
    Citation Envoyé par g.Arnaud Voir le message

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    if(item.Date.HasValue)
    {
       dateCell.SetCellValue(item.Date.Value);
    }
    Et ca affiche des valeurs comme : #####

    Alors , lorsque j'essayer d'ecrire de cette maniere
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
                                    valueDateCell.GetCell(0).SetCellValue(item.Date.Value.ToShortTimeString());
    Ou

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
                                      dateCell.SetCellValue(item.Date.Value.ToShortTimeString());
    Ca affiche des valeurs sous Format date : 12:00 AM , Cette valeur s'affiche dans toutes les colonnes date ( ce qui est pas les valeurs de la base de donner )

    Faut-t'il que je change quelque chose?

    Merci encore et encore
    Bassel EL-BIZRI

  12. #12
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Septembre 2010
    Messages
    67
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 33
    Localisation : Canada

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2010
    Messages : 67
    Points : 61
    Points
    61
    Par défaut
    Bonjour,

    J'ai reussis a trouver le problem par moi memme

    Le problem etait dans ma selection de liste

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
                                             select new { a.Facture, a.IDFDT, a.Description, a.Duree, c.Materiau, d.NomLegal, e.NomEquipement, a.No_Voyage, a.No_Tonnes, a.ID_Projet_out, a.Doc_in, a.Date, a.Prix_UM, em.Nom, em.Prenom }).ToArray();
    La bonne selection est de :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
                                             select new { a.Facture, a.IDFDT, a.Description, a.Duree, c.Materiau, d.NomLegal, e.NomEquipement, a.No_Voyage, a.No_Tonnes, a.ID_Projet_out, a.Doc_in, at.Date, a.Prix_UM, em.Nom, em.Prenom }).ToArray();
    Bassel EL-BIZRI

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Problème JSF concernant la saisie des valeurs
    Par soffru dans le forum JSF
    Réponses: 4
    Dernier message: 27/03/2014, 15h43
  2. problème saisie des Dates à partir d'un calendrier
    Par girlworld86 dans le forum IHM
    Réponses: 4
    Dernier message: 23/06/2007, 17h53
  3. [MySQL] Problème de requête sur des dates
    Par dahu29 dans le forum Langage SQL
    Réponses: 3
    Dernier message: 14/03/2006, 13h08
  4. Saisie des dates
    Par J-P-B dans le forum XMLRAD
    Réponses: 5
    Dernier message: 04/07/2003, 11h08
  5. Réponses: 3
    Dernier message: 19/03/2003, 15h19

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo