I am using Aspose Words Version=16.7.0.0 and i am embedding excel file in word document using the code below but i cannot preserve the file name of excel file when i open it.
The steps are:
- Creating excel document and saving to memory stream:
Workbook workbook = new Workbook(FileFormatType.Xlsx);
workbook.FileName = filename; // (this file name is relevant)
MemoryStream ms = new MemoryStream();
workbook.Save(ms, SaveFormat.Xlsx);
return ms;
- This memory stream is read and written to temporary file using file stream.
Code:
using (MemoryStream excelFileMemoryStream = this.myService.Value.GetExcelFileContent(excelFileName))
{
string temporaryExcelFilePath = Path.Combine(Path.GetTempPath(), excelFileName);
using (FileStream tempFileStream = new FileStream(temporaryExcelFilePath, FileMode.Create, FileAccess.Write))
{
excelFileMemoryStream.WriteTo(tempFileStream);
}
return temporaryExcelFilePath;
}
- Then i am embedding it to word document with InsertOleObject:
using (Stream fileStream = File.OpenRead(temporaryExcelFilePath))
{
builder.InsertOleObject(fileStream, "Excel.Sheet.12", true, iconImage);
}
The problem here is that when i open this excel file from word document, the name of excel file is not preserved.
New contributor
Luka Kalinić is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.