"Paste as Picture" in Aspose.Words

I have a table in Excel which uses the Orientation element of Excel’s Alignment functionality to create a table with angled headers.


This particular aspect of the cell formatting is lost when I select the table and paste it into the Word document. However, there is a “Paste as Picture” Paste Option which results in a document that looks the way I want - the cell orientation is preserved.

Is there a way to have Aspose.Words execute a Paste action with the “Paste as Picture” Paste Option?

I’ve attached the source Excel document and the destination Word document, so you can see what I’m trying to achieve in Aspose.

Thanks,

Peter Hornby

Hi Peter,

Thanks for your inquiry. There is no such method to paste MS Excel contents as “Paste as Picture” into MS Word document by using Aspose.Words. However, you can use Aspose.Cells to convert MS Excel sheet to image and insert that image to Word document by using Aspose.Words as shown in following code snippet.

//open a template Excel file.
Aspose.Cells.Workbook book = new Aspose.Cells.Workbook(MyDir + "Angled+Headers.xlsx");

//Get the first worksheet.
Aspose.Cells.Worksheet sheet = book.Worksheets[0];

//Define ImageOrPrintOptions
Aspose.Cells.Rendering.ImageOrPrintOptions imgOptions = new Aspose.Cells.Rendering.ImageOrPrintOptions();

//Specify the image format
imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;

//Only one page for the whole sheet would be rendered
imgOptions.OnePagePerSheet = true;

//Render the sheet with respect to specified image/print options
Aspose.Cells.Rendering.SheetRender sr = new Aspose.Cells.Rendering.SheetRender(sheet, imgOptions);

//Render the image for the sheet
Bitmap bitmap = sr.ToImage(0);

//Save the image file specifying its image format.
bitmap.Save(MyDir + @"SheetImage.jpg");

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

builder.InsertImage(MyDir + @"SheetImage.jpg");

doc.Save(MyDir + "AsposeOut.docx");

I have noticed that the Aspose.Cells component is not converting the sheet to image correctly. I am moving this forum thread to Aspose.Cells forum and my colleagues from Aspose.Cells team will reply you shortly.

Hi,



Thanks for your posting and using Aspose.Cells for .NET.

We were able to replicate this issue using the latest version: Aspose.Cells
for .NET v7.3.4.3
with the following code.

We have logged this issue in our database. We will look into this issue and fix it.

Once the issue is fixed or we have some other update for you, we will let you know asap.

This issue has been logged as CELLSNET-41270.

Please see the following code and output image generated by it for your reference.

C#


Workbook workbook = new Workbook(path);


Worksheet worksheet = workbook.Worksheets[0];


//Apply different Image / Print options.

Aspose.Cells.Rendering.ImageOrPrintOptions options = new Aspose.Cells.Rendering.ImageOrPrintOptions();

options.OnePagePerSheet = true;

options.ImageFormat = ImageFormat.Png;


SheetRender sr = new SheetRender(worksheet, options);

Bitmap bitmap = sr.ToImage(0);

bitmap.Save(path + “.out.png”, ImageFormat.Png);


Output Image:

Hi,

Thanks for your posting and using Aspose.Cells for .NET.

We have fixed this issue. .

Please download and try this fix: Aspose.Cells for .NET v7.4.0.1 and let us know your feedback.

The issues you have found earlier (filed as CELLSNET-41270) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.