欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JavaScript打開word文檔的實(shí)現(xiàn)代碼(c#)

 更新時(shí)間:2012年04月16日 13:08:20   作者:  
在C#中打開word文檔其實(shí)不算太難,方法也比較多,用javascript怎么打開呢?其實(shí),也不難
在C#中打開word文檔其實(shí)不算太難,方法也比較多。
一.C#中打開word文檔方法
復(fù)制代碼 代碼如下:

//在項(xiàng)目引用里添加上對(duì)Microsoft Word 11.0 object library的引用
private void button1_Click(object sender, System.EventArgs e)
{
//調(diào)用打開文件對(duì)話框獲取要打開的文件WORD文件,RTF文件,文本文件路徑名稱
OpenFileDialog opd = new OpenFileDialog();
opd.InitialDirectory = \"c:\\\\\";
opd.Filter = \"Word文檔(*.doc)|*.doc|文本文檔(*.txt)|*.txt|RTF文檔(*.rtf)|*.rtf|所有文檔(*.*)|*.*\";
opd.FilterIndex = 1;
if (opd.ShowDialog() == DialogResult.OK && opd.FileName.Length > 0)
{
//建立Word類的實(shí)例,缺點(diǎn):不能正確讀取表格,圖片等等的顯示
Word.ApplicationClass app = new Word.ApplicationClass();
Word.Document doc = null;
object missing = System.Reflection.Missing.Value;
object FileName = opd.FileName;
object readOnly = false;
object isVisible = true;
object index = 0;
try
{
doc = app.Documents.Open(ref FileName, ref missing, 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);
doc.ActiveWindow.Selection.WholeStory();
doc.ActiveWindow.Selection.Copy();
//從剪切板獲取數(shù)據(jù)
IDataObject data=Clipboard.GetDataObject();
this.richTextBox1.Text=data.GetData(DataFormats.Text).ToString();
}
finally
{
if (doc != null)
{
doc.Close(ref missing, ref missing, ref missing);
doc = null;
}
if (app != null)
{
app.Quit(ref missing, ref missing, ref missing);
app = null;[Page]
}
}
}
}

但是,如果我們?cè)趺从胘avascript怎么打開呢?其實(shí),也不難。
二.在javascript打開word文檔
我們新建一個(gè)html文件,并且寫一個(gè)FileUpLoad以及button控件。
復(fù)制代碼 代碼如下:

<input id="flUpload" type="file" />flUpload
<input id="btnOpenFile" type="button" value="button" onclick="OpenFile()" />

然后,在寫一個(gè)javascript OpenFile方法。
復(fù)制代碼 代碼如下:

function OpenFile()
{
if (document.getElementById("flUpload").value.toUpperCase().indexOf(".XLS") != -1)
{
var objExcel;
objExcel = new ActiveXObject("Excel.Application");
objExcel.Visible = true;
objExcel.Workbooks.Open(document.getElementById("flUpload").value);
}
else if (document.getElementById("flUpload").value.toUpperCase().indexOf(".DOC") != -1)
{
var objDoc;
objDoc = new ActiveXObject("Word.Application");
objDoc.Visible = true;
objDoc.Documents.Open(document.getElementById("flUpload").value);
}
else
{
alert("Please select Word/Excel file only");
return false;
}
}

OK。然后 在IE中就能先選入一個(gè)doc文檔,然后點(diǎn)open,就可以打開了。
希望對(duì)你有幫助。
呵呵!~。

相關(guān)文章

最新評(píng)論