Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 18th, 2005, 02:31 AM
Registered User
 
Join Date: May 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help me please aboutVS 2003 and Office 2003

Why does it cannot work?Could you tell me the mistake?

Thanks you very much :)

using System;
using System.Windows.Forms;
using Office = Microsoft.Office.Core;
using Excel = Microsoft.Office.Interop.Excel;
using System.Data;
using System.Diagnostics;
using System.Xml.Serialization;
using System.Web.Services.Protocols;
using System.Web.Services;
using MSForms = Microsoft.Vbe.Interop.Forms;

// Office integration attribute. Identifies the startup class for the workbook. Do not modify.
[assembly:System.ComponentModel.DescriptionAttribut e("OfficeStartupClass, Version=1.0, Class=Excel_ja.BondCalculation")]

namespace Excel_ja
{
    /// <summary>
    /// Contains managed code extensions for the workbook.
    /// </summary>
    ///

    [System.Web.Services.WebServiceBindingAttribute(
         Name="BondCalculationSoap",
         Namespace="urn:BondCalculation")]

    public class BondCalculation : System.Web.Services.Protocols.SoapHttpClientProtoc ol
    {
        /// <summary>
        /// Application object.
        /// </summary>
        ///



        internal Excel.Application ThisApplication
        {
            get { return thisApplication;}
        }

        /// <summary>
        /// Workbook object.
        /// </summary>
        internal Excel.Workbook ThisWorkbook
        {
            get { return thisWorkbook;}
        }

        private Excel.Application thisApplication = null;
        private Excel.Workbook thisWorkbook = null;
        private MSForms.CommandButton button;
        private Excel.Worksheet ws;

        private Excel.WorkbookEvents_OpenEventHandler openEvent;
        private Excel.WorkbookEvents_BeforeCloseEventHandler beforeCloseEvent;

        #region Generated initialization code

        /// <summary>
        /// Default constructor.
        /// </summary>


        /// <summary>
        /// Required procedure. Do not modify.
        /// </summary>
        /// <param name="application">Application object.</param>
        /// <param name="workbook">Workbook object.</param>
        public void _Startup(object application, object workbook)
        {
            this.thisApplication = application as Excel.Application;
            this.thisWorkbook = workbook as Excel.Workbook;

            openEvent= new Excel.WorkbookEvents_OpenEventHandler (ThisWorkbook_Open);
            thisWorkbook.Open += openEvent;

            beforeCloseEvent = new Excel.WorkbookEvents_BeforeCloseEventHandler(ThisW orkbook_BeforeClose);
            thisWorkbook.BeforeClose += beforeCloseEvent;
        }

        /// <summary>
        /// Required procedure. Do not modify.
        /// </summary>
        public void _Shutdown()
        {
            thisApplication = null;
            thisWorkbook = null;
        }

        /// <summary>
        /// Finds the control with the specified name in the active worksheet.
        /// </summary>
        /// <param name='name'>Name of the control to find.</param>
        /// <returns>
        /// Returns the specified control, or null if it is not found.
        /// </returns>
        object FindControl(string name )
        {
            return FindControl(name, (Excel.Worksheet) ThisWorkbook.ActiveSheet);
        }

        /// <summary>
        /// Returns the control with the specified name in the specified worksheet.
        /// </summary>
        /// <param name='name'>Name of the control to find.</param>
        /// <param name='sheet'>Worksheet object that contains the control.</param>
        /// <returns>
        /// Returns the specified control, or null if it is not found.
        /// </returns>
        object FindControl(string name, Excel.Worksheet sheet )
        {
            Excel.OLEObject theObject;
            try
            {
                theObject = (Excel.OLEObject) sheet.OLEObjects(name);
                return theObject.Object;
            }
            catch
            {
                // Returns null if the control is not found.
            }
            return null;
        }

        #endregion

        /// <summary>
        /// Called when the workbook is opened.
        /// </summary>
        ///

        public BondCalculation()
        {
            this.Url = "http://192.168.10.74/bondserv_test/pricingservice.asmx";
        }

        [System.Web.Services.Protocols.SoapDocumentMethodAt tribute(
             "urn:BondCalculation/calcPriceByYTM",
             RequestNamespace="urn:BondCalculation",
             ResponseNamespace="urn:BondCalculation",
             Use=System.Web.Services.Description.SoapBindingUse .Literal,
             ParameterStyle=System.Web.Services.Protocols.SoapP arameterStyle.Wrapped)]

        public string calcPriceByYTM(string name)
        {
            object[] results = this.Invoke("calcPriceByYTM",
                new object[] {"LB22NA",3,DateTime.Now.Date,DateTime.Now.Date });

            return ((string)(results[0]));
        }

        protected void ThisWorkbook_Open()
        {
            this.button = (MSForms.CommandButton) this.FindControl("button");
            this.button.Click +=new MSForms.CommandButtonEvents_ClickEventHandler(butt on_Click);

            if (this.button != null)
            {
                this.button.Click += new
                    MSForms.CommandButtonEvents_ClickEventHandler(
                    button_Click);
            }

            Excel.Worksheet ws = (Excel.Worksheet) ThisApplication.Sheets.get_Item(1);
            Excel.Range rng = ws.get_Range ("D1" , "H1");
            rng.Value2 = "Hello, ****ing Excel";

            ws.Cells.AutoFit();
            ws.Cells.AddComment("Nash");

            ThisApplication.get_Range("A1","G2").Calculate();

            show();

            //InitSheet ( );

            Ex();

            MSForms.CommandButton button1 = (MSForms.CommandButton) FindControl("button1");
            button1.Click += new Microsoft.Vbe.Interop.Forms.CommandButtonEvents_Cl ickEventHandler
                                    (button1_Click);

        }

        /// <summary>
        /// Called before the workbook is closed. Note that this method
        /// might be called multiple times and the value assigned to Cancel
        /// might be ignored if other code or the user intervenes.
        /// </summary>
        /// <param name="Cancel">False when the event occurs. If the event procedure
        /// sets this to true, the document does not close when the procedure is finished.
        /// </param>
        protected void ThisWorkbook_BeforeClose(ref bool Cancel)
        {
            Cancel = false;
        }


        private void show()
        {
            Console.WriteLine("Calling the SOAP Server to say hello");
// BondCalculation BondCalculation = new BondCalculation();
// Console.WriteLine("The SOAP Server says: "+BondCalculation.calcPriceByYTM("siwaporn"));
        }
        private void button_Click()
        {
            show();
        }

        private void button1_Click()
        {
            Excel.Worksheet sheet = (Excel.Worksheet) ThisApplication.Sheets.get_Item(1);
            Excel.Range rng = sheet.get_Range ( "A1", "D1" );
            rng.Value2 = "Hi What the hell is going on";

        }

        protected void Ex()
        {
            Excel.Worksheet ws=new Excel.WorksheetClass();
            ws = (Excel.Worksheet)ThisApplication.ActiveWorkbook.Ac tiveSheet;
            for(int i=1;i<11;i++)
            {
                for(int j=1;j<11;j++)
                {
                    ws.Cells[i,j]=i;
                }
            }
        }

        private void InitSheet ( )
        {
            Excel.Range rng;

            for ( int i = 1 ; i < 30; i ++ )
            {
                rng = (Excel.Range)ws.Rows[i,"nash"];
                rng.RowHeight = 10;
            }

            for ( int j = 1 ; j < 30; j ++ )
            {
                rng = (Excel.Range)ws.Columns[j,"Nash"];
                rng.ColumnWidth = 1;
            }
        }


    }
}


 
Old May 18th, 2005, 08:29 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Please provide us with the error message or specific problem you are encountering. We aren't here to proofread code.

-Peter
 
Old May 18th, 2005, 11:58 PM
Registered User
 
Join Date: May 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

No error message , this code can debug but it can't work with excel
I can't find solution this problem
please help me
thank you very much






Similar Threads
Thread Thread Starter Forum Replies Last Post
Office 2003 absolute minimum w/VSTO? cjkoontz Visual Studio 2005 0 October 16th, 2008 10:36 AM
Customizing MS OFFICE 2003 using C#.NET pradpb999 General .NET 0 December 27th, 2005 01:11 AM
XMLHttprequest::Send hangs after office 2003 inst vijuma C# 0 October 17th, 2005 12:53 AM
XMLHttprequest::Send hangs after office 2003 inst vijuma XML 0 October 14th, 2005 01:48 AM
-2147024770 VBA Office 2003 josemariagomes Access VBA 8 March 29th, 2005 08:47 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.