?
Solved

convert an excel to image

Posted on 2014-10-05
4
Medium Priority
?
160 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 14

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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Note:  There are two main ways to deploy InfoPath forms:  Server-side and directly through the SharePoint site.  Deploying a server-side InfoPath form means the form is approved by the Administrator, thus allowing greater functionality in the form. …
In case you ever have to remove a faulty web part from a page , add the following to the end of the page url ?contents=1
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

770 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