本文目录一览:

后缀为mht的文件能转换为word文档么

MHT格式文件是WEB档案,单一文件。

先把你需要的内容选中,或在“编辑”中选“全选”。再单击右键,然后点一下“复制”,再在桌面(或在其它路径)创建一个word文档。然后打开这个文档,把刚才复制就行了。

的东东粘贴到word文档上(如果是选“全选”,则要把你不需要的东东用退格键删掉)。然后再把你需要修改的东东修改一下,然后在WORD文档中“文件”中选中“另存为”,然后选择“文件类型”里面的word文档(.doc),再点一下“保存”

如何把mht文件中的图片一起拷贝到word文档

这个是无法直接复制粘贴过去的。

可以使用QQ截图,先把文字都复制过去,QQ截图后粘贴到word就可以了。

如何将mht转成word格式

第一步,先制作了一个很简单的html模板。将动态内容用诸如“$htmldata[1]”来代替,等取出数据后用Replace函数进行替换。

!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""

html xmlns=""

head

meta http-equiv="Content-Type" content="text/html; charset=utf-8" /

title$htmldata[1]/title

style type="text/css"

* {

margin:0px;

padding:0px;

}

.article_s{

width:980px;

height:auto;

overflow:hidden;

margin:0 auto;

}

.article_s_t_f{

width:960px;

height:auto;

line-height: 30px;

font-size: 18px;

padding-top: 10px;

text-align: center;

font-weight:700;

margin:0 auto;

}

.article_s_t_s{

width:960px;

line-height: 30px;

text-align: center;

font-size: 13px;

border-bottom:1px dashed #CCC;

margin:0 auto;

}

.article_s_l{

width:960px;

margin:0 auto;

line-height:28px;

font-size:14px;

padding:10px 0px 10px 0px;

}

.article_s_c{

width:960px;

height:23px;

text-align:center;

margin-bottom:20px;

}

/style

/head

body

div class="article_s"

div class="article_s_t_f"$htmldata[2]/div

div class="article_s_t_s"$htmldata[3]/div

div class="article_s_l"

$htmldata[4]

/div

/div

/body

/html

第二步:

建立一个静态类,代码如下:

public class Function

{

static Function() { }

//根据html生成mht文件,需要引入相应的dll,如图所示

public static void HtmlToMht(string src, string dst)

{

CDO.Message msg = new CDO.MessageClass();

CDO.Configuration c = new CDO.ConfigurationClass();

msg.Configuration = c;

msg.CreateMHTMLBody(src, CDO.CdoMHTMLFlags.cdoSuppressNone, "", "");

ADODB.Stream stream = msg.GetStream();

stream.SaveToFile(dst, ADODB.SaveOptionsEnum.adSaveCreateOverWrite);

}

public static void WriteHtml(string name,string content,string addTime,string hits,stringuser)//参数内容都是从数据库读出来的文章信息,其中content就是ewebeditor生成的html代码

{

DateTime dt = DateTime.Parse(addTime);//将string型的日期格式转为DateTime型的因为默认的日期格式不能作为文件名,所以将日期的“:”替换为“-”

string Temp_Name = @"D:/Application/Visual Studio 2010/Projects/富文本转Word/富文本转Word/temp/Articles.html";//HTML模板的路径

string File_Name = @"D:/Application/Visual Studio 2010/Projects/富文本转Word/富文本转Word/html/【" + dt.ToShortDateString().Replace("/","-") +"】" +name + ".html";//生成html文件的路径

string File_NameM = @"D:/Application/Visual Studio 2010/Projects/富文本转Word/富文本转Word/html/【" + dt.ToShortDateString().Replace("/","-") +"】" +name + ".mht";//生成mht文件的路径

string File_Name2 = @"D:/Application/Visual Studio 2010/Projects/富文本转Word/富文本转Word/html/【" + dt.ToShortDateString().Replace("/", "-") + "】" + name + ".doc";//生成Word文档的路径

StreamReader sr = new StreamReader(Temp_Name);

StringBuilder htmltext = new StringBuilder();

String line;

while ((line = sr.ReadLine()) != null)

{

htmltext.Append(line);//读取到html模板的内容

}

sr.Close();

//替换相应的内容到指定的位置

htmltext = htmltext.Replace("$htmldata[1]", name);

htmltext = htmltext.Replace("$htmldata[2]", name);

htmltext = htmltext.Replace("$htmldata[3]", ("点击数:" + hits + " 发布时间:" + addTime + "  发布者:" + user));

htmltext = htmltext.Replace("$htmldata[4]", content);

using (StreamWriter sw = new StreamWriter(File_Name, false, System.Text.Encoding.GetEncoding("UTF-8"))) //保存地址

{

//生成HTML文件

sw.WriteLine(htmltext);

sw.Flush();

sw.Close();

}

HtmlToMht(File_Name, File_NameM);//因为带图片的html直接转为Word的话,图片会以引用的形式展示(也就是说不是内置到word文档里去的,一旦断网或将图片放在别的路径之后,打开word文档图片会显示不出来,所以通过折冲的办法先生成html,然后转换为mht,再转为word)

WordAction.SaveAsWord(File_NameM, File_Name2);//生成word

}

}

建立另外一个操作word 的静态类,代码如下(代码都是拷的O(∩_∩)O):

public class WordAction

{

public static void SaveAsWord(string fileName, string pFileName)//使用原生方法将mht转换为word文档,不是那种直接修改后缀名的方式

{

object missing = System.Reflection.Missing.Value;

object readOnly = false;

object isVisible = true;

object file1 = fileName;

object html1 = pFileName;

object format = WdSaveFormat.wdFormatDocument;

ApplicationClass oWordApp = new ApplicationClass();

oWordApp.Visible = false;

Document oWordDoc = oWordApp.Documents.Open(ref   file1, ref   format, ref  readOnly,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);

oWordApp.ActiveWindow.View.Type = Microsoft.Office.Interop.Word.WdViewType.wdPrintView;//将web视图修改为默认视图,不然打开word的时候会以web视图去展示,而不是默认视图。(唯独这句代码是自己加的 = =|||)

oWordDoc.SaveAs(ref   html1, ref   format, 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);

oWordDoc.Close(ref     missing, ref     missing, ref     missing);

oWordDoc = null;

oWordApp.Application.Quit(ref   missing, ref   missing, ref   missing);

oWordApp = null;

killAllProcess();

}

protected static void killAllProcess() // 杀掉所有winword.exe进程

{

System.Diagnostics.Process[] myPs;

myPs = System.Diagnostics.Process.GetProcesses();

foreach (System.Diagnostics.Process p in myPs)

{

if (p.Id != 0)

{

string myS = "WINWORD.EXE" + p.ProcessName + "  ID:" + p.Id.ToString();

try

{

if (p.Modules != null)

if (p.Modules.Count 0)

{

System.Diagnostics.ProcessModule pm = p.Modules[0];

myS += "/n Modules[0].FileName:" + pm.FileName;

myS += "/n Modules[0].ModuleName:" + pm.ModuleName;

myS += "/n Modules[0].FileVersionInfo:/n" + pm.FileVersionInfo.ToString();

if (pm.ModuleName.ToLower() == "winword.exe")

p.Kill();

}

}

catch

{ }

finally

{

}

}

}

}

}

第三步:

随便建了个aspx页面,写上以下代码。

string title = "";

string postuser = "";

string content = "";

string addTime = "";

string hits = "";

DataTable dt = CatalogAccess.GetArticles();//从数据库取出自己需要的数据

for (int i = 0; i dt.Rows.Count; i++)

{

DataRow dr = dt.Rows[i];

title = dr["Title"].ToString();

postuser = dr["PostUser"].ToString();

addTime = dr["AddTime"].ToString();

hits = dr["Hits"].ToString();

content = dr["Content"].ToString();

content = content.Replace("src=/"/new/Editor/uploadfile/", "src=/"files/");//替换图片文件的引用目录,这个动作是非必要的,因为我把图片都下载到本地了,所以替换一下里面引用的图片路径,只要根据模板生成的html能正常显示图片就可以了

Function.WriteHtml(title, content, addTime, hits, postuser);//生成word文档

}

}

好了,大功告成啦。当然生成的word文档跟网页存在一点差别,在接受的范围内。

怎么把表格内容转成word文档

打开要复制的excel文档。

请点击输入图片描述

点击左上角的圆形按钮,在展开的选项中选择 另存为--其他格式

请点击输入图片描述

然后在打开的另存为界面,保存类型选择 单个文件网页(*.mht;*.mhtml)

请点击输入图片描述

接着在新界面上,保存 选项那选择工作表的那个选项,如下图红色框起来的地方。然后点击右下角的【保存】按钮。

请点击输入图片描述

系统弹出“发布为网页”的对话框,在 选择 的框那选择好后,点击【发布】按钮。就会生成一个page.mht的文件。

请点击输入图片描述

在page.mht的文件右键,选择打开方式--Microsoft Office Word。然后就会用word打开刚才的这个文件。

请点击输入图片描述

打开之后,选择左上角的圆形按钮 另存为--Word 97-2003文档

请点击输入图片描述

在另存为界面,就可以选择要保存word的路径,及其文件名。最后点击【保存】按钮。这样就可以把excel文档完整的转为word文档。

请点击输入图片描述

怎么把表格转换为word文档

方法如下:

1,打开要转换的excel表格,然后点击“文件”→“另存为web页”。web页就是网页文件,在“保存选项”处把“保存整个工作簿”调整成“选择:工作表”,把默认文件名"Page.mht ”根据实际情况改成你所需要的名字,再点击“保存”。注意,在改名时绝对不可以把后面的.mht去掉,只要改“.”前面的部分就可以了。

2,此时在桌面上便有一个文档,右键单击该文档,选择“打开方式”,在下拉列表中选择“Microsoft Office Word”,打开该文档,如下图所示,一个完美的word文档就呈现啦!

我要把MHT文件格式转换成WORD文件要怎么弄。

打开mht文件,然后选文件,另存为,html格式,然后用word打开这个html文件