How to insert an object into a worksheet?


#1

i wanna inset a xls or doc file as objects into a xls file, and my code here

Dim fs As System.IO.FileStream = IO.File.OpenRead("e:\file.jpg")
Dim imagedata(fs.Length) As Byte
fs.Read(imagedata, 0, imagedata.Length)
fs.Close()
fs = IO.File.OpenRead("e:\123.txt")
Dim objectData(fs.Length) As Byte
fs.Read(objectData, 0, objectData.Length)
fs.Close()
'Response.Write(imagedata.Length)
'Response.Write(objectData.Length)
Dim wb As New Cells.Workbook
Dim worksheet As Cells.Worksheet = wb.Worksheets(0)
worksheet.OleObjects.Add(3, 3, 150, 150)
worksheet.OleObjects(0).ImageData = imagedata
worksheet.OleObjects(0).ObjectData = objectData
worksheet.OleObjects(0).Border.IsVisible = False
wb.Save("e:\test.xls")

but it not work,always show System.NullReferenceException err, and file that create cant open with 0 byte


#2

Please try this attached fix.

Aspose.Cells only supports to insert an xls file as an ole object. So please change your code to:

fs = IO.File.OpenRead("e:\123.xls")


#3

thanx alot,i tried your fix and it works well.hope aspose.cells can supports more file future