MIME type not getting set properly?

I'm using aspose.cells to add an image to the background of each page of an excel document to represent a watermark of sorts. The problem I seem to be having is that when I save the document the mime type is not set properly. The code I am using is below:

Workbook workbook = new Workbook();

workbook.Open(docImageStream);

FileStream watermarkStream = File.OpenRead(filePath);

byte[] imageData = new byte[watermarkStream.Length];

watermarkStream.Read(imageData, 0, imageData.Length);

for(int i = 0; i < workbook.Worksheets[i].Count; i++)

{

workbook.Worksheets[i].SetBackground(imageData);

}

MemoryStream watermarkedDoc = new MemoryStream();

workbook.Save(watermarkedDoc, FileFormatType.Excel2003);

When I then save the file to my desktop and open with excel it tells me the file is not an excel file. The mimetype appears to be application/octet-stream??

Hi,

Thanks for your inquiry.

I am not sure about your code (especially regarding saving
the excel file), I think you may save the file directly to disk (e.g
workbook.Save(“f:\test\outputfile.xls”, FileFormatType.Excel2003):wink:
or use my updated code. I have tried it and it works fine.

Sample code:
Workbook workbook = new Workbook();
workbook.Open(“f:\test\MyFile.xls”);
FileStream watermarkStream = File.OpenRead(“f:\test\school.jpg”);
byte[] imageData = new byte[watermarkStream.Length];
watermarkStream.Read(imageData, 0, imageData.Length);
for (int i = 0; i < workbook.Worksheets.Count; i++)
{

workbook.Worksheets[i].SetBackground(imageData);

}

MemoryStream watermarkedDoc = workbook.SaveToStream();

FileStream fileStream = new FileStream(“f:\test\outputfile.xls”, FileMode.Create, FileAccess.Write);
fileStream.Write(watermarkedDoc.GetBuffer(), 0, Convert.ToInt32(watermarkedDoc.Position));
fileStream.Close();


Thank you.