Solved

convert an excel to image

Posted on 2014-10-05
4
130 Views
Last Modified: 2014-11-01
Hi,

I have  a scenario where a user will be uploading an excel file to SharePoint and then we need to automate the process of converting the excel file with its maximum range to an image file and upload it to the same folder in the document library. How can we achieve this process?

Please help!!!
0
Comment
Question by:Techsavy
  • 2
4 Comments
 
LVL 13

Expert Comment

by:frankhelk
ID: 40363163
There are printer drivers who could export images instaed of really printing paper, i.e. these:

http://sourceforge.net/projects/imageprinter/
http://code-industry.net/imageprinter.php

There are more when you ask Google for "printer diver image". When you equip your excel files with some kind of onLoad-Macro, or generate some.NET code that does Excel remote control, you'd be able to print the table automatically to an image ... for upload, you might use some command line FTP client ....
0
 
LVL 12

Expert Comment

by:Ramkisan Jagtap
ID: 40363175
Please create a event receiver for the document library you are using.
Create a Item added event and try below code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using xls = Microsoft.Office.Interop.Excel;
using System.IO;
using System.Windows.Forms;

namespace PracticeConsoleApp
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            string fileNameToProcess = @"C:\Users\jagtaram\Desktop\Office\App_n_Services.xls";

            //Start Excel and create a new document.
            xls.Application oExcel = new xls.Application();
            xls.Workbook wb = null;
            try
            {
                wb = oExcel.Workbooks.Open(
                    fileNameToProcess.ToString(), false, false, Type.Missing, "", "", true, xls.XlPlatform.xlWindows, "", false, false, 0, false, true, 0);
                //wb.RefreshAll();

                xls.Sheets sheets = wb.Worksheets as xls.Sheets;
                xls.Worksheet sheet = sheets[1];

                //Following is used to find range with data
                string startRange = "A1";
                string endRange = "P25";
                xls.Range range = sheet.get_Range(startRange, endRange);
                range.CopyPicture(xls.XlPictureAppearance.xlScreen, xls.XlCopyPictureFormat.xlBitmap);

                System.Drawing.Image imgRange = GetImageFromClipboard();

                imgRange.Save(@"C:\Users\jagtaram\Desktop\Office\ExcelSheetImage.bmp", System.Drawing.Imaging.ImageFormat.Bmp);

                wb.Save();
                Console.Write("Specified range converted to image successfully. Press Enter to continue.");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                //throw;
            }
            finally
            {
                wb.Close();
                oExcel.Quit();
                oExcel = null;
            }

            Console.ReadLine();
        }

        public static System.Drawing.Image GetImageFromClipboard()
        {
            System.Drawing.Image returnImage = null;

            // This doesn't work
            //if (Clipboard.ContainsImage())
            //{
            //    returnImage = Clipboard.GetImage();
            //}
            //return returnImage;

            // This works
            System.Windows.Forms.IDataObject d = Clipboard.GetDataObject();
            if (d.GetDataPresent(DataFormats.Bitmap))
            {
                returnImage = Clipboard.GetImage();
            }

            return returnImage;
        }
       
    }
}

Open in new window

0
 

Author Comment

by:Techsavy
ID: 40364186
Hi Kisan,

Can you please help me how to tie this to an eventhandler?
0
 
LVL 12

Accepted Solution

by:
Ramkisan Jagtap earned 500 total points
ID: 40372294
Please check following for for creating an event receiver for a list item.
http://msdn.microsoft.com/en-us/library/ee231563.aspx
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now