Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Wed Jun 02, 2021 11:32 am

Hi,

I'm trying to find examples of how to save a WorkSheet and Workbook to a stream and convert to HTML. When I try to convert to HTML and return that as a stream I just get binary data. Loading is fine and works.

I'm doing the following (simplified):

Code: Select all
Workbook workbook = new Workbook();
MemoryStream stream = new MemoryStream();

workbook.LoadFromStream(fileToConvert);
workbook.SaveToStream(stream, Spire.Xls.FileFormat.HTML)

stream.Seek(0, SeekOrigin.Begin);
return stream;


I've also tried a sheet as follows:

Code: Select all
var activeWorksheet = workbook.ActiveSheetIndex;
Worksheet sheet = workbook.Worksheets[activeWorksheet];

sheet.SaveToStream(stream, "");

I don't know what the separator parameter is or how to convert this to HTML as sheet.SaveToStream(stream, Spire.Xls.FileFormat.HTML) does not work?

Any help would be appreciated.
Thanks.

kal.dhami
 
Posts: 7
Joined: Fri Apr 30, 2021 10:15 am

Thu Jun 03, 2021 9:22 am

Hello,

Thanks for your inquiry.
Regarding converting a workbook to html stream, I did observed that the method “workbook.SaveToStream(stream, Spire.Xls.FileFormat.HTML)” does not work. I am sorry that our spire.xls converts the excel file to html use the standard html specification, the content of multiple sheets will be written in a directory (as shown in the attached screenshot). This cannot be achieved with streams. Hope you can understand.
screenshot.png
screenshot.png (77.99 KiB) Viewed 1991 times

As for converting a worksheet to html stream, please note that "sheet.SaveToHtml();" is used to convert the worksheet to a csv/txt stream. Please use the following code instead to save the worksheet as an html stream.
Code: Select all
            //sheet.SaveToStream(stream, " ");
            sheet.SaveToHtml(stream);


If there are any other questions related to our products, please feel free to contact us.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Return to Spire.XLS