Free Support Forum - aspose.com

Problem while convering HTML Table to Word using Aspose words

Hi,

We are using Aspose.Words.dll (trial version) version 10.0.0.0 for converting

  1. Word to HTML (using Aspose)
  2. Apply some styles (in the generated HTML) which does not affect the table in the document
  3. Again convert HTML to word file (using Aspose)

We are facing problem while converting some table having colspan and rowspan defined in HTML.

PFA:

  1. "InputDoc.docx" file that we are taking as input
  2. "generateword.doc" file that is output file

We have to fix this issue asap so your quick help on this will be appreciated.

Thanks,

Samanvay

Hi

Thanks for your inquiry. How can I reproduce this problem on my side? Could you please provide me the code which will allow me to reproduce the problem on my side?

Best regards,

Hi,

Please find below the code that we have used for genrating html for "InputDoc.docx" (contains table with row and col span). We are using licence version of aspose dll

HtmlSaveOptions saveOptions = new HtmlSaveOptions();

Aspose.Words.Document doc = new Aspose.Words.Document(C:\\InputDoc.Docx);

MemoryStream htmlStream = new MemoryStream();

doc.Save(htmlStream, saveOptions);

string htmlText = Encoding.UTF8.GetString(htmlStream.GetBuffer());

htmlStream.Close();

After genrating html we applied external css for some formatting.Then we are converting this html to word doc using below code

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

builder.InsertHtml(htmlStream);

string outputFile = Server.MapPath(C:\generateword.doc);

doc.Save(outputFile);

Thanks,

Samanvay

Hello

Thank you for additional information. Could you please also provide your external CSS and describe the way how can I apply this CSS to reproduce the problem on my side?

Best regards,

hi

I think it is not problem of external css.

Please find the below code that we are using for genrating word doc using html

StringBuilder lSbTemp = new StringBuilder();

lSbTemp.Append(" ");

strHTML = lSbTemp.ToString() + strHTML;

builder.InsertHtml(strHTML);

css style:

body

{

font-family:Arial;

}

h1

{

font-family:Arial;

color:red;

text-transform: uppercase;

font-size:13pt;

}

h2

{

font-family:Arial;

color:green;

text-transform: uppercase;

font-size:11pt;

font-style:normal;

}

h3

{

font-family:Arial;

color:#616365;

text-transform: uppercase;

font-size:10pt;

}

h4

{

font-family:Arial;

color:#000000;

font-size:10pt;

font-style:normal;

}

h5

{

font-family:Arial;

color:#000000;

text-transform: uppercase;

font-size:8pt;

}

a

{

font-family:Arial;

font-size:10pt;

}

Thanks

Samanvay

Hello

Thank you for additional information. I think in this case, you should reapply a style for each Heading paragraph. Please see the following code:

Document doc = new Document("C:\\Temp\\InputDoc.docx");

MemoryStream htmlStream = new MemoryStream();

HtmlSaveOptions saveOptions = new HtmlSaveOptions();

doc.Save(htmlStream, saveOptions);

string htmlText = Encoding.UTF8.GetString(htmlStream.GetBuffer());

htmlStream.Close();

StringBuilder lSbTemp = new StringBuilder();

lSbTemp.Append(" ");

htmlText = lSbTemp.ToString() + htmlText;

// Get bytes from string

byte[] htmlBytes = Encoding.UTF8.GetBytes(htmlText);

// Create memory stream

MemoryStream newHtmlStream = new MemoryStream(htmlBytes);

// Create document

Document outDoc = new Document(newHtmlStream);

foreach (Paragraph paragraph in outDoc.GetChildNodes(NodeType.Paragraph, true))

{

switch (paragraph.ParagraphFormat.StyleIdentifier)

{

case StyleIdentifier.Heading1:

case StyleIdentifier.Heading2:

case StyleIdentifier.Heading3:

case StyleIdentifier.Heading4:

case StyleIdentifier.Heading5:

case StyleIdentifier.Heading6:

case StyleIdentifier.Heading7:

case StyleIdentifier.Heading8:

case StyleIdentifier.Heading9:

Style currentStyle = paragraph.ParagraphFormat.Style;

paragraph.ParagraphFormat.ClearFormatting();

foreach (Run run in paragraph.GetChildNodes(NodeType.Run, true))

run.Font.ClearFormatting();

paragraph.ParagraphFormat.Style = currentStyle;

break;

default:

// do nothing.

break;

}

}

outDoc.Save("C:\\Temp\\out.docx");

Best regards,

Hi,

Thanks for your suggestion. I think the solution you provided here is for paragraph heading and we are facing problem in table with colspan and rowspan while generating word from HTML. I think the input files we have provided are sufficient for reproducing the issue.

Please let us know if you need any futher information.

Thanks,

samanvay

Hello

Thanks for your inquiry. As I can see the problem with table occurs just in case of using DOC format. Your request has been linked to the appropriate issue. You will be notified as soon as it is fixed. Currently, as a workaround, you can try using DOCX format.

Best regards,

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


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