We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Error on Reading Excel File

Hello Sir,
Using VB.Net with ASpose.cells, I have Created an Excel File which Contains an Image Column. I use the Following Code to add an Image to an Excel File.

Dim b() As Byte
If (ds.Tables(0).Rows(i).ItemArray(j).ToString() <> “”) Then

b = CType(ds.Tables(0).Rows(i).ItemArray(j), Byte())
Dim mem As MemoryStream
mem = New MemoryStream(b)
'apWorkSheet.Pictures.Add(100, 3, mem, 23, 1)
'apWorkSheet.Pictures.Add(0, 0, 2, 1, mem)
apWorkSheet.Pictures.Add(1, 1, mem)
End If.
I Sent the Excel File as an Attachment. Kindly Check it. While Opening that File, an Error Occurs.

Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for considering Aspose,

Well, I have tried to write an image from stream to Excel sheet and it works fine using Aspose.Cells Latest Version. May be you are using some Old Version. Please try the latest attached fix. Following is my Sample Code which I used to write the Picture from a memory stream to a worksheet,

Sample Code:-

Dim _book As Workbook = New Workbook


Dim sheet As Worksheet = _book.Worksheets(0)

Dim fs As FileStream = File.OpenRead("C:\Sample.jpg")

Dim imageData(fs.Length) As Byte

'Obtain the picture into the array of bytes from streams.

fs.Read(imageData, 0, imageData.Length)

Dim mem As MemoryStream

mem = New MemoryStream(imageData)

sheet.Pictures.Add(1, 1, mem)


If you still face the problem please post your Template Excel file from which you are extracting the image and we will figure it out.

Thank you & Best Regards,

There is No Problem on Attaching a Single Image File from My Computer. But I am Getting an Image From Sql Server. My Entire Coding is as Follows.

If (cmbStudentNo.SelectedIndex > 0) Then
query = “Select " & _
" StudentPhoto,admison_no " & _
" from " & _
" tbl_admison adm,tbl_rollnum roll” & _
" where " & _
" adm.admison_no=roll.adm_num "
'and roll.roll_num= ‘" + cmbStudentNo.SelectedValue.ToString() + "’"
Dim b() As Byte
Dim apWorkbook As New Workbook()
Dim apWorksheet As Worksheet
Dim cells As Cells
apWorksheet = apWorkbook.Worksheets(0)
cells = apWorksheet.Cells
’ cmd = New SqlCommand(query, con)
If (con.State = ConnectionState.Closed) Then
End If
sda = New SqlDataAdapter(query, con)
ds = New DataSet()


'b = CType(cmd.ExecuteScalar, Byte())

Dim i, j As Integer
For i = 0 To ds.Tables(0).Rows.Count - 1
For j = 0 To ds.Tables(0).Columns.Count - 1
If (ds.Tables(0).Rows(i).ItemArray(0).ToString() <> “”) Then
b = CType(ds.Tables(0).Rows(i).ItemArray(0), Byte())
Dim mem As MemoryStream
mem = New MemoryStream(b)
PictureBox1.Image = Image.FromStream(mem)
cells(4 + i, 0).PutValue(ds.Tables(0).Rows(i).ItemArray(j).ToString())
apWorksheet.Pictures.Add(0, i + 4, mem)
End If

SaveFileDialog1.DefaultExt = “.xls”
If (SaveFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK) Then
apWorkbook.Save(SaveFileDialog1.FileName, FileFormatType.Default)
MessageBox.Show(“Report Generated Successfully”, “Placement Informations”)
End If
Catch ex As Exception
MessageBox.Show(ex.Message, “Placement Informations”)
End Try

End If.

Yes I got the Result while using Latest Aspose.cells Dll which u sent. Thanks for your Help.