Exemple #1
0
        private void Extract()
        {
            Excel.Application application = new Excel.Application {
                Visible = false
            };
            Excel.Workbook  workbook  = application.Workbooks.Open(textBoxFilePath.Text);
            Excel.Worksheet worksheet = workbook.Sheets[1];

            Excel.Pictures pics = worksheet.Pictures(Missing.Value) as Excel.Pictures;
            if (pics != null)
            {
                progressBar.Maximum = pics.Count;
                for (var i = 1; i <= pics.Count; i++)
                {
                    progressBar.Value = i;

                    try
                    {
                        pics.Item(i).CopyPicture(Excel.XlPictureAppearance.xlScreen, Excel.XlCopyPictureFormat.xlBitmap);

                        var    image     = Clipboard.GetImage();
                        string imageName = worksheet.Cells[pics.Item(i).TopLeftCell.Row, 3].Formula;
                        image?.Save(Path.Combine(textBoxImagePath.Text, imageName + ".bmp"));
                    }
                    catch (Exception)
                    {
                        // ignored
                    }
                }
            }

            workbook.Close();
            application.Quit();
            MessageBox.Show(@"Image Extraction completed.", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);

            Process.Start(textBoxImagePath.Text);
        }
Exemple #2
0
        public static List <Product> writeProducts(List <Product> products)
        {
            List <Image> images = new List <Image>();

            Excel.Pictures pics = xlws.Pictures(Missing.Value) as Excel.Pictures;
            for (int x = 1; x <= pics.Count; x++)
            {
                pics.Item(x).CopyPicture(Excel.XlPictureAppearance.xlScreen, Excel.XlCopyPictureFormat.xlBitmap);
            }
            foreach (Excel.Range row in xlws.Rows)
            {
                if (row.Cells[1] != null)
                {
                    products.Add(new Product(
                                     row.Cells[1].ToString(),
                                     int.Parse(row.Cells[2].ToString()),
                                     int.Parse(row.Cells[3].ToString()),
                                     row.Cells[5].ToString(),
                                     null,
                                     row.Cells[7].ToString()
                                     ));
                }
            }
        }