Results 1 to 6 of 6

Thread: [RESOLVED] Render one cell as image (from XLS,XLSX)

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2010
    Posts
    63

    Resolved [RESOLVED] Render one cell as image (from XLS,XLSX)

    Hello people,
    I am working on one program where I need to get one cell from Excel document as image. I try to combine something with trial options from a lot different software companies (like Telerik) but without success.
    To make it more simple, from this document (for example):


    when I request render of B3 cell I need this BITMAP as result:


    I am really tired of trying to solve this,
    any help is appreciated,


    Thanks,
    Stefan

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Render one cell as image (from XLS,XLSX)

    Use the clipboard.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2010
    Posts
    63

    Re: Render one cell as image (from XLS,XLSX)

    Mm nice, I didn't even try simple thing as that :O
    I select B3 CTRL+C/V it to Paint and get what I want...
    But, how to do that with VB/C#? I must embed and COM control or something like that? Or it can be done without that visual things?

    Thanks,
    Stefan

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Render one cell as image (from XLS,XLSX)

    vb.net Code:
    1. Dim oExcel As New Microsoft.Office.Interop.Excel.Application
    2.     Dim oBook As Microsoft.Office.Interop.Excel.Workbook
    3.     Dim oSheet As Microsoft.Office.Interop.Excel.Worksheet
    4.  
    5.     Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    6.         oBook = oExcel.Workbooks.Open("C:\TestBook.xlsx")
    7.         oSheet = CType(oBook.Worksheets(1), Microsoft.Office.Interop.Excel.Worksheet)
    8.         Dim r As Microsoft.Office.Interop.Excel.Range = oSheet.Range("b3")
    9.  
    10.         Try
    11.             r.CopyPicture(Microsoft.Office.Interop.Excel.XlPictureAppearance.xlScreen, Microsoft.Office.Interop.Excel.XlCopyPictureFormat.xlBitmap)
    12.             PictureBox1.Image = My.Computer.Clipboard.GetImage
    13.  
    14.         Catch ex As Exception
    15.             TextBox1.Text = ex.Message
    16.  
    17.         Finally
    18.             oExcel.Quit()
    19.  
    20.         End Try
    21.     End Sub
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  5. #5

    Thread Starter
    Member
    Join Date
    Jul 2010
    Posts
    63

    Re: Render one cell as image (from XLS,XLSX)

    I already find something similar on MSDN, but this your sample is much easier to understand. Thank you very much.

    I will mark my thread as RESOLVED and add reputation to your post

  6. #6

    Thread Starter
    Member
    Join Date
    Jul 2010
    Posts
    63

    Re: Render one cell as image (from XLS,XLSX)

    Unfortunately I get another problem...
    I didn't even think about this situation. Most of PCs where this app will work have Windows XP/7 and Office 2007. I developing my app on Win7 (I set target framework .NET 3.5) and Office 2013 (COM Interop Excel 15/2013).

    When I try to run app on machines with Win7 and Office 2007 I get error like "Object reference not set to an instance of an object" (with MS.Office.Interop.Excel.dll)
    When I try to run app on machines with WinXP and Office 2007 it works with Office.Interop.Excel.dll (when I set "copy local" to true)

    Without copy local set to true (dll) app doesn't work at all. Just crash instantly.

    Anybody have idea how to solve this? If install Office 2007 and develop app with older Office.Interop on my PC does that mean that my app will work on PCs with Office 2007 and 2013?

    Thanks in advice,
    Stefan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width