Free Support Forum -

Render Aspose.Words docx in ReportViewer

I’m using Aspose.Words ( - Trial Version) to convert an HTML document (see attached input.txt) into a DOCX document (see attached output2.docx) using the following code:

void export_Click(object sender, EventArgs e)
Document doc = new Document(Server.MapPath("/input.html"));
doc.Save(Response, “output2.docx”, ContentDisposition.Inline, null);



protected void RemoveContentFromMergedCells(Document doc)

// Remove content from merged cells.
// Get collection of cells in the docuemnt.
NodeCollection cells = doc.GetChildNodes(NodeType.Cell, true);

foreach (Cell cell in cells)
// Check whether cell is merged with previouse.
if (cell.CellFormat.HorizontalMerge == CellMerge.Previous ||
cell.CellFormat.VerticalMerge == CellMerge.Previous)
// Remove content from the cell.

Everything get converted properly, but then when I try to take the DOCX document and render it with a ReportViewer control, I loose almost all of my formatting in the table (see attached screenshot.png), and get an error message with the nested list. The code I’m using to get the docx into the report viewer is as follows:

static byte[] RenderStatement(string text, ref ContentType cType)
byte[] renderContent;
cType = ContentType.None;

if (text.IsWordDoc())
//Rich text, generate HTML
ReportViewer rptViewer = new ReportViewer();
rptViewer.ServerReport.ReportServerUrl = new Uri(
rptViewer.ServerReport.ReportServerCredentials = new ReportServerCredentials();

//Load report definition
string fpath = Path.Combine(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath,
XDocument report = XDocument.Load(fpath);
RDLBuilder rbd = new RDLBuilder(report);

using (WordprocessingDocument wdoc = text.XDeSerialize())
MemoryStream ms = report.GetReportDefinition();

renderContent = rptViewer.RenderHTML();
//Success, set content type as HTML
cType = ContentType.HTML;
catch (ReportServerException ex)
renderContent = new ASCIIEncoding().GetBytes(String.Format(“Content rendering error: {0}”,
renderContent = new ASCIIEncoding().GetBytes(text);
cType = ContentType.Text;
return renderContent;

Is there anything I can do with the Aspose.Words library to make it more compatible with the ReportViewer control?


Thanks for your request. I do not thin that the problem is in Aspose.Words. I suppose ReportViewer renders is quite restricted. Have you tried converting your HTML to DOCX using MS Word and then render it in ReportViewver? Is it rendered properly?

Also, if I understand your requirements properly, you are using ReportViewver to show document preview. Right? If so, you can consider using SWF to achieve this. Aspose.Words allows converting documents to SWF files. SWF files produced by Aspose.Words alredy contains a simple document viewer UI.

Best regards,