Connecting Tech Pros Worldwide Help | Site Map

embedding a attachment using vb.net

Newbie
 
Join Date: Apr 2009
Posts: 3
#1: Apr 15 '09
Hi,

I'm providing a link button in my page(which contains a datagrid) so that when the user clicks on it they will be able to see the contents of the datagrid in a separate excel file.I provide the user with the option of attaching documents while they use my application.I would want that particular attachment to be embedded into excel document along with other contents.Is there a way to do this?

Note:I don't want to specify the link(location) where the attachment is present.Instead I would need the attached document itself to be embedded into the excel file.
iam_clint's Avatar
Forum Leader
 
Join Date: Jul 2006
Location: Oklahoma
Posts: 1,076
#2: Apr 16 '09

re: embedding a attachment using vb.net


Quote:

Originally Posted by niklesh View Post

Hi,

I'm providing a link button in my page(which contains a datagrid) so that when the user clicks on it they will be able to see the contents of the datagrid in a separate excel file.I provide the user with the option of attaching documents while they use my application.I would want that particular attachment to be embedded into excel document along with other contents.Is there a way to do this?

Note:I don't want to specify the link(location) where the attachment is present.Instead I would need the attached document itself to be embedded into the excel file.

I really don't get what you are trying to accomplish

So you have a datagrid exporting to excel.. what documents are going to be attached? where will they go? You say embedded into the excel document so I assume its a table/grid type layout attachment?
Newbie
 
Join Date: Apr 2009
Posts: 3
#3: Apr 17 '09

re: embedding a attachment using vb.net


I have a excel file created,whose contents are generated by exporting contents from a datagrid, when the user clicks on a link provided.I want to append a document present in my server into the excel file created.
Member
 
Join Date: Mar 2009
Location: Kathmandu
Posts: 42
#4: Apr 18 '09

re: embedding a attachment using vb.net


Sample code below, please add reference to Microsoft.Office.Interop.Excel

Imports Microsoft.Office.Interop


Expand|Select|Wrap|Line Numbers
  1.   Dim MyExcel As New Excel.Application
  2.         Dim wb As Excel.Workbook
  3.         wb = MyExcel.Workbooks.Open("c:\backup\text.xls")
  4.         Dim oleobjs = CType(wb.ActiveSheet.OleObjects, Excel.OLEObjects)
  5.         oleobjs.Add(Link:=False, Filename:="c:\backup\test.doc")
  6.  
  7.         wb.Close(True)
  8.         MyExcel.Quit()
  9.         Try
  10.             System.Runtime.InteropServices.Marshal.ReleaseComObject(source)
  11.             System.Runtime.InteropServices.Marshal.ReleaseComObject(wb)
  12.             System.Runtime.InteropServices.Marshal.ReleaseComObject(MyExcel)
  13.             GC.Collect()
  14.             GC.WaitForPendingFinalizers()
  15.  
  16.         Catch ex As Exception
  17.             MyExcel = Nothing
  18.             wb = Nothing
  19.         End Try
Reply


Similar Visual Basic .NET bytes