Well, Aspose.Cells for .NET is pure .NET component and it generally relies on .NET Garbage collection to release the resources against objects. Could you give us details why you save it to stream twice at the same time. When you call the save method of the workbook, after saving the book to a format, the workbook object (with its related object plus data) would be null. we appreciate if you could provide your code with template file here, we will check it soon.
here is a sample of code. Just click the button twice and you will get the error the second time the code runs.
Private mWorkbook As Aspose.Cells.Workbook
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'create a new empy Excel document
mWorkbook = New Workbook()
mWorkbook.Worksheets.RemoveAt(0)
Dim objSheet As Worksheet = mWorkbook.Worksheets.Add("Test")
objSheet.Pictures.Add(0, 0, Application.StartupPath + "\namelogo.jpg")
'save as PDF
'Save the document in Aspose.Pdf.Xml format
Dim stream As IO.MemoryStream = New IO.MemoryStream
mWorkbook.Save(stream, FileFormatType.AsposePdf)
stream.Seek(0, IO.SeekOrigin.Begin) '// Reset the pointer to the beginning of the stream
'// Load the document as raw XML
Dim xmlDoc As Xml.XmlDocument = New Xml.XmlDocument
xmlDoc.Load(stream)
stream.Close()
stream.Dispose()
stream = Nothing
'Read the file in Aspose.Pdf.Xml format into Aspose.Pdf
Dim pdf1 As Aspose.Pdf.Pdf = New Aspose.Pdf.Pdf()
'Bind the XML file (containing spreadsheet data) with the Pdf object
pdf1.BindXML(xmlDoc, Nothing)
'Create the PDF document by calling its Save method
pdf1.Save(Application.StartupPath + "\test.pdf")
'pdf1.Close()
pdf1 = Nothing
mWorkbook = Nothing
End Sub
exactly the same exception is raised (only filename changes):
System.IO.IOException: The process cannot access the file 'C:\_Dev\Matis\TestReporting\bin\Debug\MySpreadsheet.xml_img0.jpg' because it is being used by another process.
I could not reproduce the error. Which version of Aspose.Cells you are using? Did you try the latest 4.4.1.
And by the way could you separate Aspose.Pdf code and try the following code twice at the same time if it works fine.
Private mWorkbook As Aspose.Cells.Workbook
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'create a new empy Excel document
mWorkbook = New Workbook()
mWorkbook.Worksheets.RemoveAt(0)
Dim objSheet As Worksheet = mWorkbook.Worksheets.Add("Test")
objSheet.Pictures.Add(0, 0, Application.StartupPath + "\namelogo.jpg")
'save as PDF
'Save the document in Aspose.Pdf.Xml format
Dim stream As IO.MemoryStream = New IO.MemoryStream
mWorkbook.Save(stream, FileFormatType.AsposePdf)
stream.Seek(0, IO.SeekOrigin.Begin) '// Reset the pointer to the beginning of the stream
'// Load the document as raw XML
Dim xmlDoc As Xml.XmlDocument = New Xml.XmlDocument
xmlDoc.Load(stream)
stream.Close()
stream.Dispose()
stream = Nothing
Please try this fix. And please download the latest Aspose.Pdf fix.I think it's caused by Multi threads.
In this fix,we use Cell.GetStyle and SetStyle method replace the property of Cell.Style. The two methods will save more memory usage than cell.Style property.
If you want to set style of the cell, please change your codes as :