[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):
http://i.imgur.com/Oa9o2ko.jpg
when I request render of B3 cell I need this BITMAP as result:
http://i.imgur.com/tXNzNGB.jpg
I am really tired of trying to solve this,
any help is appreciated,
Thanks,
Stefan
Re: Render one cell as image (from XLS,XLSX)
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
Re: Render one cell as image (from XLS,XLSX)
vb.net Code:
Dim oExcel As New Microsoft.Office.Interop.Excel.Application
Dim oBook As Microsoft.Office.Interop.Excel.Workbook
Dim oSheet As Microsoft.Office.Interop.Excel.Worksheet
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
oBook = oExcel.Workbooks.Open("C:\TestBook.xlsx")
oSheet = CType(oBook.Worksheets(1), Microsoft.Office.Interop.Excel.Worksheet)
Dim r As Microsoft.Office.Interop.Excel.Range = oSheet.Range("b3")
Try
r.CopyPicture(Microsoft.Office.Interop.Excel.XlPictureAppearance.xlScreen, Microsoft.Office.Interop.Excel.XlCopyPictureFormat.xlBitmap)
PictureBox1.Image = My.Computer.Clipboard.GetImage
Catch ex As Exception
TextBox1.Text = ex.Message
Finally
oExcel.Quit()
End Try
End Sub
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 ;)
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