Aspose.Cells extract cell coordinates

Hi


Can I extract cell coordinates in pixels? I need to convert the *.xls file into image and get coordinates of each cell on this image.

Thank you for your help!

Hi,


I am not sure about your requirement, could you elaborate it more and give us more details and examples/screen shots for it, we will check it soon.

By the way, do you want to get the position of every cell in the generated image in the worksheet?

Thank you.

I want to get the position of cells in the generated image from the worksheet by using ToImage or ToTiff. I calculated cells positions and sizes in the worksheet and found, that they don’t equal positions and sized in the generated image in actual size.


For example, width of some cell in the worksheet is 151 pixel, width of this cell in the images with resolution 96dpi is 155, with 100dpi - 162.

I want to know, how changes size of cells on the image in relation to cells in worksheet. It depends on the resolution?

Hi Samsen,

Please try the following code for your reference:

Sample code:

class MyDraw:DrawObjectEventHandler


{

Bitmap bit;

Graphics gr;

public MyDraw()

{

bit = new Bitmap(1200, 1200);

gr = Graphics.FromImage(bit);

gr.PageUnit = GraphicsUnit.Point;

}

public override void Draw(DrawObject drawObject, float x,float y,float width ,float height)

{

if(drawObject.Image != null)

gr.DrawImage(drawObject.Image, x,y,width,height);

if (drawObject.Cell != null)

{

gr.DrawString(drawObject.Cell.StringValue, new System.Drawing.Font("arial", 10), new SolidBrush(Color.Black),x,y);

}

}

}

ImageOrPrintOptions options = new ImageOrPrintOptions();

MyDraw md = new MyDraw();

options.DrawObjectEventHandler = md;

SheetRender sheetRender = new SheetRender(wb.Worksheets[0], options);

sheetRender.ToImage(0, @"e:\m\" + 0 + "" + ".png");

Thank you.

Hi,

"By the way, do you want to get the position of every cell in the generated image in the worksheet?" (c)
You earlier wrote this. And yes you guessed correct. So can you please tell me how to extract cell coordinates in pixel by using aspose.cells?

workSheet.Cells.GetViewColumnWidthPixel(j) - with this I can get width.
workSheet.Cells.GetRowHeightPixel(i) - with this I can get height.


Have Aspose.cells something like GetCellCoordinates(row,column)?
Thanks in advance :wink:

Hi,


I think you may refer to the code segment provided in our previous reply for your reference to accomplish your task:
https://forum.aspose.com/t/87295

And there is no such method like “GetCellCoordinates(row,column)” in Aspose.Cells APIs.

Thank you.

Okay Sahi, thanks it helped me.

Just one more clarifying for me. Coordinates return with DPI 72. When I set vertical resolution and horizontal resolution in option for SheetRender. It still return coordinates with DPI72. Can I change somehow that? Currently I use coefficient = neededresolution/72*(x or y or width or height).

Thanks in advance!

Hi,


Good to know that the sample helps you to accomplish your task. Well, there might be an issue with horizontal and vertical resolution of the SheetRender APIs, could you try to use some other image file format type e.g JPG if it helps you a bit.

Thank you.