<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: conduct2024</title>
    <description>The latest articles on Forem by conduct2024 (@conduct2024).</description>
    <link>https://forem.com/conduct2024</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1445726%2F51f51a43-ffe8-42c2-8a00-566565f0b291.png</url>
      <title>Forem: conduct2024</title>
      <link>https://forem.com/conduct2024</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/conduct2024"/>
    <language>en</language>
    <item>
      <title>Couldn’t get equations in html when convert word .docx file to html file in C#.</title>
      <dc:creator>conduct2024</dc:creator>
      <pubDate>Wed, 24 Apr 2024 04:48:50 +0000</pubDate>
      <link>https://forem.com/conduct2024/couldnt-get-equations-in-html-when-convert-word-docx-file-to-html-file-in-c-4j5</link>
      <guid>https://forem.com/conduct2024/couldnt-get-equations-in-html-when-convert-word-docx-file-to-html-file-in-c-4j5</guid>
      <description>&lt;p&gt;I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.&lt;br&gt;
At the time of converting from word file to html my equations which are in the word document file was convert into image.&lt;/p&gt;

&lt;p&gt;`Globals.ThisAddIn.Application.ActiveDocument.Select();&lt;br&gt;
Microsoft.Office.Interop.Word.Document doc = Globals.ThisAddIn.Application.ActiveDocument;&lt;/p&gt;

&lt;p&gt;string result = Path.GetTempPath();&lt;/p&gt;

&lt;p&gt;string tmpFileName = Globals.ThisAddIn.Application.ActiveDocument.FullName;&lt;br&gt;
doc.SaveEncoding = Microsoft.Office.Core.MsoEncoding.msoEncodingUSASCII;&lt;br&gt;
if (File.Exists(result + "temp.html"))&lt;br&gt;
{&lt;br&gt;
    File.Delete(result + "temp.html");&lt;br&gt;
}&lt;br&gt;
doc.SaveAs(result + "temp.html", WdSaveFormat.wdFormatFilteredHTML); &lt;/p&gt;

&lt;p&gt;doc.Close(Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges);&lt;/p&gt;

&lt;p&gt;HtmlAgilityPack.HtmlDocument mangledHTML = new HtmlAgilityPack.HtmlDocument();&lt;br&gt;
mangledHTML.Load(result + "temp.html");&lt;/p&gt;

&lt;p&gt;if (File.Exists(result + "newtemp.html"))&lt;br&gt;
{&lt;br&gt;
    File.Delete(result + "newtemp.html");&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;mangledHTML.Save(result + "newtemp.html");&lt;br&gt;
// Remove standalone CRLF&lt;/p&gt;

&lt;p&gt;string badHTML = File.ReadAllText(result + "newtemp.html");&lt;br&gt;
badHTML = badHTML.Replace("\r\n\r\n", "ackThbbtt ");&lt;br&gt;
badHTML = badHTML.Replace("\r\n", " ");&lt;br&gt;
badHTML = badHTML.Replace("ackThbbtt ", "\r\n");&lt;br&gt;
badHTML = badHTML.Replace('�', ' ');&lt;br&gt;
if (File.Exists(result + "finaltemp.html"))&lt;br&gt;
{&lt;br&gt;
    File.Delete(result + "finaltemp.html");&lt;br&gt;
}&lt;br&gt;
File.WriteAllText(result + "finaltemp.html", badHTML);&lt;/p&gt;

&lt;p&gt;// Clean up temp files, show the finished result in Notepad&lt;br&gt;
File.Delete(result + "temp.html");&lt;br&gt;
File.Delete(result + "newtemp.html");&lt;/p&gt;

&lt;p&gt;Microsoft.Office.Interop.Word.Document orignalDoc = new Document();&lt;br&gt;
orignalDoc = Globals.ThisAddIn.Application.Documents.Open(tmpFileName);`&lt;/p&gt;

&lt;p&gt;Basically, what I want to do is I want to store all word document paragraph data separately in database and I also want it’s all property like font size, font width, font name and font style. So that I can show it in my application as it is as I written in word document file.&lt;br&gt;
To represent it as it is I need to convert it html format and the by sepreting all paragraphs I can store it in database. But when in my word document has paragraph which have equations then &lt;/p&gt;

&lt;p&gt;`Globals.ThisAddIn.Application.ActiveDocument.Select();&lt;br&gt;
Microsoft.Office.Interop.Word.Document doc = Globals.ThisAddIn.Application.ActiveDocument;&lt;/p&gt;

&lt;p&gt;string result = Path.GetTempPath();&lt;/p&gt;

&lt;p&gt;string tmpFileName = Globals.ThisAddIn.Application.ActiveDocument.FullName;&lt;br&gt;
doc.SaveEncoding = Microsoft.Office.Core.MsoEncoding.msoEncodingUSASCII;`&lt;/p&gt;

&lt;p&gt;This code converts my word documents all equations in Images and as it convert in image I can’t show the equation properly in my application.&lt;br&gt;
So I tried to convert this equations in MATHML form but I couldn’t solve this.&lt;/p&gt;

</description>
      <category>csharp</category>
      <category>dotnet</category>
      <category>html</category>
      <category>coding</category>
    </item>
  </channel>
</rss>
