色婷婷狠狠18禁久久YY,CHINESE性内射高清国产,国产女人18毛片水真多1,国产AV在线观看

請問如何將word轉化為HTML

李中冰2年前25瀏覽0評論

請問如何將word轉化為HTML?

頁面代碼:

[html] view plaincopy

Choose File

C#代碼:

[csharp] view plaincopy

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.IO;

protected void Page_Load(object sender, EventArgs e)

{

}

///

/// 將word轉換為Html

///

///

///

protected void btnConvert_Click(object sender, EventArgs e)

{

try

{

//上傳

//uploadWord(File1);

//轉換

wordToHtml(File1);

}

catch (Exception ex)

{

throw ex;

}

finally

{

Response.Write("恭喜,轉換成功!");

}

}

//上傳文件并轉換為html wordToHtml(wordFilePath)

///

///上傳文件并轉存為html

///

///word文檔在客戶機的位置

///上傳的html文件的地址

public string wordToHtml(System.Web.UI.HtmlControls.HtmlInputFile wordFilePath)

{

Microsoft.Office.Interop.Word.ApplicationClass word = new Microsoft.Office.Interop.Word.ApplicationClass();

Type wordType = word.GetType();

Microsoft.Office.Interop.Word.Documents docs = word.Documents;

// 打開文件

Type docsType = docs.GetType();

//應當先把文件上傳至服務器然后再解析文件為html

string filePath = uploadWord(wordFilePath);

//判斷是否上傳文件成功

if (filePath == "0")

return "0";

//判斷是否為word文件

if (filePath == "1")

return "1";

object fileName = filePath;

Microsoft.Office.Interop.Word.Document doc = (Microsoft.Office.Interop.Word.Document)docsType.InvokeMember("Open",

System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] { fileName, true, true });

// 轉換格式,另存為html

Type docType = doc.GetType();

string filename = System.DateTime.Now.Year.ToString() + System.DateTime.Now.Month.ToString() + System.DateTime.Now.Day.ToString() +

System.DateTime.Now.Hour.ToString() + System.DateTime.Now.Minute.ToString() + System.DateTime.Now.Second.ToString();

// 判斷指定目錄下是否存在文件夾,如果不存在,則創建

if (!Directory.Exists(Server.MapPath("~\\html")))

{

// 創建up文件夾

Directory.CreateDirectory(Server.MapPath("~\\html"));

}

//被轉換的html文檔保存的位置

string ConfigPath = HttpContext.Current.Server.MapPath("html/" + filename + ".html");

object saveFileName = ConfigPath;

/*下面是Microsoft Word 9 Object Library的寫法,如果是10,可能寫成:

* docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod,

* null, doc, new object[]{saveFileName, Word.WdSaveFormat.wdFormatFilteredHTML});

* 其它格式:

* wdFormatHTML

* wdFormatDocument

* wdFormatDOSText

* wdFormatDOSTextLineBreaks

* wdFormatEncodedText

* wdFormatRTF

* wdFormatTemplate

* wdFormatText

* wdFormatTextLineBreaks

* wdFormatUnicodeText

*/

docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod,

null, doc, new object[] { saveFileName, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatFilteredHTML });

//關閉文檔

docType.InvokeMember("Close", System.Reflection.BindingFlags.InvokeMethod,

null, doc, new object[] { null, null, null });

// 退出 Word

wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, word, null);

//轉到新生成的頁面

return ("/" + filename + ".html");

}

public string uploadWord(System.Web.UI.HtmlControls.HtmlInputFile uploadFiles)

{

if (uploadFiles.PostedFile != null)

{

string fileName = uploadFiles.PostedFile.FileName;

int extendNameIndex = fileName.LastIndexOf(".");

string extendName = fileName.Substring(extendNameIndex);

string newName = "";

try

{

//驗證是否為word格式

if (extendName == ".doc" || extendName == ".docx")

{

DateTime now = DateTime.Now;

newName = now.DayOfYear.ToString() + uploadFiles.PostedFile.ContentLength.ToString();

// 判斷指定目錄下是否存在文件夾,如果不存在,則創建

if (!Directory.Exists(Server.MapPath("~\\wordTmp")))

{

// 創建up文件夾

Directory.CreateDirectory(Server.MapPath("~\\wordTmp"));

}

//上傳路徑 指當前上傳頁面的同一級的目錄下面的wordTmp路徑

uploadFiles.PostedFile.SaveAs(System.Web.HttpContext.Current.Server.MapPath("wordTmp/" + newName + extendName));

}

else

{

return "1";

}

}

catch

{

return "0";

}

//return "http://" + HttpContext.Current.Request.Url.Host + HttpContext.Current.Request.ApplicationPath + "/wordTmp/" + newName + extendName;

return System.Web.HttpContext.Current.Server.MapPath("wordTmp/" + newName + extendName);

}

else

{

return "0";

}

}

css 網頁load效果,請問如何將word轉化為HTML