Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected List<string> ExportRecoltesXLSX(string nomfic, List<Recolte> recoltes)
- {
- nomfic += ".xlsx";
- Workbook wb = new Workbook();
- wb.Worksheets[0].Name = "Recolte";
- wb.Worksheets.Add("Recolte_Raisins");
- wb.Worksheets.Add("Recolte_Mouts");
- wb.Worksheets.Add("Recolte_Cave");
- var propR = typeof(Recolte).GetProperties(BindingFlags.Public | BindingFlags.Instance);
- var propDR = typeof(DetailRecolte).GetProperties(BindingFlags.Public | BindingFlags.Instance);
- int i = 0;
- /*sheet 1*/
- for (int rowP = 0; rowP < recoltes.Count; rowP++)
- {
- for (int col = 0; col < propR.Length; col++)
- {
- if (propR[col].PropertyType.Equals(typeof(List<DetailRecolte>)))
- {
- var value = propR[col].GetValue(recoltes[rowP], null);
- var list = value as List<DetailRecolte>;
- wb.Worksheets[0].Cells[0, i].Value = propR[col].Name + "(Bailleur)";
- wb.Worksheets[0].Cells[rowP + 1, i].Value = list.Sum(dr => dr.QteBai);
- i++;
- wb.Worksheets[0].Cells[0, i].Value = propR[col].Name + "(Exploitant)";
- wb.Worksheets[0].Cells[rowP + 1, i].Value = list.Sum(dr => dr.QteExp);
- i++;
- }
- else
- {
- wb.Worksheets[0].Cells[0, i].Value = propR[col].Name;
- wb.Worksheets[0].Cells[rowP + 1, i].Value = propR[col].GetValue(recoltes[rowP], null);
- i++;
- }
- }
- i = 0;
- }
- /*sheet2,3,4*/
- for (int rowP = 0; rowP < recoltes.Count; rowP++)
- {
- var r = recoltes[rowP];
- var dets = new List<List<DetailRecolte>>() { r.QteVenduesRaisins, r.QteVenduesMouts, r.QteApporteesCave };
- var lineIndex = new List<int>() { 1, 1, 1 };
- int j = 1;
- do
- {
- int cCount = 0;
- wb.Worksheets[j].Cells[0, cCount++].Value = "IdRecolte";
- wb.Worksheets[j].Cells[0, cCount++].Value = "CodeEVV";
- wb.Worksheets[j].Cells[0, cCount++].Value = "CodePPMBailleur";
- wb.Worksheets[j].Cells[0, cCount++].Value = "CodeProduit";
- wb.Worksheets[j].Cells[0, cCount++].Value = "Campagne";
- foreach (var det in dets[j - 1])
- {
- for (int propIndex = 0; propIndex < propDR.Length; propIndex++)
- {
- wb.Worksheets[j].Cells[0, cCount + propIndex].Value = propDR[propIndex].Name;
- wb.Worksheets[j].Cells[lineIndex[j-1] + 1, 0].Value = r.Id;
- wb.Worksheets[j].Cells[lineIndex[j-1] + 1, 1].Value = r.CodeEVV;
- wb.Worksheets[j].Cells[lineIndex[j-1] + 1, 2].Value = r.CodePPMBailleur;
- wb.Worksheets[j].Cells[lineIndex[j-1] + 1, 3].Value = r.CodeProduit;
- wb.Worksheets[j].Cells[lineIndex[j-1] + 1, 4].Value = r.Campagne;
- wb.Worksheets[j].Cells[lineIndex[j-1] + 1, cCount + propIndex].Value = propDR[propIndex].GetValue(det, null);
- }
- }
- lineIndex[j - 1]++;
- j++;
- }
- while (j <= dets.Count);
- }
- wb.Save(nomfic);
- return new List<string> { nomfic};
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement