We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Sheet to image

Hello, again!

I was searching through the forums and found some posts about this issue but couldn’t find a suitable solution for it. I realize that the “Object Changed” is not an Aspose caused issue, but from Office itself. However, I have a presentation where I need to include both Charts and Tables. With Charts, I managed to replace the Object Changed picture with the picture of the chart, so the user does not recognize the OLE Object Frame as an image or frame, but as the chart itself.

Thus the problem resides in the tables, as user
kosystems already posted in this thread. I was wondering if anyone has already found a solution, i.e., how to take a picture of a worksheet or, better yet, a picture of the table itself so it can replace the Object Changed picture. Any other solution to go around the Object Changed issue with tables is welcome.

Once more, congratulations for a great work

Hi,

Thanks for considering Aspose.

Aspose.Cells do support to convert a chart to an image file but to take a sheet / sheet data table's pictrue is not available. I think you may try to insert an ole object (based on that spreadsheet file) in your powerpoint presentation using Aspose.Slides APIs. Is it not working fine?

Thank you.

Hi, Amjad.

Yes that works, but it results in the Object Changed issue, i.e, when I insert the workbook in a slide, through an OLE Object Frame it stays there and it contains the table, but it shows up with the “Object Changed” image, thus hiding the data in the table. This data is only revealed to the user when he edits that object. This is exactly what happens with the charts embedded in the slides, but in this case I am able to replace the object changed image with the image that results from “my_chart.ToImage()”. However, as you stated, I’m not able to take a sheet’s picture to replace the object changed image.

I was thinking of a workaround, like programatically exporting the book to a file, somehow “take its picture”, an then replace it in the OLE Object Frame.

Does anyone here ever had the same problem? Did anyone solve it?

If noone has a solution for this, can I request this as new feature?

I really need to have this Workbook in a slide so the user can edit the values, but cannot use a regular table because I need to preserve the formulas.

We will make sheet2image feature in the future. However, it’s a very complex feature so it won’t be available in a short time.

Hello again,

I was wondering if you have any updates regarding sheet2image feature. I manage to create a sheet2image function of my own, but it is somewhat inaccurate. It is enough, for now, but I’m afraid my client will request something more… perfect.

If you like, I can show you my code for you to use in the development of this feature. I already cover merged cells, cell borders, cell font styles, text alignment and other small stuff. This function returns a nice picture of the table, but not nearly has perfect has a copy paste from excel to power point has an image.

Please give me some feedback on this.
Thanks,
Cruz

Hi,

Well, hopefully the feaure Sheet2Image would be available in a couple of months time as we are working on feature.

Thanks for being patient!

Ok, I understand your position. In any case, I offer my help in this development, as I absolutely need this feature as soon as possible. My client is putting the project at risk, if this issue is not solved in the near weeks.

Please tell me, is there something I can help you with?
Cruz

Hi Cruz,

We will post a test fix at the end of this week.

But the fix only supports default page setup setting not support Scale,FitToPageWidth..and so on.

Thanks for your patience.

Oh, perfect!

Thanks a lot for your effort and sorry about the pressure… :wink:
I will wait until the end of the week, then.

By the way… if it is of any good to you, the features that I need most are really the basic ones: font styles; cell alignments and merges; borders; row and column sizes and autofits; and text wrapping. I believe this is all we need for now. If you could focus your development on these issues, I would very much appreciate.

Thanks again,
Cruz

Hi Cruz,

Please try this fix.

We have added some methods to conveter worksheet to image.See following sampe codes:

Workbook wb = new Workbook();
wb.Open(@"F:\FileTemp\Book1.xls");

Bitmap bitmap = wb.Worksheets[0].SheetToImage();
bitmap.Save(@"F:\FileTemp\dest.bmp");

The following list is Worksheet.SheetToImage() verload methods:

///


/// Creates the sheet image and returns it as a Bitmap object.
///

///
public Bitmap SheetToImage()

///


/// Creates the sheet image and saves it to a file.
///

/// The image file name with full path.
/// Indicates whether workshert can be paginated
///
///

The following formats are supported:
/// .bmp, .gif, .jpg, .jpeg, .tiff, .emf.


///
public void SheetToImage(string imageFile, bool isPaginate)

///


/// Creates the sheet image and saves it to a file.
///

/// The image file name with full path.
///

The following formats are supported:
/// .bmp, .gif, .jpg, .jpeg, .tiff, .emf.


///
public void SheetToImage(string imageFile)

///


/// Creates the sheet image and saves it to a file in the specified format.
///

/// The image file name with full path.
/// The format in which to save the image.
/// Indicates whether workshert can be paginated
///

The following formats are supported:
/// .bmp, .gif, .jpg, .jpeg, .tiff, .emf.


///
public void SheetToImage(string imageFile, ImageFormat imageFormat, bool isPaginate)


///


/// Creates the sheet image and saves it to a file in the specified format.
///

/// The image file name with full path.
/// The format in which to save the image.
///

The following formats are supported:
/// .bmp, .gif, .jpg, .jpeg, .tiff, .emf.


///
public void SheetToImage(string imageFile, ImageFormat imageFormat)

And we also support print worksheet now.

///


/// Prints the work sheet
///

/// The printer name
public void SheetToPrinter(String PrinterName)

Hello again,

I was testing SheetToImage and it seems really good! For me to be completely satisfied with it, though, I think it’s only missing the support of merged cells. Everything else seems just perfect.

I also noticed that you always create the image with a white border around the data cells. Can you tell me if this is size fixed? If so, what is its size, so I can cut it out if necessary?

Can you give me an estimate for the merged cells issue?

Thanks again for your brilliant work!
Cruz

Oh, actually it does support merged cells, but only along rows. If I merge a cell with another below it, the bmp is returned as a null pointer.

Hi Cruz,

Could you provide some sample worksheet files to us? Thank you.

No problem, it’s very simple… just run this code:

Workbook book = new Workbook();
Worksheet sheet = book.Worksheets[0];

sheet.Cells[2, 2].PutValue(“test1”);
sheet.Cells[2, 3].PutValue(“test2”);
sheet.Cells[3, 3].PutValue("<- merge test");

sheet.Cells.Merge(2, 2, 2, 1);

Bitmap bmp = book.Worksheets[0].SheetToImage();
bmp.Save(“c:\test.bmp”);

book.Save(“c:\test.xls”);

Hi Cruz,

The attachment is my result using your code. "test.xlsPrintViewByPrintScreen.bmp" is Print Preview of ms.excel. I think it is same as test.bmp created by Aspose. Could you point out what is the problem in printting merge cells?

Thank you.

Humm… this is very strange… because if I run this code in my project (which is blank so no other control is causing problems) I get a NullReferenceException in the bolded row below:

Workbook book = new Workbook();
Worksheet sheet = book.Worksheets[0];

sheet.Cells[2, 2].PutValue(“test1”);
sheet.Cells[2, 3].PutValue(“test2”);
sheet.Cells[3, 3].PutValue("<- merge test");

sheet.Cells.Merge(2, 2, 2, 1);

Bitmap bmp = book.Worksheets[0].SheetToImage(); // NullReferenceException here
bmp.Save(“c:\test.bmp”);
book.Save(“c:\test.xls”);

Here’s the stack trace for the exception:

at Aspose.Cells.Pdf.ᢽ.get_ᢾ()
at Aspose.Charts.SheetPrint.ᙻ.ᚳ(Int32 ᚴ, Int32 ஧, Int32 ஁, Int32 ந, Int32 ஂ, Double Ւ, Double Փ, Double ୅)
at Aspose.Charts.SheetPrint.ᙻ.ᚱ(Int32 ᚭ)
at Aspose.Charts.SheetPrint.ᙻ.ᔛ(Boolean ᚢ, Int32 ی)
at Aspose.Cells.Worksheet.SheetToImage(Boolean isPaginate)
at Aspose.Cells.Worksheet.SheetToImage()
at _Default.Page_Load(Object sender, EventArgs e) in c:\Documents and Settings\Sergio Picarra\My Documents\Visual Studio 2005\WebSites\WebSite1\Default.aspx.cs:line 49
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

I’ve also attached the dll you sent me 3 or 4 posts ago for you to test the version.

Thanks
Cruz

Hi Cruz,

Please try this fix.

Ahh, it looks perfect now! Many thanks, this is just what I needed!

Once again, excelent work. Will be in touch if anything else comes up :wink:

One question, though, regarding the white border around the sheet in the generated bmp: is the border sized fixed? If so, what is its size? I would like to be able to remove that border but I suppose I can do it myself if it really is fixed size.

Cruz

Hi Cruz,

Please try using following codes. Thank you.

YourWorksheet.PageSetup.LeftMargin = 0;
YourWorksheet.PageSetup.RightMargin = 0;
YourWorksheet.PageSetup.BottomMargin = 0;
YourWorksheet.PageSetup.TopMargin = 0;