Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Apr 08, 2010 10:00 AM by hiral.hapani
Member
61 Points
59 Posts
Apr 08, 2010 08:10 AM|LINK
hi friends.. how can we convert html pages to ms word??/
XmlSerializer web
Contributor
2408 Points
629 Posts
Apr 08, 2010 09:15 AM|LINK
Hi check this
http://support.microsoft.com/kb/819398
http://forums.asp.net/t/1526275.aspx
http://forums.asp.net/t/1224223.aspx
Participant
1046 Points
206 Posts
Apr 08, 2010 10:00 AM|LINK
Hello
Below is code for your query.
string Wordstring = ""; int stsrt = body.IndexOf("<body>"); int lastindex = body.IndexOf("</body>"); int last = lastindex - stsrt;
Wordstring = body.Substring(stsrt + 6, last - 6); //int length = filename.LastIndexOf(".pdf"); string wordfilename = obj_letter[i].debt_id + "_" + letterid.ToString();
#region MS WORD
System.Text.StringBuilder strBody = new System.Text.StringBuilder(""); string HeaderPath = string.Empty; /*if (System.IO.File.Exists(Server.MapPath("~") + "/DocumentRepository/" + BAL.AgentSection.Common.PageBase.GetCurrentAgencyName() + "/Letters/Headers/" + hdnHeaderFileName.Value)) { HeaderPath = System.Configuration.ConfigurationManager.AppSettings["Livepath"].ToString() + "/DocumentRepository/" + GetCurrentAgencyName() + "/Letters/Headers/" + hdnHeaderFileName.Value; }*/
strBody.Append("<html " + "xmlns:v='urn:schemas-microsoft-com:vml'" + "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><title>Letter</title>"); //The setting specifies document's view after it is downloaded as Print //instead of the default Web Layout strBody.Append("<!--[if gte mso 9]>" + "<xml>" + "<w:WordDocument>" + "<w:View>Print</w:View>" + "<w:Zoom>100</w:Zoom>" + "<w:DoNotOptimizeForBrowser/>" + "</w:WordDocument>" + "</xml>" + "<![endif]-->"); strBody.Append("<style>" + "<!-- /* Style Definitions */" + "p.MsoHeader, li.MsoHeader, div.MsoHeader" + "{mso-style-noshow:yes;" + "mso-style-priority:99;" + "mso-style-link:'Header Char';" + "margin:0in;" + "margin-bottom:.0001pt;" + "mso-pagination:widow-orphan;" + "tab-stops:center 3.25in right 6.5in;" + "font-size:11.0pt;" + "font-family:'Calibri','sans-serif';" + "mso-ascii-font-family:Calibri;" + "mso-ascii-theme-font:minor-latin;" + "mso-fareast-font-family:Calibri;" + "mso-fareast-theme-font:minor-latin;" + "mso-hansi-font-family:Calibri;" + "mso-hansi-theme-font:minor-latin;" + "mso-bidi-font-family:'Times New Roman';" + "mso-bidi-theme-font:minor-bidi;}"); if (!string.IsNullOrEmpty(HeaderPath)) { strBody.Append(" @page Section1" + " {size:8.5in 11.0in; " + " margin:0.5in 1.0in 0.5in 1.0in ; " + " mso-header-margin:.1in; " + " mso-header:url('" + HeaderPath + "') h1;" + " mso-footer-margin:.1in; mso-paper-source:0;}" + " div.Section1" + " {page:Section1;}" + "-->" + "</style></head>"); } else { strBody.Append(" @page Section1" + " {size:8.5in 11.0in; " + " margin:1in 0.5in 0.5in 1.0in ; " + " mso-header-margin:.1in; " + " mso-footer-margin:.1in; mso-paper-source:0;}" + " div.Section1" + " {page:Section1;}" + "-->" + "</style></head>"); }
strBody.Append("<body lang=EN-US style='tab-interval:.5in'>" + Wordstring.ToString()/*.Replace("> ", ">")*/ + "</body></html>");
#endregion
#region Write Word file ........
FileInfo file1 = new FileInfo(Server.MapPath("~") + "/Client/LetterPdf/" + wordfilename + ".doc"); if (file1.Exists) { try { if (file1.IsReadOnly) { file1.IsReadOnly = false; } file1.Delete(); } catch (Exception ex) {
} } using (StreamWriter debugWriter = new StreamWriter(file1.Open(FileMode.Create, FileAccess.Write, FileShare.ReadWrite))) { debugWriter.Write(strBody); debugWriter.Flush(); debugWriter.Dispose(); debugWriter.Close(); } file.Refresh();
skalyanchakr...
Member
61 Points
59 Posts
HTML to MS Word
Apr 08, 2010 08:10 AM|LINK
hi friends.. how can we convert html pages to ms word??/
XmlSerializer web
------------------------
Please Mark This As Answer, If It Helps You
Vijaya.A
Contributor
2408 Points
629 Posts
Re: HTML to MS Word
Apr 08, 2010 09:15 AM|LINK
Hi check this
http://support.microsoft.com/kb/819398
http://forums.asp.net/t/1526275.aspx
http://forums.asp.net/t/1224223.aspx
hiral.hapani
Participant
1046 Points
206 Posts
Re: HTML to MS Word
Apr 08, 2010 10:00 AM|LINK
Hello
Below is code for your query.
string Wordstring = "";
int stsrt = body.IndexOf("<body>");
int lastindex = body.IndexOf("</body>");
int last = lastindex - stsrt;
Wordstring = body.Substring(stsrt + 6, last - 6);
//int length = filename.LastIndexOf(".pdf");
string wordfilename = obj_letter[i].debt_id + "_" + letterid.ToString();
#region MS WORD
System.Text.StringBuilder strBody = new System.Text.StringBuilder("");
string HeaderPath = string.Empty;
/*if (System.IO.File.Exists(Server.MapPath("~") + "/DocumentRepository/" + BAL.AgentSection.Common.PageBase.GetCurrentAgencyName() + "/Letters/Headers/" + hdnHeaderFileName.Value))
{
HeaderPath = System.Configuration.ConfigurationManager.AppSettings["Livepath"].ToString() + "/DocumentRepository/" + GetCurrentAgencyName() + "/Letters/Headers/" + hdnHeaderFileName.Value;
}*/
strBody.Append("<html " +
"xmlns:v='urn:schemas-microsoft-com:vml'" +
"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><title>Letter</title>");
//The setting specifies document's view after it is downloaded as Print
//instead of the default Web Layout
strBody.Append("<!--[if gte mso 9]>" +
"<xml>" +
"<w:WordDocument>" +
"<w:View>Print</w:View>" +
"<w:Zoom>100</w:Zoom>" +
"<w:DoNotOptimizeForBrowser/>" +
"</w:WordDocument>" +
"</xml>" +
"<![endif]-->");
strBody.Append("<style>" +
"<!-- /* Style Definitions */" +
"p.MsoHeader, li.MsoHeader, div.MsoHeader" +
"{mso-style-noshow:yes;" +
"mso-style-priority:99;" +
"mso-style-link:'Header Char';" +
"margin:0in;" +
"margin-bottom:.0001pt;" +
"mso-pagination:widow-orphan;" +
"tab-stops:center 3.25in right 6.5in;" +
"font-size:11.0pt;" +
"font-family:'Calibri','sans-serif';" +
"mso-ascii-font-family:Calibri;" +
"mso-ascii-theme-font:minor-latin;" +
"mso-fareast-font-family:Calibri;" +
"mso-fareast-theme-font:minor-latin;" +
"mso-hansi-font-family:Calibri;" +
"mso-hansi-theme-font:minor-latin;" +
"mso-bidi-font-family:'Times New Roman';" +
"mso-bidi-theme-font:minor-bidi;}");
if (!string.IsNullOrEmpty(HeaderPath))
{
strBody.Append(" @page Section1" +
" {size:8.5in 11.0in; " +
" margin:0.5in 1.0in 0.5in 1.0in ; " +
" mso-header-margin:.1in; " +
" mso-header:url('" + HeaderPath + "') h1;" +
" mso-footer-margin:.1in; mso-paper-source:0;}" +
" div.Section1" +
" {page:Section1;}" +
"-->" +
"</style></head>");
}
else
{
strBody.Append(" @page Section1" +
" {size:8.5in 11.0in; " +
" margin:1in 0.5in 0.5in 1.0in ; " +
" mso-header-margin:.1in; " +
" mso-footer-margin:.1in; mso-paper-source:0;}" +
" div.Section1" +
" {page:Section1;}" +
"-->" +
"</style></head>");
}
strBody.Append("<body lang=EN-US style='tab-interval:.5in'>" +
Wordstring.ToString()/*.Replace("> ", ">")*/ +
"</body></html>");
#endregion
#region Write Word file ........
FileInfo file1 = new FileInfo(Server.MapPath("~") + "/Client/LetterPdf/" + wordfilename + ".doc");
if (file1.Exists)
{
try
{
if (file1.IsReadOnly)
{
file1.IsReadOnly = false;
}
file1.Delete();
}
catch (Exception ex)
{
}
}
using (StreamWriter debugWriter = new
StreamWriter(file1.Open(FileMode.Create, FileAccess.Write,
FileShare.ReadWrite)))
{
debugWriter.Write(strBody);
debugWriter.Flush();
debugWriter.Dispose();
debugWriter.Close();
}
file.Refresh();
Hiral Hapani
'Action of Today Becomes Destiny of Tomorrow.'