在.aspx页面中以HTML格式显示word文档 [英] Displaying word document in HTML format in .aspx page

查看:82
本文介绍了在.aspx页面中以HTML格式显示word文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我在.aspx页面中以HTML格式显示word文档,但嵌入式HTML文件将space替换为?特殊性格。



如何删除特殊字符?



这是我用过的代码您的参考:



Hi,

I have displayed word document in HTML format in .aspx page, but the embedded HTML file replaces "space" as "?" special character.

How can I remove the special character?

Here is the code I used for your reference:

try
            {
                //To check the file extension if it is word document or something else
                string strFileName = fUpload.FileName;
                string[] strSep = fUpload.FileName.Split('.');
                int arrLength = strSep.Length - 1;
                string strExt = strSep[arrLength].ToString().ToUpper();
                //Save the uploaded file to the folder
                strPathToUpload = Server.MapPath("Uploaded");
                //Map-path to the folder where html to be saved
                strPathToConvert = Server.MapPath("WordToHtml");
                object FileName = strPathToUpload + "\\" + fUpload.FileName;
                object FileToSave = strPathToConvert + "\\" + fUpload.FileName + ".htm";
                if (strExt.ToUpper().Equals("DOC"))
                {
                    fUpload.SaveAs(strPathToUpload + "\\" + fUpload.FileName);
                    lblMessage.Text = "File uploaded successfully";
                    //open the file internally in word. In the method all the parameters should be passed by object reference
                    objWord.Documents.Open(ref FileName, ref readOnly, ref missing, ref missing, ref missing, ref missing,
                    ref missing, ref  missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing,
                    ref missing, ref missing);
                    //Do the background activity
                    objWord.Visible = false;
                    Microsoft.Office.Interop.Word.Document oDoc = objWord.ActiveDocument;
                    oDoc.SaveAs(ref FileToSave, ref fltDocFormat, ref missing, ref missing, ref missing, ref missing,
                    ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
                    ref missing, ref missing);
                    lblMessage.Text = fUpload.FileName + " converted to HTML successfully";

                }
                else
                {
                    lblMessage.Text = "Invalid file selected!";
                }
                //Close/quit word
                objWord.Quit(ref missing, ref missing, ref missing);

                string[] strHtml = System.IO.Directory.GetFiles(strPathToConvert);
                Response.ContentType = "text/html";
                Response.WriteFile(strHtml[0]);



你能帮帮我吗这个。



提前致谢。


Can you please help me out in this.

Thanks in advance.

推荐答案

尝试添加 charset = utf-8 ContentType

Try adding charset=utf-8 to ContentType.
Response.ContentType = "text/html;charset=utf-8";


这篇关于在.aspx页面中以HTML格式显示word文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆