We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Reading strings and converting it into HTML

Hi,


I have a string which is actually a OWC XML file coming into my method as attached (report.xml, FYI).

I am trying to read to convert this string into a stream and convert it into HTML, but i am ending up getting a blank HTML…

Here is my code sample:

// Actual Conversion Function
public String GetHTMLOutput(String spreadSheetXml)
{
StreamReader reader = null;
MemoryStream stream = new MemoryStream();
string htmlData = “”;
try
{
byte[] b = System.Text.ASCIIEncoding.ASCII.GetBytes(spreadSheetXml);
stream.Read(b, 0, b.Length);
Aspose.Cells.Workbook wBook = new Aspose.Cells.Workbook(stream);
Aspose.Cells.License license = new Aspose.Cells.License();
license.SetLicense(ResourceHelper.GetLicenseStream());
wBook.Save(stream, Aspose.Cells.SaveFormat.Html);
reader = new StreamReader(stream);
reader.BaseStream.Position = 0;
htmlData = reader.ReadToEnd();
}
finally
{
if (reader != null)
{
reader.Close();
reader = null;
}
if (stream != null)
{
stream.Close();
stream = null;
}
}

return htmlData;
}

I am ending up getting a blank html document with only styles and no data.

If i do something like:
Aspose.Cells.Workbook wBook = new Aspose.Cells.Workbook(@“Report\Bin\report.xml”, false);
I am able to get the HTML file with some special characters like, ', ‘’ inside them.

But as this code is running on the DMZ, we don’t have the option of creating files, so i have to save it onto Mem Stream and manage the same.

Can you please guide me in solving this problem?


Thanks & Regards,
Anil

Hi,

I have converted your file to html using the latest version:
Aspose.Cells for .NET v6.0.1.6

The output html file, I am attaching, opens fine and works fine.

Do you see any problem, I did notice some extra “carriage return or line feed character” at the the end of the file when I viewed it in notepad? Do you want to remove it?

Below is my code.

C#


string path = @“C:\Documents and Settings\Home\Desktop\report.xml”;


Workbook workbook = new Workbook(path);


workbook.Save(path + “.out.html”, SaveFormat.Html);

Hi,


I do agree that this thing work, but the problem that i am facing is the contents in the XML file are coming in as strings rather than from file. So when i try to load a string into the WorkBook.

Try copying the entire file contents as a .NET String Class object and please go through this procedure, you might find the issue.

Thanks & Regards,
Anil

Hi,

Please try this code.

C#


StreamReader reader = null;


//MemoryStream stream = new MemoryStream();

string htmlData = “”;


try

{

byte[] b = System.Text.ASCIIEncoding.ASCII.GetBytes(spreadSheetXml);

MemoryStream stream = new MemoryStream(b);

stream.Read(b, 0, b.Length);

Thanks for the code…


But the same code is what i have written and have provided to you as attachment on the first mail of this post which didn’t work properly and hence have posted the issue

Thanks
Anil

Hi,


The code is not exactly the same. In the updated code segment, we have initialized the MemoryStream later on and also with respect to byte array. Please try it and let us know.

Thank you.

I do aggree, the other one keeps the Stream Read Only and also does initialize the capacity of the stream and hence there may be chances of an exception if the new stream exceeds this limit which is not so in the case of ReadBytes.


I have already tried them as well…

But the problem that we are facing is after the stream gets in, you have configued as ASCII encoding -
is OWC’s Spreadsheet XML compatible with this?
When we write to re-write this stream into
wBook.Save(stream, SaveFileFormat.HTML), it creates an HTML file with no data in it, but just with skeletion of styles…


Cheers,
Anil

Hi,


We suggest to set the encoding to ASCII and if the issue is still there, please give us entire code segment, we request you to create a sample console application to show the issue. By the way, we did test your code and found it works fine.


Thank you.