问题描述
就是读不出来啊。。。。。word控件导入的问题usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingAxDSOFramer;usingSystem.IO;namespaceRMS_Reader.Reader{classcOfficeReader:iReader{privateAxFramerControloffice=newAxFramerControl();privatebyte[]officeStream=null;privateFileInfoinfo=newFileInfo();//文档信息FileStreamfs;#regioniDocumentsMemberspublicSystem.Windows.Forms.ControlGetReaderControl(){returnoffice;}publicboolInitReader(){//office.Toolbars=false;office.MenuAccelerators=false;office.Menubar=false;office.Titlebar=false;returntrue;}publicboolOpenFile(stringfilePath){//加载文件try{office.Open(filePath);office.Activate();}catch{returnfalse;}//获取文档信息info.fileType=System.IO.Path.GetExtension(filePath);info.filePath=filePath;returntrue;}publicboolSave(){try{office.Save();}catch{returnfalse;}returntrue;}publicvoidSaveAs(stringfilePath){GetFileContent();//打开文件FileStreamofs=newFileStream(filePath,FileMode.Create);//保存文件ofs.Seek(0,SeekOrigin.Begin);//Movefilepointertobeginningoffile.ofs.Write(officeStream,0,officeStream.Length);ofs.Close();}publicvoidPrint(){thrownewNotImplementedException();}publicvoidClose(){if(office!=null){//尝试关闭officetry{office.Save();office.Close();}catch{}}if(fs!=null)fs.Close();}publicFileInfoGetFileInfo(){returninfo;}publicbyte[]GetFileContent(){//关闭OfficeClose();//打开文档,获取内容fs=newFileStream(info.filePath,FileMode.Open);//文件流//读取文件内容if(null==officeStream)officeStream=newbyte[fs.Length];fs.Read(officeStream,0,(int)fs.Length);fs.Close();//打开OfficeOpenFile(info.filePath);returnofficeStream;}publicvoidSetReaderProperties(uintproperties){//thrownewNotImplementedException();}#endregion}}求各位大哥救救小弟。。。。。。。。。。。诚心拜拜
解决方案
解决方案二:
用這個啊
解决方案三:
前提:导入COM库:Microsoftword11.0ObjectLibrary.引用里面就增加了:创建新WordobjectoMissing=System.Reflection.Missing.Value;Word._ApplicationoWord;Word._DocumentoDoc;oWord=newWord.Application();oWord.Visible=true;oDoc=oWord.Documents.Add(refoMissing,refoMissing,refoMissing,refoMissing);打开文档:objectoMissing=System.Reflection.Missing.Value;Word._ApplicationoWord;Word._DocumentoDoc;oWord=newWord.Application();oWord.Visible=true;objectfileName=@"E:CCCXCXXTestDoc.doc";oDoc=oWord.Documents.Open(reffileName,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing);导入模板objectoMissing=System.Reflection.Missing.Value;Word._ApplicationoWord;Word._DocumentoDoc;oWord=newWord.Application();oWord.Visible=true;objectfileName=@"E:XXXCCXTest.doc";oDoc=oWord.Documents.Add(reffileName,refoMissing,refoMissing,refoMissing);.添加新表objectoMissing=System.Reflection.Missing.Value;Word._ApplicationoWord;Word._DocumentoDoc;oWord=newWord.Application();oWord.Visible=true;oDoc=oWord.Documents.Add(refoMissing,refoMissing,refoMissing,refoMissing);objectstart=0;objectend=0;Word.RangetableLocation=oDoc.Range(refstart,refend);oDoc.Tables.Add(tableLocation,3,4,refoMissing,refoMissing);.表插入行objectoMissing=System.Reflection.Missing.Value;Word._ApplicationoWord;Word._DocumentoDoc;oWord=newWord.Application();oWord.Visible=true;oDoc=oWord.Documents.Add(refoMissing,refoMissing,refoMissing,refoMissing);objectstart=0;objectend=0;Word.RangetableLocation=oDoc.Range(refstart,refend);oDoc.Tables.Add(tableLocation,3,4,refoMissing,refoMissing);Word.TablenewTable=oDoc.Tables[1];objectbeforeRow=newTable.Rows[1];newTable.Rows.Add(refbeforeRow);.单元格合并objectoMissing=System.Reflection.Missing.Value;Word._ApplicationoWord;Word._DocumentoDoc;oWord=newWord.Application();oWord.Visible=true;oDoc=oWord.Documents.Add(refoMissing,refoMissing,refoMissing,refoMissing);objectstart=0;objectend=0;Word.RangetableLocation=oDoc.Range(refstart,refend);oDoc.Tables.Add(tableLocation,3,4,refoMissing,refoMissing);Word.TablenewTable=oDoc.Tables[1];objectbeforeRow=newTable.Rows[1];newTable.Rows.Add(refbeforeRow);Word.Cellcell=newTable.Cell(1,1);cell.Merge(newTable.Cell(1,2));.单元格分离objectoMissing=System.Reflection.Missing.Value;Word._ApplicationoWord;Word._DocumentoDoc;oWord=newWord.Application();oWord.Visible=true;oDoc=oWord.Documents.Add(refoMissing,refoMissing,refoMissing);objectstart=0;objectend=0;Word.RangetableLocation=oDoc.Range(refstart,refend);oDoc.Tables.Add(tableLocation,3,4,refoMissing,refoMissing);Word.TablenewTable=oDoc.Tables[1];objectbeforeRow=newTable.Rows[1];newTable.Rows.Add(refbeforeRow);Word.Cellcell=newTable.Cell(1,1);cell.Merge(newTable.Cell(1,2));objectRownum=2;objectColumnnum=2;cell.Split(refRownum,refColumnnum);通过段落控制插入objectoMissing=System.Reflection.Missing.Value;objectoEndOfDoc="endofdoc";/**//*endofdocisapredefinedbookmark*///StartWordandcreateanewdocument.Word._ApplicationoWord;Word._DocumentoDoc;oWord=newWord.Application();oWord.Visible=true;oDoc=oWord.Documents.Add(refoMissing,refoMissing,refoMissing,refoMissing);//Insertaparagraphatthebeginningofthedocument.Word.ParagraphoPara1;oPara1=oDoc.Content.Paragraphs.Add(refoMissing);oPara1.Range.Text="Heading1";oPara1.Range.Font.Bold=1;oPara1.Format.SpaceAfter=24;//24ptspacingafterparagraph.oPara1.Range.InsertParagraphAfter();赞同18|评论(3)
解决方案四:
Microsoftword11.0ObjectLibrary不是對應各個版本office,還是用我說的那個吧,,,,,,,呵呵呵呵呵額呵呵呵呵
解决方案五:
这个控件能直接返回control类吗?。。。。我比较菜。。。还有大哥你那个下不到呀
解决方案六:
引用3楼的回复:
Microsoftword11.0ObjectLibrary不是對應各個版本office,還是用我說的那個吧,,,,,,,呵呵呵呵呵額呵呵呵呵
这个控件能直接返回control类吗?。。。。我比较菜。。。还有大哥你那个下不到呀