c#获取word文件页数、字数
程序员文章站
2022-03-26 09:32:31
引用命名空间:using Microsoft.Office.Interop.Word; ......
引用命名空间:using microsoft.office.interop.word;
//启动word程序 application mywordapp = new applicationclass(); object omissing = missing.value; object nothing = missing.value; object filepath = "/upload/123.docx"; //这里是word文件的路径 filepath = server.mappath(filepath.tostring()); //word物理路径 //打开文件 document myworddoc = mywordapp.documents.open( ref filepath, ref omissing, ref omissing, ref omissing, ref omissing, ref omissing, ref omissing, ref omissing, ref omissing, ref omissing, ref omissing, ref omissing, ref omissing, ref omissing, ref omissing, ref omissing); //文件页数 int pagenum = myworddoc.computestatistics(wdstatistic.wdstatisticpages, ref nothing); //文件字数 int wordnum = myworddoc.characters.count; //关闭文件 myworddoc.close(ref omissing, ref omissing, ref omissing); //退出word程序 mywordapp.quit(ref nothing, ref nothing, ref nothing); response.write("文件页数:" + pagenum + "<br/>文件字数:" + wordnum);
下一篇: python基础学习笔记(一)