Solved

convert an excel to image

Posted on 2014-10-05
4
136 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 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 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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
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 …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

828 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