Export HTML content to Docx Format in ASP.NET

Hello,

I have some HTML content, which I want to export to “Docx” format using Aspose.Words .NET.

I have used the following code snippet:

Document doc = new Document();
string strContent = “

This is some content

”;
byte[] byteArray = GetBytes(strContent);

FileStream f = new FileStream(“yourfile.docx”, FileMode.Create);
f.Write(byteArray, 0, byteArray.Length);
doc.Save(f, SaveFormat.Docx);

I basically want to show a “Save file dialog” when exporting this content as “docx” in an ASP.NET webform.

However, when I run the above code, there is no exception, and no file is being exported.

Can you please let me know the proper code for exporting content to Docx along with the Save file dialog?

Hi,

Thanks for your inquiry. You can use the following overload of Save method to send the document to client browser:

Document.Save Method (HttpResponse, String, ContentDisposition, SaveOptions)

If you need to use Aspose.Words in ASP.NET application, I would recommend you use Aspose.Words.dll from .NET 2.0 folder.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertHtml("**This is some content**");
// Send the document in Word format to the client browser with an option to save to disk.
doc.Save(Response, "output", ContentDisposition.Attachment, new OoxmlSaveOptions());
Response.End();

I hope, this helps.

Best regards,

Hi Awaiz,

Thanks for the reply.

I tried the code and have been successfully able to export the content to a “docx” format.

However, when viewing the content in Word, it does not display the proper date about when the content was added / deleted.

For example, I made changes to the HTML content today (27 Jan 2014). However, when exporting to “docx”, it shows the date as "0/0/1900 12:00:00 AM"

I have attached the Html content (“Content.html”) and the exported “docx” document (“AsposeExport.docx”) herewith.

Is there any setting which will export the exact datetime stamp along with the content?

Hi Awais,

Can you please give an update?

Hi,

Thanks for your inquiry. While using the latest version of Aspose.Words i.e. 13.12.0, I managed to reproduce this issue on my side. I have logged this issue in our bug tracking system. The ID of this issue is WORDSNET-9589. Your thread has also been linked to this issue and you will be notified as soon as it is resolved. Sorry for the inconvenience.

Best regards,

Thanks Awais,

Is it a public bug tracking system? Can I have a look at it?

Hi Awais,

I also wanted to mention a related issue:
When exporting Html content to Docx, any comments added by the user against any content are not being exported at all.

Example Html:
normal content



added with track changes

When the above Html is exported, the comments are not being exported at all.

Can you please add this issue as well to the bug tracking issue WORDSNET-9589.

Thanks

Hi,

yjs:
Is it a public bug tracking system? Can I have a look at it?
Unfortunately, there is no direct way you can track issues by yourself. But, you are welcome to ask your issue status via forum threads. We will verify the status from our internal issue tracking system and reply you back.

Best regards,

Hi,

yjs:

normal content

But, when you convert this Html fragment to Word format using Microsoft Word 2013, you’ll observe the same behavior. In this case, Aspose.Words’ Html engine mimics the behavior of Microsoft Word. Please refer to the Annotation Features Supported on HTML Import section.

If we can help you with anything else, please feel free to ask.

Best regards,

Hi Awais,

Does that mean comments present within Html content will not be exported at all when converting to Docx format?

Hi,


Thanks for your inquiry. We will provide an ability to preserve comments during “Html to Word to Html” round-trip in Aspose.Words 14.1.0 - Jan 2014 release. Your request has been linked to the appropriate issue (WORDSNET-8647) and you will be notified as soon as this feature is supported. Sorry for the inconvenience.

Best regards,
Hi,

Regarding WORDSNET-9589, our development team has completed the work on this issue and has come to a conclusion that this issue and the undesired behaviour you're observing is actually not a bug in Aspose.Words. So, we will close this issue as 'Not a Bug'.

To fix this issue, please supply the "DateTime" in tag in the following format:

<ins cite="RadEditorUser" datetime="2014-01-31T19:10:50Z">Added some content</ins>

Best regards,

The issues you have found earlier (filed as WORDSNET-8647) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(1)