I am evaluating Aspose Word and have run into the following problem: When I use the InsertHtml method in DocumentBuilder, the font color is sometimes lost. The HTML was created from a Word document. I have attached the document file that the HTML is added to.
Thanks
Code:
public void InsertHTMLAtEnd(string fileName, string html, string outFileName)
{
FileStream inStream = File.OpenRead(fileName);
FileStream outStream = File.OpenWrite(outFileName);
try
{
Word word = new Word();
Document doc = word.Open(inStream);
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToDocumentEnd();
builder.InsertHtml(html);
doc.Save(outStream, SaveFormat.FormatDocument);
}
finally
{
if (inStream != null)
{
inStream.Close();
}
if (outStream != null)
{
outStream.Close();
}
}
}
HTML:
<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<meta name=ProgId content=Word.Document>
<meta name=Generator content="Microsoft Word 11">
<meta name=Originator content="Microsoft Word 11">
<link rel=File-List href="DataHTML_files/filelist.xml">
<title>This is an HTML file with some formatting</title>
<!--[if gte mso 9]><xml>
<o:DocumentProperties>
<o:Author>Jeff Seibel</o:Author>
<o:LastAuthor>Jeff Seibel</o:LastAuthor>
<o:Revision>2</o:Revision>
<o:TotalTime>4</o:TotalTime>
<o:Created>2005-10-24T17:31:00Z</o:Created>
<o:LastSaved>2005-10-24T17:31:00Z</o:LastSaved>
<o:Pages>1</o:Pages>
<o:Words>22</o:Words>
<o:Characters>127</o:Characters>
<o:Company>Virtual Radiologic Consultants</o:Company>
<o:Lines>1</o:Lines>
<o:Paragraphs>1</o:Paragraphs>
<o:CharactersWithSpaces>148</o:CharactersWithSpaces>
<o:Version>11.6408</o:Version>
</o:DocumentProperties>
</xml><![endif]-->
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:SpellingState>Clean</w:SpellingState>
<w:GrammarState>Clean</w:GrammarState>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
</w:WordDocument>
</xml><![endif]-->
<!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" LatentStyleCount="156">
</w:LatentStyles>
</xml><![endif]-->
<style>
<!--
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal {
mso-style-parent: "";
margin: 0in;
margin-bottom: .0001pt;
mso-pagination: widow-orphan;
font-size: 12.0pt;
font-family: "Times New Roman";
mso-fareast-font-family: "Times New Roman";
}
@page Section1 {
size: 8.5in 11.0in;
margin: 1.0in 1.25in 1.0in 1.25in;
mso-header-margin: .5in;
mso-footer-margin: .5in;
mso-paper-source: 0;
}
div.Section1 {
page: Section1;
}
-->
</style>
<!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
</style>
<![endif]-->
</head>
<body lang=EN-US style='tab-interval:.5in'>
<div class=Section1>
<p class=MsoNormal>This is an HTML file with some formatting.</p>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal>
<i style='mso-bidi-font-style:normal'>
<span style='color:#99CC00'>This is italic and green</span><span style='color:#339966'>.<o:p></o:p></span>
</i>
</p>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal>
<b style='mso-bidi-font-weight:normal'>
<span style='color:red'>This is bold and red</span>
</b>.
</p>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal><u><span style='color:#00CCFF'>This is underlined and blue.<o:p></o:p></span></u></p>
<p class=MsoNormal>
<u>
<span style='color:#00CCFF'>
<o:p>
<span style='text-decoration: none'> </span>
</o:p>
</span>
</u>
</p>
<p class=MsoNormal>
<u>
<span style='font-size:22.0pt;color:yellow'>
This is BIG
and yellow<o:p></o:p>
</span>
</u>
</p>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal><o:p> </o:p></p>
</div>
</body>
</html>