User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C# section within the Software Development category of DaniWeb, a massive community of 392,318 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,852 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C# advertiser:
Views: 6656 | Replies: 3 | Solved
Join Date: Apr 2006
Posts: 87
Reputation: blacklocist is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 2
blacklocist blacklocist is offline Offline
Junior Poster in Training

Help Using Microsoft Excel 10.0 Libary Object -Dang .dlls

  #1  
Apr 18th, 2006
Hi All,
Well where I work they are having a problem and I had a solution. Well I was reading on this http://www.c-sharpcorner.com/UploadF...4-031b641aae3c

Well what it does is pull a named range, sticks the data in an array, my software does it's thing, then puts the changed data back into excel. I used the Office PIA and installed them and everything.

Several long nights, and much snaking I was done. I tested it and fixed some changes and it works beautiflully. I was so proud!!

Well I created a little setup packaged and started trying to install it on other machines. Well it installs prefectly but when I try to run the app a message box comes up and says in the title "Missing Reference", the message says "Please Reinstall Software'.

What?!? How can this be???? Well I did everything I know. Reinstalled it again and again, made sure the Office PIA were "registered" and installed. Made sure the .net framework was installed. Tried the install on several computers. Even installed VS.Net 2005 on another computer and when I open up the solution won't even build sucessfully.

So what it all boils down to is the app can only build and run on the original deveolper machines.

Here is the code, but the loops that I worked really hard on I deleted.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
//great for using missing.value;
using System.Reflection;
using Microsoft.Office.Core;
using System.Threading;
using System.IO;



namespace DeannaProj2
{
    public partial class Form1 : Form
    { 
        
        //declaring and object Called AppExcel
        private Excel.Application AppExcel = null;
       
        
        ArrayManipulator AM = new ArrayManipulator();

        string strSource = null;
        string strRowCount = null;
        public string [,] arrySingle = null;
               
      
        
        public Form1()
        {
            InitializeComponent();
        }


        //to take care of opening and picking the excel file
        private void btnExcel_Click(object sender, EventArgs e)
        {

            exceldata.ShowDialog();
            strSource = exceldata.FileName;
            lblSource.Text = strSource;

           
        }

        private void btnRow_Click(object sender, EventArgs e)
        {

            //to check to see if user has selected an excel file
            if (strSource == "")
            {
                MessageBox.Show("Please Pick An Excel File", "Error");
            }                                                         

            strRowCount = txtbxRowCount.Text;
            btnStart.Enabled = true;
            btnLabels.Enabled = true;
         
        }
        
  
        private void btnStart_Click(object sender, EventArgs e)
        {
            

            //to check to see if user has selected an excel file
            if ((strSource == "") || (strSource == null))
            {
                MessageBox.Show("Please Pick An Excel File", "Error");
            }

            //then creating and starting the application

            InitializeComponent();
            AppExcel = new Excel.Application();
            
            if (AppExcel == null)
            {
                MessageBox.Show("Could not start Excel");
                exceldata.ShowDialog();
            }


           //now declaring to start a new workbook                     readonly
            Excel.Workbook WB1 = AppExcel.Workbooks.Open(strSource, 0, true, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false,
                0, true, 0, 0);
            
                      

            //to get the compile a list of worksheets
            Excel.Sheets WBsheets = WB1.Worksheets;

            //get the first and only worksheet                    the  1 if for the first sheet in the workbook
            Excel.Worksheet sheet = (Excel.Worksheet)WBsheets.get_Item(1);

            //prep the row count by subtracting one cause of 0 based counting
            int intRowCount = System.Convert.ToInt32(strRowCount);
           
            strRowCount = System.Convert.ToString(intRowCount);

            //here to prep the rows by adding a Colum 5 ("E")
            strRowCount = "E" + strRowCount;

        
            //here you define your range        
            Excel.Range range = sheet.get_Range("A1", strRowCount);
            //here you pull the data out
            System.Array arryReturn = (System.Array)range.Cells.Value2;
          
        


            //good old cleanup
            arryReturn = null;
            arrySource = null;

             //end of dangerous code
             #endregion
       

             //to show excel
           // AppExcel.Visible = true;


          //going to kill excel so it removes the deadlock on the file
            KillExcel();
            

        }

        private void btnKillExcel_Click(object sender, EventArgs e)
        {
               //will call KillExcel procedure
            KillExcel();
        }

        private void btnLabels_Click(object sender, EventArgs e)
        {   //will build the schema for the array
            AM.arryTemp = new string[arrySingle.Length / 5, 5];
            //this will then copy the contents of the array ____MAKE NOTE_____
            Array.Copy(arrySingle, AM.arryTemp, arrySingle.Length);
            //Will start the multiplying process
            AM.Multiplexer();
            //Start the Write To Excel Process
            WriteToExcel();
         
        }

        public void WriteToExcel()
        {
            //then creating and starting the application

            InitializeComponent();
            AppExcel = new Excel.Application();

            if (AppExcel == null)
            {
                MessageBox.Show("Could not start Excel");
                exceldata.ShowDialog();
            }


            //now declaring to start a new workbook
            Excel.Workbook WB1 = AppExcel.Workbooks.Open(strSource, 0, false, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false,
                0, true, 0, 0);

            //to get the compile a list of worksheets
            Excel.Sheets WBsheets = WB1.Worksheets;

            //get the first and only worksheet                    the  2 if for the first sheet in the workbook
            Excel.Worksheet sheet = (Excel.Worksheet)WBsheets.get_Item(2);

            //will take the length of arryFinal and divide by five cause multi deimension array
            int intLenght = AM.arryFinal.Length / 5;


          

               //now that the array has then been fed and written to excel, the WorkBook must be saved to the hard drive
            sheet.SaveAs(strSource, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
                                    Missing.Value, Missing.Value, Missing.Value, Missing.Value);
            try
            {

                //messagebox to show the process is done
                MessageBox.Show("The Multiplexing is complete.", "Completed");
            }
            catch
            {
                MessageBox.Show("Operation Cancled By User (Did Not Save Over)", "Error");
            }
        }

        public void KillExcel()
        {

            //this will fish out all the process that have excel
            //the secret is "process name w/o .exe"
            Process[] process = Process.GetProcessesByName("Excel");
            for (int i = 0; i < process.GetLength(0); i++)
            {
                //kills excel process
                process[i].Kill();


            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            #region Licensing
            //pulls the hostname (LBMISTECH1) all caps too
            string strHostName = System.Environment.MachineName;
            // add the "\r\n" so it will match the line we will pull out of the text file
            strHostName = strHostName + "\r\n";
            //will assign where the file needs to go
            string strPath = @"c:\windows\system32\work.mul";

            //see if file work.mul exists in sytem32 folder
            if (File.Exists(strPath))
            {
                MessageBox.Show("Welcome To Multiplexer.", " Written By Lee Hicks");
            }
            else
            {
                //this will execute if file is not present
                MessageBox.Show("Please reinstall application", "Missing reference");
                //will close the form
                this.Close();
                
            }

            //this will try to open the text file to see if anything exists
            try
            {
                //create a streamreader to read the text file
                StreamReader srWorkMul = File.OpenText(strPath);
                //dumb the contents from file to the string
                string strContents = srWorkMul.ReadToEnd();
                // test to see if contents of text file match the hostname
                if (strContents == strHostName)
                {
                    //do nothing
                }
                else
                {
                    MessageBox.Show("Please reinstall application", "Missing reference");
                   //once again kill sthe app
                    this.Close();
                }

            }
            catch 
            {
                MessageBox.Show("Please reinstall application", "Missing reference");
                //if the applications can't find the file to open will close it again
                this.Close();

            }
            #endregion


        }

       

       

        



    }// end class
}// end namespace

Also I did add my own little version of licensing so the company I work for dosen't take my program and sell it without me knowing it. If anyone can help me with the Office Primary Interop Assemblies I would be thankful. I need this asap and is currently rewriting my app using OLE DB and a SQL server. But I would like to atleast get this first version working so people and actually see that it works and my second version is comming along slowly.

Help plz!!!!
Lee
Last edited by alc6379 : Apr 19th, 2006 at 12:39 pm.
AddThis Social Bookmark Button
Reply With Quote  

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb C# Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the C# Forum

All times are GMT -4. The time now is 10:41 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC