Example #1
0
        private static List <string> ReadPostIts(SharpCloudApi sc, string filename, ViewModels.MainViewModel vm)
        {
            var list = new List <string>();

            var XL = new Microsoft.Office.Interop.Excel.Application();

            var wb = XL.Workbooks.Open(filename);

            var directoryName = System.IO.Path.GetDirectoryName(filename);

            int counter = 1;

            foreach (Microsoft.Office.Interop.Excel.Chart chart in wb.Charts)
            {
                string file = string.Format("{0}\\chart{1}.jpg", directoryName, counter++);

                vm.Status = "uploading images " + file;

                chart.Export(file, "JPEG", false);

                list.Add(sc.UploadImageFile(file, false));
            }

            wb.Close();
            XL = null;

            return(list);
        }
Example #2
0
        private async void  ReadPostItsFromExcel(SharpCloudApi sc, string filename, ViewModels.MainViewModel vm)
        {
            try
            {
                _bCancel = false;
                _wait    = true;
                _list    = new List <imageProperties>();

                var XL = new Microsoft.Office.Interop.Excel.Application();

                Workbook wb = XL.Workbooks.Open(filename);

                var directoryName = System.IO.Path.GetDirectoryName(filename);

                int counter = 1;

                foreach (Worksheet worksheet in wb.Worksheets)
                {
                    foreach (Microsoft.Office.Interop.Excel.Shape shape in worksheet.Shapes)
                    {
                        if (!_bCancel)
                        {
                            string file = string.Format("{0}\\chart{1}.jpg", directoryName, counter++);
                            vm.Status = "uploading images " + file;

                            int col = shape.TopLeftCell.Column;
                            int row = shape.TopLeftCell.Row;

                            string text      = ((Range)worksheet.Cells[row, col + 1]).Text;
                            string textTitle = ((Range)worksheet.Cells[3, col]).Text;
                            string Id        = $"R[{row}] : C[{col}]";

                            if (row > 3)
                            {
                                shape.CopyPicture(XlPictureAppearance.xlScreen, XlCopyPictureFormat.xlBitmap);

                                if (Clipboard.ContainsImage())
                                {
                                    try
                                    {
                                        var img = Clipboard.GetImage();
                                        vm.Image  = img;
                                        vm.Status = $"{Id}\n{textTitle}\n{text}";
                                        await Task.Delay(100);

                                        WriteJpeg(file, 100, img);
                                    }
                                    catch (Exception exception)
                                    {
                                        MessageBox.Show(exception.Message);
                                    }
                                }
                                var imageName = new imageProperties();
                                imageName.imageId      = sc.UploadImageFile(file, false);
                                imageName.itemName     = text;
                                imageName.categoryName = textTitle;
                                imageName.Id           = Id;
                                imageName.row          = row;
                                imageName.col          = col;
                                _list.Add(imageName);
                            }
                        }
                    }
                }
                vm.Image = null;
                wb.Close();
                XL    = null;
                _wait = false;
            }
            catch (Exception e)
            {
                vm.Status = e.Message;
                await Task.Delay(1000);
            }
        }