Free Support Forum - aspose.com

Cells questions

We are currently evaluating the Java version of Cells and I have a couple of questions:


  • Is it possible to determine the cell range to for each page be rendered?
  • Would it be possible to render an image or file consisting of a specified cell range?
    i.e. render a complete sheet or cell range to an image that is sized by the cell range at a specified resolution rather than a specific page size

As background we are looking to integrate Cells into our image viewing product and need to be able to render spreadsheets in a sheet per page mode and also in print preview mode. As we allow users to add annotations we need to track where a particular cell is rendered in each mode so that the annotation can be correctly placed.

Hi,

I think you may specify the printable range/area before rending image of the sheet. Aspose.Cells for Java does support to render images of your desired format/attributes based on your desired area. See the documents for your reference

http://www.aspose.com/documentation/java-components/aspose.cells-for-java/utilize-page-setup-and-printing-options.html

http://www.aspose.com/documentation/java-components/aspose.cells-for-java/converting-worksheet-to-image.html


Thank you.

Thanks for the quick reply though it doesn’t offer anything we haven’t already tried.


What I am looking for is a way to set the image size to reflect the size of the cell range being rendered, not use a specific paper size. i.e. I would like to do something like pageSetup.setPaperSize(PaperSizeType.PAGE_AUTO)
or imgOptions.setRenderType(CELL_RANGE)

The above would cater for a render full sheet scenario.

I also need to determine what cell range is associated with each SheetRender page.
Something like sheetRenderer.getCellRange(page) would work

Hi,

Please see the following sample code, it will give your reference on how you can achieve your desired results. I take the image of certain area in the sheet, also the image size is same as range.

Sample code:
Workbook wb = new Workbook();
wb.open(“e:\test\Book1.xls”);
Worksheet sheet = wb.getWorksheets().getSheet(“Sheet1”);
ImageOptions options = new ImageOptions();
options.setPaginate(false);
options.setImageFormat(ImageFormat.EMF);

PageSetup ps = sheet.getPageSetup();
ps.setPrintArea(“A1:B5”);
ps.setLeftMargin(0);
ps.setRightMargin(0);
ps.setTopMargin(0);
ps.setBottomMargin(0);


SheetRender sr = new SheetRender(sheet, options);

for (int index = 0; index < sr.getPageCount(); index++)
{
sr.toImage(index,“out_ImgRange.emf”);


}


Thank you.

Amjad Sahi:

Please see the following sample code, it will give your reference on how you can achieve your desired results. I take the image of certain area in the sheet, also the image size is same as range.

Hi,

I tried the code you supplied with the attached spreadsheet. It should render at 600x600 pixels when then horizontal and vertical resolutions are set to 100DPI.
However the file produced measured 633x578 pixels.

Are there any settings that I may have missed?

Hi,

You cannot control the exact size of the image. Using horizontal and vertical resolution, you can only stretch or shrink the image.