咔片PPT · AI自动生成演示文稿,模板丰富、排版精美 讯飞智文 · 一键生成PPT和Word,高效应对学习与办公

内容导航:


一、word文件怎么转换成htm文件


解决办法,试试
一、替换格式法
就是把损坏的Word文档存为另一种格式。
1、打开被损坏的文档单击“文件/另存为”菜单,在“保存类型”列表中,选择“RTF格式”,然后单击“保存”按钮,并关闭Word。
2、打开刚才保存的RTF格式文件,再次使用“另存为”将文件重新保存为“Word文档”,现在打开这个Word文件就可以发现文件已经被恢复过来了。
如果在转换成rtf格式后文件仍然不能被恢复,可以将文件再次转换为纯文本格式(*.txt),再转换回Word格式。当然在转换为txt文件的时候其图片等信息会丢失掉。
二、删除格式信息法
Word文档的最后一个段落符号记录着全篇文档的格式信息,有时删除这些格式信息就可以恢复变成乱码的文件。
1、在打开损坏的文档后,单击“工具/选项”菜单,选择“编辑”标签,取消对“使用智能段落选择范围”复选框的勾选,然后单击按钮。这样就可以修复文件了。
2、选定最后一个段落符之外的全部内容,然后将这些内容粘贴复制到新的Word文件中即可。


二、如何将HTML格式转化为word


1、打开浏览器搜索关键词,选择合适的转换工具,然后点击下载安装到电脑。

2、安装完成后,点击回到桌面打开PDF转换器,进入主页面,浏览一下软件功能。

3、解决的是如何将PDF转换为HTML格式,点击选择PDF文件转换打来,会发现它分为好几个小类目,点击文件转换HTML。

4、接着就可以添加文件了,点击添加文件按钮,也可以直接拖拽PDF文件到转换列表内。

5、文件添加成功后,在页面顶端设置文件保存路径,选择点击原文件或自定义。

6、选中转换的文件,在文件后面有全部字样,打开它可以设置文件内转换的页码范围,文件过多的需要进行批量操作,完成后点击开始转换。



三、如何将mht转成word格式


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

http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

http://www.w3.org/1999/xhtml">

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

$htmldata[1]

<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>

$htmldata[2]
$htmldata[3]

$htmldata[4]

第二步:

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

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:ApplicationVisual Studio 2010Projects富文本转Word富文本转WordtempArticles.html";//HTML模板的路径

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

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

string File_Name2 = @"D:ApplicationVisual Studio 2010Projects富文本转Word富文本转Wordhtml【" + 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文档跟网页存在一点差别,在接受的范围内。