I was assigned the task of making a “small” modification to an existing C++/CLI (with Excel automation) application (target framework: .NET4.0, IDE: VS2010). The task: insert a couple of pictures (*.jpg) into an Excel worksheet. I was pleased to find here at stackoverflow a thread in which precisely this task was addressed in C#. Here is the link: please see the very end of this question
In the above thread, I followed the instructions provided in the answer from user JMK. The code compiles without errors and works! Indeed, the code successfully places a picture in the worksheet. Unfortunately, I also obtain one hundred C4691 compiler warnings.
My code:
//attributes - used by several different methods
private:
Excel::Application^ xlApp;
Excel::_Workbook^ xlBook;
Excel::Workbooks^ xlBooks;
Excel::Sheets^ xlSheets;
Excel::_Worksheet^ xlSheet;
Excel::Range^ range;
String^ templateFilename;
String^ picFilename;
private: System::Void buttonRunExcel_Click(System::Object^ sender, System::EventArgs^ e)
{
//create the Excel Application
xlApp = gcnew Excel::Application();//55 C4691 compiler warnings for this line of code
xlBooks = xlApp->Workbooks;//no compiler warnings here
//open the Excel template - 30 C4691 compiler warnings for the next line of code
xlBook = xlApp->Workbooks->Open(templateFilename, Type::Missing, false, Type::Missing, Type::Missing, Type::Missing, Type::Missing, Type::Missing, Type::Missing, Type::Missing, Type::Missing, Type::Missing, Type::Missing, Type::Missing, Type::Missing);
xlSheets = xlBook->Worksheets;//no compiler warnings here
//set the active worksheet to sheet 3
xlSheet = (Excel::_Worksheet^)xlSheets->Item[3];//no compiler warnings here
//insert the picture - 15 C4691 compiler warnings for the next line of code
xlSheet->Shapes->AddPicture(picFilename, Core::MsoTriState::msoFalse, Core::MsoTriState::msoCTrue, 100, 200, 640, 480);
}
My references:
using namespace System::Reflection;
using namespace System::Runtime::InteropServices;
using namespace Microsoft::Office::Core;
using namespace Microsoft::Office::Interop::Excel;
A sample compiler warning:
warning C4691: "Microsoft::Office::Core::Assistant": type referenced was expected in unreferenced assembly "office", type defined in current translation unit used instead. This diagnosis occurred while importing type 'Microsoft: Office:Interop:Excel:ApplicationClass' from Assembly "Microsoft.Office.Interop.Excel, Version = 12.0.0.0, culture = neutral, PublicKeyToken = 71e9bce111e9429c".
MSDN’s description of this compiler warning was not particularly helpful (for me). I don’t wish to simply ignore the warnings (foolish) nor do I want to “turn off” the warnings using pragma warning (sloppy).
How can I eliminate warning C4691? All advice, comments, even (constructive) criticism are gratefully appreciated. Thanks