Saving File to a Stream

Hi, I have workbook.Save(report, SaveFormat.Html);
the report is empty

But the workbook.Save(report, SaveFormat.Pdf); is working
It is same workbook.


I have try to save to other types. Only pdf works.

Hi,

Thanks for your posting. Please download and use the latest version:
Aspose.Cells
for .NET v7.1.2.7



I found, it is working fine.

Please see the code below, it saves the html output in memory stream and then convert memory stream into byte array.

C#


string filePath = @“F:\Shak-Data-RW\Downloads\chart.xlsx”;


Workbook workbook = new Workbook(filePath);


MemoryStream ms = new MemoryStream();


workbook.Save(ms, SaveFormat.Html);


byte[] bytes = ms.ToArray();


I have the a stream return from service. 
MemoryStream report = new MemoryStream();

workbook.Save(report, SaveFormat.Html);
Then I return the stream to filestream reusult. 
return var results = new FileStreamResult(queryPrintResponse.FileData, “text/html
”);
I got the only pdf type work all right. All other types are empty report. Thanks for you help. 

Tony

Hi,

When you will return a stream of html, it will only show text and will not show images.

Because html cannot embed images, but you should look into data uri(s) that can embed your images.

Also, your style sheets will be lost.

PDF works fine because it can embed images and style sheets inside itself.

On the other hand, html just refer to your image and style sheet. For example below htm tag is referring to Aspose Logo.



If you want to embed, you will have to use DATA URI as I shown below.