Beispiel #1
0
        public string GetExcel(SiteBase s, Dictionary <string, Dictionary <string, JOffer> > offerMap)
        {
            FileInfo template = new FileInfo(HttpContext.Current.Server.MapPath(@"\Content\ExcelPackageTemplate.xlsx"));
            string   filename = @"\output\" + s.GetTitle() + s.GetPuMonth() + "-" + s.GetPuDay() + s.GetCity() + ".xlsx";
            FileInfo newFile  = new FileInfo(HttpContext.Current.Server.MapPath(filename));

            using (ExcelPackage excelPackage = new ExcelPackage(newFile, template))
            {
                ExcelWorkbook  myWorkbook  = excelPackage.Workbook;          // Getting the complete workbook...
                ExcelWorksheet myWorksheet = myWorkbook.Worksheets["Rates"]; // Getting the worksheet by its name...

                int      rowNum = 2;
                DateTime doDate = new DateTime(Convert.ToInt32(s.GetPuYear()), Convert.ToInt32(s.GetPuMonth()), Convert.ToInt32(s.GetPuDay()));
                foreach (string link in offerMap.Keys.ToList())
                {
                    Dictionary <string, JOffer> map = offerMap[link];
                    List <JOffer> offers            = OffersToArray(map, link);
                    int           colNum            = 2;
                    myWorksheet.Cells[rowNum, 1].Value = s.GetPuMonth() + "-" + s.GetPuDay() + "/" + doDate.AddDays(rowNum - 1).Day + "\n" + (rowNum - 1);
                    for (int i = 0; i < offers.Count; i++)
                    {
                        myWorksheet.Row(rowNum).Height = 50;
                        //myWorksheet.Row(rowNum + 1).Height = 50;
                        //myWorksheet.Row(rowNum + 2).Height = 50;

                        JOffer      o     = offers.ElementAt(i);
                        SupplierNew other = o.GetOtherSupplier();
                        SupplierNew gm    = o.GetGmSupplier();
                        SupplierNew cr    = o.GetCrSupplier();

                        myWorksheet.Cells[rowNum, colNum].Value     = (gm != null ? gm.ToString() : "");
                        myWorksheet.Cells[rowNum, colNum + 1].Value = (cr != null ? cr.ToString() : "");
                        myWorksheet.Cells[rowNum, colNum + 2].Value = (other != null ? other.ToString() : "");
                        colNum += 3;
                    }
                    rowNum++;
                }
                excelPackage.Save();// Saving the change...
                return(filename);
            }
        }
Beispiel #2
0
 public void SetDocumentDetails()
 {
     if (SiteName != null)
     {
         documentTitle = SiteName.GetTitle();
         city          = SiteName.GetCity();
         int.TryParse(SiteName.GetPuDay(), out puDay);
         int.TryParse(SiteName.GetPuMonth(), out puMonth);
         int.TryParse(SiteName.GetPuYear(), out puYear);
     }
     else
     {
         Debug.WriteLine("SITENAME IS EMPTY or INCORRECT");
     }
 }