Solved

convert an excel to image

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

We had a requirement to extract data from a SharePoint 2010 Customer List into a CSV file and then place the CSV file into a directory on the network so that the file could be consumed by an AS400 system. I will share in Part 1 how to Extract the Da…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

740 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