C # after Microsoft. Office. Core is referenced in the projectMicrosoft. Office. Core. msotristate, Still error:
Error 1 type"Microsoft. Office. Core. msotristate"InCentralized definition of referenced programs. You must add a reference to the assembly "office, version = 12.0.0.0, culture = neutral, publickeytoken = 71e9bce111e9429c. C:/documents and
Error 2: Microsoft. Office. InterOP. PowerPoint. Presentations. Open (string,Microsoft. Office. Core. msotristate,Microsoft. Office. Core. msotristate,Microsoft. Office. Core. msotristate) "The Most matched overload method has some invalid parameters.
Error 3 parameter "2": cannot start from"Microsoft. Office. Core. msotristate[C:/Documents and Settings/Administrator/My Documents/Visual Studio 2008/projects/pptpaser/classlibrary1/obj/debug/InterOP. microsoft. office. core. DLL] "to"Microsoft. Office. Core. msotristate[]"
After several hours of struggle, I still cannot solve the problem. Hope you can give me some advice and I am very grateful. I will give you more points!
I wrote an article on csdn for the first time.
This is because I want to build a project to extract PPT texts. I first came into contact with office development.
The following is the source code:
View plaincopy to clipboardprint?
··· · 50 ······· · 90 ····· · 140 · 150
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Using PowerPoint = Microsoft. Office. InterOP. PowerPoint;
Using Microsoft. Office. core;
Using system. runtime. interopservices;
Namespace consoleapplication1
{
Public class Program
{
Public static void main (string [] ARGs)
{
String filename = "F: // test.ppt ";
Program. parse (filename );
}
Public static void parse (string filename)
{
Try
{
PowerPoint. Application Pa = new Powerpoint. applicationclass ();
PowerPoint. Presentation pp = pa. Presentations. Open (filename,
Microsoft. Office. Core. msotristate. Msotrue,
Microsoft. Office. Core. msotristate. Msofalse,
Microsoft. Office. Core. msotristate. Msofalse );
Console. writeline ("Open success ");
PowerPoint. textframe frame;
String text;
Foreach (PowerPoint. slide in pp. slides)
{
Foreach (PowerPoint. Shape shape in slide. SHAPES)
{
If (shape. hastextframe =Microsoft. Office. Core. msotristate. Msotrue)
{
Frame = shape. textframe;
If (frame. hastext =Microsoft. Office. Core. msotristate. Msotrue)
{
TEXT = frame. textrange. text;
Console. writeline (text );
}
}
}
}
}
Catch (exception E)
{
Console. writeline (E. Message );
}
}
}
}
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Using PowerPoint = Microsoft. Office. InterOP. PowerPoint;
Using Microsoft. Office. core;
Using system. runtime. interopservices;
Namespace consoleapplication1
{
Public class Program
{
Public static void main (string [] ARGs)
{
String filename = "F: // test.ppt ";
Program. parse (filename );
}
Public static void parse (string filename)
{
Try
{
PowerPoint. Application Pa = new Powerpoint. applicationclass ();
PowerPoint. Presentation pp = pa. Presentations. Open (filename,
Microsoft. Office. Core. msotristate. Msotrue,
Microsoft. Office. Core. msotristate. Msofalse,
Microsoft. Office. Core. msotristate. Msofalse );
Console. writeline ("Open success ");
PowerPoint. textframe frame;
String text;
Foreach (PowerPoint. slide in pp. slides)
{
Foreach (PowerPoint. Shape shape in slide. SHAPES)
{
If (shape. hastextframe =Microsoft. Office. Core. msotristate. Msotrue)
{
Frame = shape. textframe;
If (frame. hastext =Microsoft. Office. Core. msotristate. Msotrue)
{
TEXT = frame. textrange. text;
Console. writeline (text );
}
}
}
}
}
Catch (exception E)
{
Console. writeline (E. Message );
}
}
}
}
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"InCentralized definition of referenced programs. 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"Also 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.