示例#1
0
        public static bool ConvertExcelToImage(string ExcelFileName, string ExportFileName = null)
        {
            if (ExportFileName == null)
            {
                ExportFileName = ExcelFileName + ".png";
            }

            if (!System.IO.File.Exists(ExcelFileName))
            {
                return(false);
            }

            try
            {
                ExcelEngine ee = new ExcelEngine();

                IWorkbook book = ee.Excel.Workbooks.OpenReadOnly(ExcelFileName);

                IWorksheet sheet = book.ActiveSheet;
                sheet.UsedRangeIncludesFormatting = false;
                int lastRow              = sheet.UsedRange.LastRow + 1;
                int lastColumn           = sheet.UsedRange.LastColumn + 1;
                System.Drawing.Image img = sheet.ConvertToImage(1, 1, lastRow, lastColumn, ImageType.Bitmap, null);
                img.Save(ExportFileName, ImageFormat.Png);

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
示例#2
0
        private void OnConvertButtonClicked(object sender, EventArgs e)
        {
            //Instantiate excel engine
            ExcelEngine excelEngine = new ExcelEngine();
            //Excel application
            IApplication application = excelEngine.Excel;

            //Get assembly manifest resource
            Assembly assembly   = Assembly.GetExecutingAssembly();
            Stream   fileStream = assembly.GetManifestResourceStream("SampleBrowser.Samples.XlsIO.Template.ExpenseReport.xlsx");

            //Open Workbook
            IWorkbook workbook = application.Workbooks.Open(fileStream);

            //Get Worksheet
            IWorksheet worksheet = workbook.Worksheets[0];

            //Initialize XlsIORenderer
            application.XlsIORenderer = new XlsIORenderer();

            //Set file content type
            string             contentType  = "image/png";
            ExportImageOptions imageOptions = new ExportImageOptions();

            imageOptions.ImageFormat = ExportImageFormat.Png;

            //Create a new memory stream
            MemoryStream stream = new MemoryStream();

            if (pngButton.Checked)
            {
                worksheet.ConvertToImage(worksheet.UsedRange, imageOptions, stream);
            }
            else
            {
                imageOptions.ImageFormat = ExportImageFormat.Jpeg;
                worksheet.ConvertToImage(worksheet.UsedRange, imageOptions, stream);
                contentType = "image/jpeg";
            }

            workbook.Close();
            excelEngine.Dispose();

            //Save and view the generated file.
            SaveAndView(stream, contentType, true);
        }
示例#3
0
        private static void ExportWorksheetToBitmap(Spreadsheet spreadsheetControl)
        {
            IWorksheet sheet = spreadsheetControl.Workbook.ActiveSheet;

            sheet.UsedRangeIncludesFormatting = false;
            int lastRow    = sheet.UsedRange.LastRow + 1;
            int lastColumn = sheet.UsedRange.LastColumn + 1;

            System.Drawing.Image img = sheet.ConvertToImage(1, 1, lastRow, lastColumn, ImageType.Bitmap, null);
            img.Save("Sample.png", ImageFormat.Png);
            System.Diagnostics.Process.Start("Sample.png");
        }
        void OnConvertClicked(object sender, EventArgs e)
        {
            //Instantiate excel engine
            ExcelEngine excelEngine = new ExcelEngine();
            //Excel application
            IApplication application = excelEngine.Excel;

            #region Initializing Workbook
            //Load the input template from assembly.
            string   resourcePath = "SampleBrowser.Samples.XlsIO.Template.ExpenseReport.xlsx";
            Assembly assembly     = Assembly.GetExecutingAssembly();
            Stream   fileStream   = assembly.GetManifestResourceStream(resourcePath);

            //Open workbook
            IWorkbook workbook = application.Workbooks.Open(fileStream);

            //The first worksheet object in the worksheets collection is accessed.
            IWorksheet sheet = workbook.Worksheets[0];
            #endregion

            //Create a new memory stream to store the generated image.
            MemoryStream stream = new MemoryStream();

            //Initialize XlsIORenderer.
            application.XlsIORenderer = new XlsIORenderer();
            ExportImageOptions imageOptions = new ExportImageOptions();
            string             fileName     = null;
            string             ContentType  = null;
            if (jpegButton != null && (bool)jpegButton.IsChecked)
            {
                imageOptions.ImageFormat = ExportImageFormat.Jpeg;
                fileName    = "Image.jpeg";
                ContentType = "image/jpeg";
            }
            else
            {
                imageOptions.ImageFormat = ExportImageFormat.Png;
                fileName    = "Image.png";
                ContentType = "image/png";
            }

            //Convert to image
            sheet.ConvertToImage(sheet.UsedRange, imageOptions, stream);

            stream.Position = 0;

            if (stream != null)
            {
                SaveiOS iOSSave = new SaveiOS();
                iOSSave.Save(fileName, ContentType, stream);
            }
        }
示例#5
0
        private static void OnExecuteExportToMetafile(object sender, ExecutedRoutedEventArgs args)
        {
            SpreadsheetControl spreadsheetControl = args.Source as SpreadsheetControl;
            IWorksheet         sheet = spreadsheetControl.ExcelProperties.WorkBook.Worksheets[0];

            sheet.UsedRangeIncludesFormatting = false;
            int lastRow    = sheet.UsedRange.LastRow + 1;
            int lastColumn = sheet.UsedRange.LastColumn + 1;

            System.Drawing.Image img = sheet.ConvertToImage(1, 1, lastRow, lastColumn, ImageType.Metafile, null);
            img.Save("Sample1.emf", ImageFormat.Emf);
            System.Diagnostics.Process.Start("Sample1.emf");
        }
        internal void OnButtonClicked(object sender, EventArgs e)
        {
            //XlsIORenderer renderer = new XlsIORenderer();
            ExcelEngine  excelEngine = new ExcelEngine();
            IApplication application = excelEngine.Excel;

#if COMMONSB
            Stream stream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.Samples.XlsIO.Samples.Template.ExpenseReport.xlsx");
#else
            Stream stream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.XlsIO.Samples.Template.ExpenseReport.xlsx");
#endif
            IWorkbook  workbook  = application.Workbooks.Open(stream);
            IWorksheet worksheet = workbook.Worksheets[0];
            application.XlsIORenderer = new XlsIORenderer();
            MemoryStream       image        = new MemoryStream();
            ExportImageOptions imageOptions = new ExportImageOptions();
            string             fileName     = null;
            string             contentType  = null;

            if (this.jpegButton.IsChecked != null && (bool)this.jpegButton.IsChecked)
            {
                imageOptions.ImageFormat = ExportImageFormat.Jpeg;
                fileName    = "Image.jpeg";
                contentType = "image/jpeg";
            }
            else
            {
                imageOptions.ImageFormat = ExportImageFormat.Png;
                fileName    = "Image.png";
                contentType = "image/png";
            }

            //Convert to image
            worksheet.ConvertToImage(worksheet.UsedRange, imageOptions, image);

            image.Position = 0;

            if (Device.RuntimePlatform == Device.UWP)
            {
                Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save(fileName, contentType, image);
            }
            else
            {
                Xamarin.Forms.DependencyService.Get <ISave>().Save(fileName, contentType, image);
            }
        }
示例#7
0
        private void XLS()
        {
            ExcelEngine  excelEngine = new ExcelEngine();
            IApplication application = excelEngine.Excel;

            application.DefaultVersion = ExcelVersion.Excel2010;
            IWorkbook  workbook = application.Workbooks.Open(sciezkaDoPliku, ExcelOpenType.Automatic);
            IWorksheet sheet    = workbook.Worksheets[0];

            sheet.UsedRangeIncludesFormatting = false;
            int   lastRow    = sheet.UsedRange.LastRow + 1;
            int   lastColumn = sheet.UsedRange.LastColumn + 1;
            Image image      = sheet.ConvertToImage(1, 1, lastRow, lastColumn, Syncfusion.XlsIO.ImageType.Bitmap, null);

            image.Save(sciezgaDoZapisaniaPliku + ".jpg");
            image.Dispose();
            excelEngine.Dispose();
        }
示例#8
0
        //
        // GET: /WorksheetToImage/

        public ActionResult WorksheetToImage(string button, string saveOption)
        {
            string basePath = _hostingEnvironment.WebRootPath;

            if (button == null)
            {
                return(View());
            }
            else if (button == "Input Template")
            {
                Stream ms = new FileStream(basePath + @"/XlsIO/ExpenseReport.xlsx", FileMode.Open, FileAccess.Read);
                return(File(ms, "Application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "Template.xlsx"));
            }
            else
            {
                // The instantiation process consists of two steps.
                // Step 1 : Instantiate the spreadsheet creation engine.
                ExcelEngine excelEngine = new ExcelEngine();

                // Step 2 : Instantiate the excel application object.
                IApplication application = excelEngine.Excel;
                application.DefaultVersion = ExcelVersion.Excel2016;

                //Read file to memory stream
                Stream file = new FileStream(basePath + @"/XlsIO/ExpenseReport.xlsx", FileMode.Open, FileAccess.Read);

                // An existing workbook is opened.
                IWorkbook workbook = application.Workbooks.Open(file);

                // The first worksheet object in the worksheets collection is accessed.
                IWorksheet worksheet = workbook.Worksheets[0];

                try
                {
                    //Create a memory stream to store the generated image.
                    Stream image = new MemoryStream();
                    application.XlsIORenderer = new XlsIORenderer();

                    ExportImageOptions imageOptions = new ExportImageOptions()
                    {
                        ImageFormat = ExportImageFormat.Jpeg
                    };

                    //Save as JPEG image
                    if (saveOption == "jpeg")
                    {
                        worksheet.ConvertToImage(worksheet.UsedRange, imageOptions, image);
                        image.Position = 0;
                        return(File(image, "image/jpeg", "Image.jpeg"));
                    }
                    //Save as PNG image
                    else
                    {
                        imageOptions.ImageFormat = ExportImageFormat.Png;
                        worksheet.ConvertToImage(worksheet.UsedRange, imageOptions, image);
                        image.Position = 0;
                        return(File(image, "image/png", "Image.png"));
                    }
                }
                catch (Exception)
                { }
                finally
                {
                    workbook.Close();
                    excelEngine.Dispose();
                }
            }
            return(View());
        }
示例#9
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            // New instance of XlsIO is created.[Equivalent to launching MS Excel with no workbooks open].
            // The instantiation process consists of two steps.

            // Step 1 : Instantiate the spreadsheet creation engine.
            ExcelEngine excelEngine = new ExcelEngine();

            // Step 2 : Instantiate the excel application object.
            IApplication application = excelEngine.Excel;

            application.DefaultVersion = ExcelVersion.Excel2007;

            // An existing workbook is opened.
            IWorkbook workbook = application.Workbooks.Open(@"..\..\..\..\..\..\..\Common\Data\XlsIO\WorkSheetToImage.xlsx");

            // The first worksheet object in the worksheets collection is accessed.
            IWorksheet sheet = workbook.Worksheets["Pivot Table"];

            sheet.UsedRangeIncludesFormatting = false;
            int lastRow    = sheet.UsedRange.LastRow + 1;
            int lastColumn = sheet.UsedRange.LastColumn + 1;


            // Save the image.
            if (this.rBtnBitmap.IsChecked.Value)
            {
                // Convert the worksheet to image
                System.Drawing.Image img = sheet.ConvertToImage(1, 1, lastRow, lastColumn, ImageType.Bitmap, null);

                fileName = "Sample.png";
                img.Save(fileName, ImageFormat.Png);
            }
            else
            {
                // Convert the worksheet to image
                System.Drawing.Image img = sheet.ConvertToImage(1, 1, lastRow, lastColumn, ImageType.Metafile, null);

                fileName = "Sample.emf";
                img.Save(fileName, ImageFormat.Emf);
            }

            //Close the workbook.
            workbook.Close();
            excelEngine.Dispose();

            //Message box confirmation to view the created spreadsheet.
            if (MessageBox.Show("Do you want to view the image?", "Image has been created",
                                MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
            {
                try
                {
                    //Launching the Excel file using the default Application.[MS Excel Or Free ExcelViewer]
                    System.Diagnostics.Process.Start(fileName);

                    //Exit
                    this.Close();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }
            else
            {
                // Exit
                this.Close();
            }
        }
示例#10
0
        private void btnConvert_Click(object sender, EventArgs e)
        {
            string fileName;

            #region Initialize Workbook
            // New instance of XlsIO is created.[Equivalent to launching MS Excel with no workbooks open].
            // The instantiation process consists of two steps.

            // Step 1 : Instantiate the spreadsheet creation engine.
            ExcelEngine excelEngine = new ExcelEngine();

            // Step 2 : Instantiate the excel application object.
            IApplication application = excelEngine.Excel;
            application.DefaultVersion = ExcelVersion.Excel2007;

            string inputPath = GetFullTemplatePath("WorkSheetToImage.xlsx");
            // An existing workbook is opened.
            IWorkbook workbook = application.Workbooks.Open(inputPath);
            // The first worksheet object in the worksheets collection is accessed.
            IWorksheet worksheet = workbook.Worksheets["Pivot Table"];

            #endregion

            #region Convert Sheet and Save as Image
            worksheet.UsedRangeIncludesFormatting = false;
            int lastRow    = worksheet.UsedRange.LastRow + 1;
            int lastColumn = worksheet.UsedRange.LastColumn + 1;

            // Save the image.
            if (rdbBitmap.Checked)
            {
                // Convert the worksheet to image
                Image img = worksheet.ConvertToImage(1, 1, lastRow, lastColumn, ImageType.Bitmap, null);
                fileName = "BitmapImg.png";
                img.Save(fileName, ImageFormat.Png);
            }
            else
            {
                // Convert the worksheet to image
                Image img = worksheet.ConvertToImage(1, 1, lastRow, lastColumn, ImageType.Metafile, null);
                fileName = "Metafile.emf";
                img.Save(fileName, ImageFormat.Emf);
            }
            #endregion

            #region Workbook close and Dispose
            //Close the workbook.
            workbook.Close();
            excelEngine.Dispose();
            #endregion

            #region View the Workbook
            //Message box confirmation to view the created spreadsheet.
            if (MessageBox.Show("Do you want to view the image?", "Conversion Successful !!!",
                                MessageBoxButtons.YesNo, MessageBoxIcon.Information)
                == DialogResult.Yes)
            {
                // Launch the image
#if NETCORE
                System.Diagnostics.Process process = new System.Diagnostics.Process();
                process.StartInfo = new System.Diagnostics.ProcessStartInfo(fileName)
                {
                    UseShellExecute = true
                };
                process.Start();
#else
                Process.Start(fileName);
#endif
                this.Close();
            }
            else
            {
                this.Close();
            }
            #endregion
        }
        public int convertExceltoEMF(string path)
        {
            double sWidth = Command.thisCommand.getSheetWidth();

            setSheetParameters(sWidth);
            string sheetSize = Command.thisCommand.getSheetSize();

            if (sheetSize == "24 x 36")
            {
                formatHeight  = 22.25;
                centerLine    = 12.0;
                imagePerSheet = 4;
            }
            else if (sheetSize == "30 x 42")
            {
                formatHeight  = 28.25;
                centerLine    = 15.0;
                imagePerSheet = 5;
            }
            else if (sheetSize == "36 x 48")
            {
                formatHeight  = 34.25;
                centerLine    = 18.0;
                imagePerSheet = 6;
            }
            else
            {
            }

            double cellB;
            double cellC;
            double cellD;
            int    resolution = 150;
            int    pWidth;

            var savePath = Path.GetDirectoryName(path) + @"\Master Schedule (Images)\";

            if (Directory.Exists(savePath))
            {
                removeExistingImages(savePath);
            }
            else
            {
                Directory.CreateDirectory(savePath);
            }
            var saveName = "Master Schedule";

            Command.thisCommand.dialog.ConvertingWord();

            //Load the document.
            ExcelEngine  excelEngine = new ExcelEngine();
            IApplication application = excelEngine.Excel;

            application.DefaultVersion = ExcelVersion.Excel2013;

            IWorkbook  workbook = excelEngine.Excel.Workbooks.OpenReadOnly(path);
            IWorksheet sheet    = workbook.Worksheets[1];

            //read widths of the cells we care about, B, C, and D
            cellB = sheet.GetColumnWidthInPixels(2);
            cellC = sheet.GetColumnWidthInPixels(3);
            cellD = sheet.GetColumnWidthInPixels(4);
            double cellWidth = cellB + cellC + cellD;

            float cellInches = Convert.ToSingle(cellWidth) / 72.0f;

            //store document width in pixels @ 150 DPI
            pWidth = Convert.ToInt32((cellInches * (float)resolution));

            double multiplier = 994.0 / pWidth;

            sheet.SetColumnWidthInPixels(2, Convert.ToInt32(cellB * multiplier));
            sheet.SetColumnWidthInPixels(3, Convert.ToInt32(cellC * multiplier));
            sheet.SetColumnWidthInPixels(4, Convert.ToInt32(cellD * multiplier));

            cellB     = sheet.GetColumnWidthInPixels(2);
            cellC     = sheet.GetColumnWidthInPixels(3);
            cellD     = sheet.GetColumnWidthInPixels(4);
            cellWidth = cellB + cellC + cellD;

            cellInches = Convert.ToSingle(cellWidth) / 72.0f;

            //store document width in pixels @ 150 DPI
            pWidth = Convert.ToInt32((cellInches * (float)resolution));

            //Read the last used row in the doc
            int lastRow = sheet.UsedRange.LastRow;

            //Resize fonts in every cell
            for (int x = 1; x <= lastRow; x++)
            {
                string searchRow = "A" + x.ToString();
                double fntSize   = sheet.Range[searchRow].CellStyle.Font.Size;
                var    fgColor   = sheet.Range[searchRow].CellStyle.PatternColorIndex;
                var    bgColor   = sheet.Range[searchRow].CellStyle.ColorIndex;
                //ExcelKnownColors checkColor = (ExcelKnownColors)65;
                fixCellSize(sheet, x);

                /*if (fntSize != 18)
                 * {
                 *  if (bgColor == checkColor)
                 *  {
                 *      string searchRowB = "B" + x.ToString();
                 *      double fontSize = sheet.Range[searchRowB].CellStyle.Font.Size;
                 *      if (fontSize != 10)
                 *      {
                 *          fixCellSize(sheet, x);
                 *      }
                 *  }
                 * }*/
            }



            string fullRange = "B1:D" + lastRow.ToString();
            string lastRange = "D1:D" + lastRow.ToString();

            // do some setup on the sheet
            sheet.IsGridLinesVisible        = false;
            sheet.Range[lastRange].WrapText = true;
            //sheet.Range[lastRange].AutofitRows();
            //sheet.Range[fullRange].AutofitRows();
            //sheet.Range[lastRange].AutofitRows();

            //delete hidden cells
            for (int rows = 1; rows <= lastRow; rows++)
            {
                bool row = sheet.IsRowVisible(rows);
                if (row == false)
                {
                    sheet.DeleteRow(rows);
                    rows--;
                }
            }

            lastRow = sheet.UsedRange.LastRow;



            //setup to figure out pages to publish
            double runningHeight = 0.0;

            ArrayList page      = new ArrayList();
            ArrayList startCell = new ArrayList();
            ArrayList endCell   = new ArrayList();

            int sPage = 1;
            int sCell = 1;

            //seperate rows into pages
            for (int rows = 1; rows <= lastRow; rows++)
            {
                string content  = sheet.Range["B1"].Text;
                double tempRow1 = sheet.GetRowHeight(1);

                double tempRow = sheet.GetRowHeightInPixels(rows) / 72.0;
                runningHeight = runningHeight + tempRow;
                if (runningHeight > formatHeight)
                {
                    page.Add(sPage);
                    startCell.Add(sCell);
                    endCell.Add(rows - 1);
                    sPage++;
                    sCell         = rows;
                    runningHeight = tempRow;
                }
                if (rows == lastRow)
                {
                    page.Add(sPage);
                    startCell.Add(sCell);
                    endCell.Add(rows);
                }
            }


            Command.thisCommand.dialog.setPageCount(page.Count);
            Command.thisCommand.dialog.SetupProgress(page.Count, "Task: Converting Excel Document to Images");


            //save document by row ranges as images
            for (int i = 0; i <= page.Count - 1; i++)
            {
                int pageValue = i + 1;
                runningHeight = 0.0;
                int startingCell = int.Parse(startCell[i].ToString());
                int endingCell   = int.Parse(endCell[i].ToString());

                for (int x = startingCell; x < endingCell; x++)
                {
                    double tempRow = sheet.GetRowHeightInPixels(x) / 72.0;
                    runningHeight = runningHeight + tempRow;
                }
                float pageHeight = Convert.ToSingle(runningHeight);
                pageHeight = pageHeight * 150;


                Image  image  = sheet.ConvertToImage(startingCell, 2, endingCell, 4, ImageType.Metafile, null);
                Bitmap bitmap = null;

                bitmap = new Bitmap(pWidth, Convert.ToInt32(pageHeight));
                bitmap.SetResolution((float)resolution, (float)resolution);
                using (Graphics g = Graphics.FromImage(bitmap))
                {
                    g.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.High;
                    g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                    g.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                    g.TextRenderingHint  = System.Drawing.Text.TextRenderingHint.AntiAlias;
                    g.DrawImage(image, 0, 0, pWidth, Convert.ToInt32(pageHeight));
                    g.Dispose();
                }
                bitmap.Save(savePath + saveName + pageValue.ToString("D2") + ".png", ImageFormat.Png);
                bitmap.Dispose();

                //setup progress for export
                //int percentage = (int)Math.Round(((double)i / (double)page.Count) * 100.0);
                //if (OnProgressUpdate != null)
                //{
                //    OnProgressUpdate(Convert.ToInt32(percentage));
                //}
                //i++;
                Command.thisCommand.dialog.IncrementProgress();
                bitmap = null;
            }
            //close document without saving
            workbook.Close();
            excelEngine.ThrowNotSavedOnDestroy = false;
            excelEngine.Dispose();

            return(page.Count);
        }
        //
        // GET: /WorksheetToImage/

        public ActionResult WorksheetToImage(string Group1, string OpenType, string button)
        {
            if (Group1 == null)
            {
                return(View());
            }
            else if (button == "Input Template")
            {
                //Step 1 : Instantiate the spreadsheet creation engine.
                ExcelEngine excelEngine = new ExcelEngine();
                //Step 2 : Instantiate the excel application object.
                IApplication application = excelEngine.Excel;
                IWorkbook    workbook    = application.Workbooks.Open(ResolveApplicationDataPath(@"WorkSheetToImage.xlsx"));
                return(excelEngine.SaveAsActionResult(workbook, "Template.xlsx", HttpContext.ApplicationInstance.Response, ExcelDownloadType.PromptDialog, ExcelHttpContentType.Excel2016));
            }
            else
            {
                // The instantiation process consists of two steps.
                // Step 1 : Instantiate the spreadsheet creation engine.
                ExcelEngine excelEngine = new ExcelEngine();

                // Step 2 : Instantiate the excel application object.
                IApplication application = excelEngine.Excel;
                application.DefaultVersion = ExcelVersion.Excel2016;

                // An existing workbook is opened.
                IWorkbook workbook = application.Workbooks.Open(ResolveApplicationDataPath("WorkSheetToImage.xlsx"));

                // The first worksheet object in the worksheets collection is accessed.
                IWorksheet sheet = workbook.Worksheets["Pivot Table"];

                sheet.UsedRangeIncludesFormatting = false;
                int lastRow    = sheet.UsedRange.LastRow + 1;
                int lastColumn = sheet.UsedRange.LastColumn + 1;


                try
                {
                    // Convert Word Document into image
                    Image image = sheet.ConvertToImage(1, 1, lastRow, lastColumn, ImageType.Bitmap, null);

                    //Save as Bitmap image
                    if (Group1 == "BMP")
                    {
                        ExportAsImage(image, "WordToImage_1.bmp", ImageFormat.Bmp, HttpContext.ApplicationInstance.Response);
                    }
                    //Save as PNG image
                    else if (Group1 == "PNG")
                    {
                        ExportAsImage(image, "WordToImage_1.png", ImageFormat.Png, HttpContext.ApplicationInstance.Response);
                    }
                    //Save as JPEG image
                    else if (Group1 == "JPEG")
                    {
                        ExportAsImage(image, "WordToImage_1.jpeg", ImageFormat.Jpeg, HttpContext.ApplicationInstance.Response);
                    }
                    //Save as EMF image
                    else if (Group1 == "EMF")
                    {
                        MemoryStream stream = new MemoryStream();// (MemoryStream)document.RenderAsImages(0, ImageFormat.Emf);
                        sheet.ConvertToImage(1, 1, lastRow, lastColumn, EmfType.EmfOnly, stream);
                        stream.Position = 0;
                        stream.WriteTo(Response.OutputStream);
                        ExportAsImage(image, "WordToImage_1.emf", ImageFormat.Emf, HttpContext.ApplicationInstance.Response);
                    }

                    workbook.Close();
                    excelEngine.Dispose();
                }
                catch (Exception)
                { }
                finally
                {
                }
            }
            return(View());
        }
        /// <summary>
        /// Convert the Excel document to image
        /// </summary>
        /// <returns>Return the created excel document as stream</returns>
        public MemoryStream WorksheetToImageXlsIO(string button, string imageFormat)
        {
            if (button == "Input Document")
            {
                //New instance of XlsIO is created.[Equivalent to launching MS Excel with no workbooks open].
                //The instantiation process consists of two steps.

                //Step 1 : Instantiate the spreadsheet creation engine
                using (ExcelEngine excelEngine = new ExcelEngine())
                {
                    //Step 2 : Instantiate the excel application object
                    IApplication application = excelEngine.Excel;
                    application.DefaultVersion = ExcelVersion.Excel2016;

                    //An existing workbook is opened
                    FileStream inputStream = new FileStream(ResolveApplicationPath("ExpenseReport.xlsx"), FileMode.Open, FileAccess.Read);
                    IWorkbook  workbook    = application.Workbooks.Open(inputStream);

                    //Save the document as a stream and retrun the stream
                    using (MemoryStream stream = new MemoryStream())
                    {
                        //Save the created Excel document to MemoryStream
                        workbook.SaveAs(stream);
                        return(stream);
                    }
                }
            }
            else
            {
                //New instance of XlsIO is created.[Equivalent to launching MS Excel with no workbooks open].
                //The instantiation process consists of two steps.

                //Step 1 : Instantiate the spreadsheet creation engine
                using (ExcelEngine excelEngine = new ExcelEngine())
                {
                    //Step 2 : Instantiate the excel application object
                    IApplication application = excelEngine.Excel;
                    application.DefaultVersion = ExcelVersion.Excel2016;

                    //An existing workbook is opened
                    FileStream inputStream = new FileStream(ResolveApplicationPath("ExpenseReport.xlsx"), FileMode.Open, FileAccess.Read);
                    IWorkbook  workbook    = application.Workbooks.Open(inputStream);

                    //The first worksheet object in the worksheets collection is accessed
                    IWorksheet worksheet = workbook.Worksheets[0];

                    application.XlsIORenderer = new XlsIORenderer();

                    ExportImageOptions imageOptions = new ExportImageOptions()
                    {
                        ImageFormat = ExportImageFormat.Jpeg
                    };

                    //Save the document as a stream and retrun the stream
                    using (MemoryStream stream = new MemoryStream())
                    {
                        if (imageFormat == "PNG")
                        {
                            imageOptions.ImageFormat = ExportImageFormat.Png;
                        }
                        //Save the converted image to MemoryStream
                        worksheet.ConvertToImage(worksheet.UsedRange, imageOptions, stream);
                        return(stream);
                    }
                }
            }
        }