New syntax

I recently upgraded to a new version of the cells control. After upgrading, I recieve warnings in studio of obsolete syntax. I look at the docs, but it is not clear to me how to change it. Here are some examples, with the associated error message from studio:

'Public Sub Open(fileName As String)' is obsolete: 'Use Workbook(string) constructor method instead.
workbook.Open(Trim(Session("USHEET")))

'Public Sub Save(fileName As String, fileFormatType As Aspose.Cells.FileFormatType)' is obsolete: 'Use Workbook.Save(string,SaveFormat) method instead
workbook.Save(Trim(Session("USHEET")), FileFormatType.Xlsx)

'Public Sub SheetToImage(imageFile As String, imageFormat As System.Drawing.Imaging.ImageFormat)' is obsolete: 'Use SheetRender class.

Dim g1path As String = ipath & Trim(Session("CURR_USER")) & "g1" & iext
mysheet2.PageSetup.PrintArea = "H22:L37"
mysheet2.PageSetup.LeftMargin = 0
mysheet2.PageSetup.RightMargin = 0
mysheet2.PageSetup.BottomMargin = 0
mysheet2.PageSetup.TopMargin = 0
mysheet2.SheetToImage(g1path, System.Drawing.Imaging.ImageFormat.Jpeg)

What should I change to update these statements?


This message was posted using Aspose.Live 2 Forum

Hi,

1) Please see the document to know how to open Excel files for your complete reference:
http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/opening-files.html

2) Please see the document to know how to save Excel files for your complete reference:
http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/saving-files.html

3) see the sample code for your reference:
Dim mysheet2 As Worksheet = workbook.Worksheets(1)

Dim printoption As New ImageOrPrintOptions()
printoption.ImageFormat = ImageFormat.Jpeg
Dim sr As New SheetRender(mysheet2, printoption)
Dim sheetPageCount As Integer = sr.PageCount
For j As Integer = 0 To sheetPageCount - 1
sr.ToImage(j, “e:\test\image” & j.ToString() & “.jpeg”)
Next j

Note: SheetRender class is included in the Aspose.Cells.Rendering namepace, so you need to import this namespace in your program too.


Thank you.

Regarding your sample code, what I am doing in my example is exporting only a range of cells to image, not the entire sheet. Using your example, how do I specify a range of cells?

Hi,

Yes, you may simply paste your code before using SheetRender API, it will work fine as before.
i.e.

mysheet2.PageSetup.PrintArea = "H22:L37"
mysheet2.PageSetup.LeftMargin = 0
mysheet2.PageSetup.RightMargin = 0
mysheet2.PageSetup.BottomMargin = 0
mysheet2.PageSetup.TopMargin = 0

I import the rendering namespace("Imports Aspose.Cells.Rendering"), but this line:

printoption.ImageFormat = ImageFormat.Jpeg

Says that the " ImageFormat" is undeclared (the second instance to the right of =).

Hi,

For the line:

ImageFormat is a .NET API in System.Drawing.Imaging namespace, so you need to import System.Drawing.Imaging namespace too into your program/application.

//You may also use fully qualified naming
printoption.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg

Your last suggestion worked, thank you very much. Now hopefully the last issue is that when I use the new syntax, I get an incomplete image with a large amount of whitespace around. Using the old syntax, I would get just the range of cells requested with no extra space around. Example:

Dim ipath As String = "C:\Data\pool-proj\" 'The rendering path for Aspose in dev

Dim iext As String = ".jpeg"

'Instantiate a Workbook object that represents Excel file & opens it for use

Dim workbook As Workbook = New Workbook(Trim(Session("USHEET")))

workbook.CalculateFormula()

'Create sheet objs for each export range

Dim mysheet As Worksheet = workbook.Worksheets(0)

mysheet.PageSetup.PrintArea = "A2:K7"
mysheet.PageSetup.LeftMargin = 0
mysheet.PageSetup.RightMargin = 0
mysheet.PageSetup.BottomMargin = 0
mysheet.PageSetup.TopMargin = 0


Dim printoption As New ImageOrPrintOptions()

printoption.ImageFormat = ImageFormat.Jpeg
Dim sr As New SheetRender(mysheet, printoption)

sr.ToImage(0, ipath & "G4" & ".jpeg")

I attach the image that is output from this code, alonmg with the source sheet. How to eliminate the whitespace and get all the cells?

Hi,

Please add a line to your code before rendering your desired sheet:
printoption.OnePagePerSheet = True


Thank you.