Esempio n. 1
0
        public MainWindow()
        {
            InitializeComponent();
            ViewMainModel model = new ViewMainModel();

            this.DataContext = model;
            thisModel        = model;
        }
Esempio n. 2
0
        public static async Task <List <DownloadedItem> > ReadAndWrite(ViewMainModel model, IProgress <int> progress)
        {
            string tempDir = Path.GetDirectoryName(model.OpenedFile);

            tempDir = Path.Combine(tempDir, "TEMP");
            if (!Directory.Exists(tempDir))
            {
                Directory.CreateDirectory(tempDir);
            }

            int rowsCount = model.RowFinish - model.RowStart + 1;
            List <DownloadedItem> items = new List <DownloadedItem>(rowsCount);

            using (FileStream stream = File.Open(model.OpenedFile, FileMode.Open, FileAccess.Read))
                using (ExcelPackage excelPackage = new ExcelPackage(stream))
                    using (PowerPoint.Application powerApplication = new PowerPoint.Application())
                    {
                        ExcelWorksheet          worksheet    = excelPackage.Workbook.Worksheets.FirstOrDefault();
                        PowerPoint.Presentation presentation = powerApplication.Presentations.Add(MsoTriState.msoTrue);
                        presentation.PageSetup.SlideSize = PpSlideSizeType.ppSlideSizeA4Paper;

                        int pagesCreated = 0;


                        for (int row = model.RowStart; row <= model.RowFinish; row++)
                        {
                            DownloadedItem item = new DownloadedItem();
                            if (!string.IsNullOrEmpty(model.ColumnText))
                            {
                                var cell = worksheet.Cells[row, ExcelColumnNameToNumber(model.ColumnText)];
                                item.Text = GetCellValue(cell);
                            }
                            if (!string.IsNullOrEmpty(model.ColumnHyperlink))
                            {
                                var cell = worksheet.Cells[row, ExcelColumnNameToNumber(model.ColumnHyperlink)];
                                item.Hyperlink = GetUrlFromCell(cell);
                            }
                            if (!string.IsNullOrEmpty(model.ColumnURI1))
                            {
                                string bitmap = await DownloadBitmap(worksheet.Cells[row, ExcelColumnNameToNumber(model.ColumnURI1)], tempDir);

                                if (bitmap != null)
                                {
                                    item.Bitmaps.Add(bitmap);
                                }
                            }
                            if (!string.IsNullOrEmpty(model.ColumnURI2))
                            {
                                string bitmap = await DownloadBitmap(worksheet.Cells[row, ExcelColumnNameToNumber(model.ColumnURI2)], tempDir);

                                if (bitmap != null)
                                {
                                    item.Bitmaps.Add(bitmap);
                                }
                            }
                            if (!string.IsNullOrEmpty(model.ColumnURI3))
                            {
                                string bitmap = await DownloadBitmap(worksheet.Cells[row, ExcelColumnNameToNumber(model.ColumnURI3)], tempDir);

                                if (bitmap != null)
                                {
                                    item.Bitmaps.Add(bitmap);
                                }
                            }
                            if (!string.IsNullOrEmpty(model.ColumnURI4))
                            {
                                string bitmap = await DownloadBitmap(worksheet.Cells[row, ExcelColumnNameToNumber(model.ColumnURI4)], tempDir);

                                if (bitmap != null)
                                {
                                    item.Bitmaps.Add(bitmap);
                                }
                            }

                            var newSlide = presentation.Slides.Add(pagesCreated + 1, PpSlideLayout.ppLayoutTitleOnly);

                            if (!string.IsNullOrEmpty(item.Text))
                            {
                                DrowItemText(newSlide, item.Text);
                            }

                            newSlide.FollowMasterBackground = MsoTriState.msoFalse;
                            SetPhotosOnPage(newSlide, item);

                            if (item.Hyperlink != null)
                            {
                                DrowHyperlinkText(newSlide, item.Hyperlink);
                            }

                            progress.Report(++pagesCreated * 100 / rowsCount);
                        }
                    }
            if (Directory.Exists(tempDir))
            {
                try
                {
                    Directory.Delete(tempDir, true);
                }
                catch  {}
            }
            return(items);
        }