I wrote an article on csdn for the first time.
Because you need to createExtract ppt textProject, first contact with office development.
The following is the source code:
Using system; <br/> using system. collections. generic; <br/> using system. LINQ; <br/> using system. text; <br/> using PowerPoint = Microsoft. office. interOP. powerPoint; <br/> using Microsoft. office. core; <br/> using system. runtime. interopservices; <br/> namespace consoleapplication1 <br/>{< br/> public class Program <br/>{< br/> Public static void main (string [] ARGs) <br/>{< br/> string filename = "F: // test.ppt"; <br/> program. parse (filename); <br/>}< br/> Public static void parse (string filename) <br/>{< br/> try <br/>{< br/> PowerPoint. application Pa = new Powerpoint. applicationclass (); </P> <p> PowerPoint. presentation pp = pa. presentations. open (filename, <br/> Microsoft. office. core. msotristate. msotrue, <br/> Microsoft. office. core. msotristate. msofalse, <br/> Microsoft. office. core. msotristate. msofalse); <br/> console. writeline ("Open success"); <br/> PowerPoint. textframe frame; <br/> string text; <br/> foreach (Powerpoint. slide in pp. slides) <br/>{< br/> foreach (Powerpoint. shape shape in slide. shapes) <br/>{</P> <p> If (shape. hastextframe = Microsoft. office. core. msotristate. msotrue) <br/>{< br/> frame = shape. textframe; <br/> If (frame. hastext = Microsoft. office. core. msotristate. msotrue) <br/>{</P> <p> text = frame. textrange. text; <br/> console. writeline (text); <br/>}< br/> catch (exception E) <br/> {<br/> console. writeline (E. message); <br/>}< br/>
The code is quite simple, but adding references wastes my effort for half a day.
The first step is to change the installation of office2003. For more information, see msdn
Http://msdn.microsoft.com/zh-cn/library/aa159923 (office.11). aspx # ehaa
In this way, the following content will appear in your reference (of course, it may have been available before, and you do not need to change the office2003 installation)
(1). Net contains Microsoft. Office. InterOP. PowerPoint and office
(2) Microsoft. Office 11.0 (or 12.0) Object Library in COM
Microsoft. Office. InterOP. PowerPoint must be added.
But who does the Office and Microsoft. Office 11.0 (or 12.0) Object Library add?
Only adding an Office is sufficient!
Practice has proved that,
(1) If you only add Microsoft. Office 11.0 (or 12.0) Object Library, the following error occurs:
Error 1 type "Microsoft. Office. Core. msotristate" is defined in the unreferenced assembly. You must add a reference to the assembly "office, version = 12.0.0.0, culture = neutral, publickeytoken = 71e9bce111e9429c ".
(2) If both office and Microsoft. Office 11.0 (or 12.0) Object Library are added, the following error occurs:
Error 1 type "Microsoft. office. core. msotristate exists in "E:/program files/Microsoft Visual Studio 9.0/Visual Studio Tools for office/Pia/office12/office. DLL and C:/Documents and Settings/Administrator/My Documents/Visual Studio 2008/projects/pptpaser/consoleapplication1/obj/debug/InterOP. microsoft. office. core. DLL"
The reason is that msotristate appears in both DLL.
Correct practice: only add Office Reference
This problem took me a lot of time to solve, so I wrote this article specially and hoped that programmers who encountered the same problem could solve it as soon as possible.
The addition of COM components and. NET components is not clear yet. I hope you can advise me.