示例地址 代码下载其实很简单,就是用我上次说的那个使用c#打开word2007文档的的方法,用xslt格式化一下就可以了,不过,由于对ooxml格式不太了解,只分析了最简单的那几个标签,图片,表格等目前还不知道怎么格式化,有xslt高手可以指导一下,代码如下,在在页面加多一个xml控件就可以了,嘿嘿,居然还能通过w3 1static string savName = string.Empty; 2 3 4protected void button1_Click(object sender, EventArgs e) 5 { 6 7 if (FileUpload1.HasFile) 8 { 9 if (FileUpload1.PostedFile.ContentType == "application/vnd.openxmlformats-officedocument.wordprocessingml.document")10 {11 savName = Server.MapPath("/DocToDocx/" + FileUpload1.FileName);12 FileUpload1.SaveAs(savName);13 //有条件可以在服务器上安装office2007直接对2007以前的doc文档进行文档转换14 //ConvertToDocx();15 DispPlayOnWeb();16 }17 else18 {19 Response.Write("对不起,只能上传office2007以docx为后缀的文件");20 }21 }22 }2324 //void ConvertToDocx()25 //{26 // object fileName = savName;27 // object missing = Type.Missing;28 // object isFalse = false;29 // object isTrue = true;30 // MSWord.ApplicationClass wordApp = new Microsoft.Office.Interop.Word.ApplicationClass();31 // wordApp.Visible = false;32 // MSWord.Document wordDocument = wordApp.Documents.Open(33 // ref fileName,//文件名称34 // ref isFalse,//如果文件有错误是否提示转换,我们在服务器运行,出现也看不到,就不用出现提示了35 // ref isFalse,//是否以只读形式打开,我们要对其转换,不能只读36 // ref isFalse,//是否增加到最精打开的文件37 // ref missing,38 // ref missing,39 // ref isFalse,40 // ref missing,41 // ref missing,42 // ref missing,43 // ref missing,44 // ref isFalse,45 // ref isTrue,46 // ref missing,47 // ref isFalse,48 // ref missing49 // );5051 // //直接使用其转换方法转换文档52 // wordDocument.Convert();5354 // wordDocument.Save();5556 // wordDocument.Close(ref missing, ref missing, ref missing);5758 // wordApp.Quit(ref missing, ref missing, ref missing);59 // wordApp = null;60 //}6162 void DispPlayOnWeb()63 {64 //string fileName = savName.Substring(0, savName.LastIndexOf('.')) + ".docx";65 using (Package package = Package.Open(savName, FileMode.Open, FileAccess.Read))66 {67 Uri docxUri = new Uri("/word/document.xml", UriKind.Relative);68 PackagePart docxPart = package.GetPart(docxUri);6970 XmlDocument docxXml = new XmlDocument();71 docxXml.Load(docxPart.GetStream());7273 Xml1.Document = docxXml;7475 package.Close();7677 File.Delete(savName);78 }798081 }
直接在网页上显示word2007文档
最新推荐文章于 2024-04-27 09:16:44 发布