Beispiel #1
0
 /// <summary>
 /// Emu to pixels
 /// </summary>
 /// <param name="emu"></param>
 /// <returns></returns>
 public static int EmuToPixels(DocumentFormat.OpenXml.Int64Value emu)
 {
     if (emu != 0)
     {
         return((int)Math.Round((decimal)emu / 9525));
     }
     else
     {
         return(0);
     }
 }
        public Int64 getCoordinateForDate(DateTime dateValue, DateTime pdtstartDate, DateTime pdtendDate, DocumentFormat.OpenXml.Int64Value pintcellWidth)
        {
            TimeSpan firstDiff  = dateValue - pdtstartDate;
            TimeSpan secondDiff = pdtendDate - pdtstartDate;

            return(firstDiff.Days * pintcellWidth / secondDiff.Days);
        }
        public string  BuildPresentation(string parameterList, string UserId)
        {
            GanttChartAutomation.GanttChartDataHelper gantt           = new GanttChartAutomation.GanttChartDataHelper();
            GanttChartAutomation.GanttReportObject    ganttReportData = gantt.GenerateGanttChartReport(parameterList, UserId);

            DateTime startDate, endDate;

            startDate = ganttReportData.StatusDate.AddMonths(-2);
            endDate   = ganttReportData.StatusDate.AddMonths(3);
            ganttReportData.SetExplicitStartEndDate(startDate, endDate);
            _dtStatsDate = ganttReportData.StatusDate;

            IList <GanttChartAutomation.GanttReportObject> ganttChartPages = ganttReportData.PaginateDataWithWeightage(15);

            GanttChartAutomation.GanttReportObject testObject = ganttChartPages[0];


            byte[] fileBytes = PPTTemplate;
            using (MemoryStream stream = new MemoryStream())
            {
                stream.Write(fileBytes, 0, fileBytes.Length);

                using (PresentationDocument presentationDocument = PresentationDocument.Open(stream, true))
                {
                    PresentationPart presentationPart  = presentationDocument.PresentationPart;
                    SlidePart        templateSlidePart = presentationPart.SlideParts.LastOrDefault();
                    SlidePart        slidePart         = presentationPart.SlideParts.FirstOrDefault();


                    SlidePart newSlide;
                    _dtstartDate = ganttChartPages[0].StartDate;
                    _dtendDate   = ganttChartPages[0].EndDate;

                    for (int _intPageCount = 0; _intPageCount < ganttChartPages.Count; _intPageCount++)
                    {
                        bool lblnSlide = false;

                        GanttChartAutomation.GanttReportObject objganttReport = ganttChartPages[_intPageCount];

                        temp = templateSlidePart.Slide.CommonSlideData.ShapeTree.ChildElements.OfType <Shape>().Where(item => (item.NonVisualShapeProperties.NonVisualDrawingProperties.Description != null) && (item.NonVisualShapeProperties.NonVisualDrawingProperties.Description.Value.Equals("PositionBox", StringComparison.OrdinalIgnoreCase))).FirstOrDefault();
                        _shpNofillDiamond = templateSlidePart.Slide.CommonSlideData.ShapeTree.ChildElements.OfType <Shape>().Where(item => (item.NonVisualShapeProperties.NonVisualDrawingProperties.Description != null) && (item.NonVisualShapeProperties.NonVisualDrawingProperties.Description.Value.Equals("NoFillDiamond", StringComparison.OrdinalIgnoreCase))).FirstOrDefault();
                        _intCellWidth     = temp.ShapeProperties.Transform2D.Extents.Cx;
                        getheight(temp.ShapeProperties.Transform2D.Extents.Cy, 15);
                        _intSymbolWidth = _shpNofillDiamond.ShapeProperties.Transform2D.Extents.Cx;
                        newSlide        = CloneSlidePart(presentationPart, templateSlidePart);
                        InitializePosition(newSlide);


                        for (int i = 1; i <= objganttReport.RowCollection.Count; i++)
                        {
                            IList <Xdr.TableCell> cells = rows[i].ChildElements.OfType <Xdr.TableCell>().ToList();
                            _intTaskhaving += objganttReport.RowCollection[i - 1].Weightage;
                            SetCellText(cells[2], objganttReport.RowCollection[i - 1].TaskName.ToString(), objganttReport.RowCollection[i - 1].Weightage, rows[i]);
                            InsertTrend(objganttReport.RowCollection[i - 1].Trend, newSlide, i - 1, objganttReport.RowCollection[i - 1].Weightage);
                            SetCellText(cells[1], objganttReport.RowCollection[i - 1].CpValue == null ? "" : objganttReport.RowCollection[i - 1].CpValue.ToString(), objganttReport.RowCollection[i - 1].Weightage, rows[i]);

                            SetCellText(cells[3], objganttReport.RowCollection[i - 1].RaaValue == null ? "" : objganttReport.RowCollection[i - 1].RaaValue.ToString(), objganttReport.RowCollection[i - 1].Weightage, rows[i]);
                            SetCellText(cells[4], objganttReport.RowCollection[i - 1].BacValue == null ? "" : objganttReport.RowCollection[i - 1].BacValue.ToString(), objganttReport.RowCollection[i - 1].Weightage, rows[i]);
                            SetCellText(cells[5], objganttReport.RowCollection[i - 1].SvValue == null ? "" : objganttReport.RowCollection[i - 1].SvValue.ToString(), objganttReport.RowCollection[i - 1].Weightage, rows[i]);
                            SetShapeCe(cells[6], "", newSlide, objganttReport.RowCollection[i - 1].rowImageDetails, i - 1, objganttReport.RowCollection[i - 1].Weightage);
                            InsertPageDetasils(newSlide, objganttReport);
                            //InsertstatusLine(newSlide);
                        }
                        if (objganttReport.RowCollection.Count < 15)
                        {
                            //_cshpStatsLine.ShapeProperties.Transform2D.Extents.Cx = (_intTaskhaving + 1) * _intcellHeight;
                            //_cshpStatsLine.ShapeProperties.Transform2D.Offset.Y = 3848497;

                            for (int i = objganttReport.RowCollection.Count + 1; i <= 15; i++)
                            {
                                rows[i].Remove();
                            }
                        }
                        _intTaskhaving = -1;

                        RemoveShapePosition(newSlide, presentationPart);
                    }

                    DeleteTemplateSlide(presentationPart, templateSlidePart);


                    xVal.OpenXmlValidator validator = new xVal.OpenXmlValidator();
                    var errors = validator.Validate(presentationDocument).ToList();



                    if (errors.Count == 0)
                    {
                        presentationPart.Presentation.Save();
                    }
                    else
                    {
                        throw new ApplicationException("Error in document.");
                    }
                }

                byte[] presentationFile = stream.ToArray();
                string outputFolder     = @"C:\\ReMICS\\OpenXMLPpt\\";
                if (!System.IO.Directory.Exists(outputFolder))
                {
                    System.IO.Directory.CreateDirectory(outputFolder);
                }

                string newPresentation = outputFolder + "OpenXML-PPT-" + Guid.NewGuid().ToString() + ".pptx";
                File.WriteAllBytes(newPresentation, presentationFile);

                return(newPresentation);
            }
        }
 /// <summary>
 /// Initializes a new instance of the Int64Value by deep copying the supplied Int64Value class.
 /// </summary>
 /// <param name="source">The source Int64Value class.</param>
 public Int64Value(Int64Value source)
     : base(source)
 {
 }