I have an app that converts the first sheet of a spreadsheet to an image. The problem is that it bombs when doing the sr.ToImage function. Here is the error:
System.ArgumentException occurred
HResult=-2147024809
Message=Parameter is not valid.
Source=System.Drawing
StackTrace:
at System.Drawing.Drawing2D.GraphicsPath.get_PathPoints()
InnerException:
Here is the code:
Dim FileFormat As New Aspose.Cells.FileFormatInfo
Dim book As Aspose.Cells.Workbook
Select Case UCase(Extension)
Case “XLS”
book = New Aspose.Cells.Workbook(DocFile, New Aspose.Cells.LoadOptions(Aspose.Cells.LoadFormat.Auto))
Case “XLSX”, “XLSB”, “XLSM”, “XLTX”, “XLTM”
book = New Aspose.Cells.Workbook(DocFile, New Aspose.Cells.LoadOptions(Aspose.Cells.LoadFormat.Auto))
Case “CSV”
book = New Aspose.Cells.Workbook(DocFile, New Aspose.Cells.LoadOptions(Aspose.Cells.LoadFormat.CSV))
End Select
Dim sheet As Aspose.Cells.Worksheet
sheet = book.Worksheets(0)
Dim imgOptions As New Aspose.Cells.Rendering.ImageOrPrintOptions()
'Specify the image format
imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Png
'Only one page for the whole sheet would be rendered
imgOptions.OnePagePerSheet = True
'Render the sheet with respect to specified image/print options
Dim sr As Aspose.Cells.Rendering.SheetRender
Try
sr = New Aspose.Cells.Rendering.SheetRender(sheet, imgOptions)
sr.ToImage(0, “C:\Temp” & DocumentVersionID & “.1.png”)
Catch ex As Exception
sheet.Dispose()
book.Dispose()
ErrMsg = "Failed to open the render the sheet into png - " & ex.Message
GoTo nextfile
End Try
The problem is that it create the file, but keeps it open. If this bombs, I create my own image saying that the file was unable to be converted. The problem is that the file is being created, but not closed. So when I try and create the png, it says that it already exists and is open. I can’t find out how to close the file. I was assuming the sheet.dispose or book.dispose would do this. Can you let me know what to do here?
Here is the spreadsheet:
XLS.zip (312.0 KB)