Solved

convert an excel to image

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Pimping Sharepoint 2007 without Server-Side Code Part 1 One of my biggest frustrations with Sharepoint 2007 in the corporate world is that while good-intentioned managers lock down the more interesting capabilities of Sharepoint programming in…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 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

21 Experts available now in Live!

Get 1:1 Help Now