最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

//在項目引用里添加上對Microsoft Word 11.0 object library的引用
private void button1_Click(object sender, System.EventArgs e)
{
//調(diào)用打開文件對話框獲取要打開的文件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類的實例,缺點:不能正確讀取表格,圖片等等的顯示
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]
}
}
}
}

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

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

然后,在寫一個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中就能先選入一個doc文檔,然后點open,就可以打開了。
希望對你有幫助。
呵呵!~。

相關(guān)文章

最新評論

兴文县| 栾川县| 长岭县| 汨罗市| 上虞市| 镶黄旗| 林甸县| 油尖旺区| 横山县| 余姚市| 张北县| 灌阳县| 海淀区| 阜康市| 珲春市| 曲阜市| 桃园市| 榆林市| 务川| 青阳县| 兖州市| 鄂尔多斯市| 闽侯县| 伊春市| 济宁市| 翁牛特旗| 施秉县| 漳浦县| 维西| 汪清县| 津市市| 宁明县| 佛山市| 霞浦县| 龙陵县| 安泽县| 天长市| 中卫市| 邵武市| 灵璧县| 青浦区|