开发者

What's the problem in this statement?

开发者 https://www.devze.com 2023-01-19 07:36 出处:网络
I am writing a sample application to convert a DOC file into a PDF. While doing this I\'m getting an error.

I am writing a sample application to convert a DOC file into a PDF. While doing this I'm getting an error.

// Creating the instance of WordApplication
MSDOC = new Microsoft.Office.Interop.Word.ApplicationClass();
try
{
    MSDOC.Visible = false;
    MSDOC.Documents.Op开发者_开发百科en(ref Source, ref Unknown,
     ref Unknown, ref Unknown, ref Unknown,
     ref Unknown, ref Unknown, ref Unknown,
     ref Unknown, ref Unknown, ref Unknown,
     ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown);
    MSDOC.Application.Visible = false;
    MSDOC.WindowState = Microsoft.Office.Interop.Word
                                 .WdWindowState.wdWindowStateMaximize;
    object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF;
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message, "Message from Sample");
}

And this is the statement I am getting an error at:

object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF;

Error Interop type 'Microsoft.Office.Interop.Word.ApplicationClass' cannot be embedded. Use the applicable interface instead.


Have you tried doing what the error message suggests? Replace

MSDOC = new Microsoft.Office.Interop.Word.ApplicationClass();

with

Microsoft.Office.Interop.Word.Application MSDOC;
MSDOC = new Microsoft.Office.Interop.Word.Application();


Try MSDOC = new Microsoft.Office.Interop.Word.Application(); instead of .ApplicationClass().


if you don't need custom word applicaton event handling, do as recommended by 0xA3 otherwise leave ApplicationClass as is but go to the project's reference: select the MIcrosoft.Office.Interop.Word, properties, and change embedded form Ture to False Be sure to add office.dll from office 2003 or it's PIA

0

精彩评论

暂无评论...
验证码 换一张
取 消