Good evening Aspose Team,
we’re working with Aspose.Total for .NET to evaluate the .Document and .Cells in order to be sure if those libraries fits our demands.
What I’m trying to realize is:
- load a word document in memory (OK)
- replace some placeholders in the document (OK)
- load an excel embedded table inside the document file into memory (OK)
- edit a value in a cell and save it back to memory (OK)
- replace original embedded excel table with the new one (OK)
- open the word document and open the new embedded table (FAIL)
what we see in point 6 is, instead of an Excel table, an image without the possibility to edit as an excel table (in the original document was possible).
Below the code we’re using:
//ms is an already filled MemoryStream
Document doc = new Document(ms);
doc.Range.Replace("@@test@@", "NEWTEXT", new FindReplaceOptions(FindReplaceDirection.Forward));
DocumentBuilder builder = new DocumentBuilder(doc);
NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);
foreach (Shape shape in shapes)
{
if (shape.OleFormat != null)
{
if (!shape.OleFormat.IsLink)
{
//Extract OLE Excel object
if (shape.OleFormat.ProgId == "Excel.Sheet.12")
{
MemoryStream stream = new MemoryStream();
shape.OleFormat.Save(stream);
stream.Seek(0, SeekOrigin.Begin);
Workbook book = new Workbook(stream);
Worksheet sheet = book.Worksheets[0];
sheet.Replace("@@a1cell@@", "newcontent");
sheet.PageSetup.PrintArea = "A1: G5";
//sheet.PageSetup.LeftMargin = 0;
//sheet.PageSetup.RightMargin = 0;
//sheet.PageSetup.TopMargin = 0;
//sheet.PageSetup.BottomMargin = 0;
book.Save(stream, Aspose.Cells.SaveFormat.Xlsx);
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
imgOptions.OnlyArea = true;
SheetRender sr = new SheetRender(sheet, imgOptions);
Bitmap bitmap = sr.ToImage(0);
builder.MoveTo(shape);
stream.Position = 0;
Shape newShape = builder.InsertOleObject(stream, "Excel.Sheet.12", true, bitmap);
shape.Remove();
break;
}
}
}
}
doc.Save(output, Aspose.Words.SaveFormat.Docx);
output.Position = 0;
String headerInfo = "attachment; filename =" + "document.docx";
WebOperationContext.Current.OutgoingResponse.Headers["Content - Disposition"] = headerInfo;
WebOperationContext.Current.OutgoingResponse.ContentType = "application/octet-stream";
return output;