I need your help again. Please help me.
I am trying to use C#NET2008 and Microsoft WORD 2003 to develop Window Application to print the Sales Transaction statement. But it not working.
This coding create the error message list below
objWord = new Microsoft.Office.Interop.Word.Words(); <--- Error
Error Message:
Error 1 Cannot create an instance of the abstract class or interface 'Microsoft.Office.Interop.Word.Words'
Here are the coding:
using Microsoft.Office.Core; using Microsoft.Office; using Microsoft.Office.Interop.Word; namespace CSharpDelegatePractice { public partial class FrmCustomerMaint : Form { private Microsoft.Office.Interop.Word.Words objWord; private Microsoft.Office.Interop.Word.Document objDoc; private void WordToolStripMenuItem_Click(object sender, EventArgs e) { string strsql = "Select * from TblSales where SalesID = " + txtSalesID objWord = new Microsoft.Office.Interop.Word.Words(); <--- Error objDoc = new Microsoft.Office.Interop.Word.Document(); } } }
Please help me. Thank You.
Cheers,
Lennie
Lennie KuahPosted Oct 10, 2010, 9:47 PM
Thank you for the URL address. Apparently the articles is referring to C#NET2003 and not C#NET2008. I did follow the instruction to use WORD Object on my C#NET2008 and it created error messages because C#NET2008 does not have this command:
Error message
Error 2 No overload for method 'AddOLEObject' takes '9' arguments
// Insert a chart
Word.InlineShape objShape;
object objclassType = "MSGraph.Chart.8";
objTblRange = objDoc.Bookmarks.get_Item(ref objEndOfDoc).Range;
objShape = objTblRange.InlineShapes.AddOLEObject(ref objclassType, ref objMissing,refobjMissing, ref objMissing, ref objMissing,
ref objMissing, ref objMissing, ref objMissing, ref objMissing );
--------------------------------------------------------------------------
Error 3 The name 'BindingFlags' does not exist in the current context
//demonstrate use of Late bound chart and oChartAoo objects to
//manipulate the chart object with MSGraph.
object objChart;
object objChartApp;
objChart = objShape.OLEFormat.Object;
objChartApp = objChart.GetType().InvokeMember("Application", BindingFlags.GetProperty,null, objChart, null);
//change the chart type to Line.
object[] Parameters = new object[1];
Parameters[0] = 4; //xlLine = 4
objChart.GetType().InvokeMember("ChartType", BindFlags.SetsProperty, null, objChart, Parameters);
//update the chart image and quit MSGraph.
objChartApp.GetType().InvokeMember("Update", BindingFlags.InvokeMethod, null, objChartApp, null);
objChartApp.GetType().InvokeMember("Quit", BindingFlags.InvokeMethod, null, objChartApp, null);
Suthish NairPosted Oct 10, 2010, 4:15 AM
Can you explain what you trying to do, exporting output to word file?
Also, always Parameterized Query instead of ( = " + txtSalesID)
Word automation using C#:
http://www.c-sharpcorner.com/UploadFile/amrish_deep/WordAutomation05102007223934PM/WordAutomation.aspx