Using Microsoft Excel 10.0 Libary Object -Dang .dlls

Please support our C# advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
Thread Solved
Reply

Join Date: Apr 2006
Posts: 88
Reputation: blacklocist is an unknown quantity at this point 
Solved Threads: 2
blacklocist blacklocist is offline Offline
Junior Poster in Training

Using Microsoft Excel 10.0 Libary Object -Dang .dlls

 
0
  #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.

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Diagnostics;
  9. //great for using missing.value;
  10. using System.Reflection;
  11. using Microsoft.Office.Core;
  12. using System.Threading;
  13. using System.IO;
  14.  
  15.  
  16.  
  17. namespace DeannaProj2
  18. {
  19. public partial class Form1 : Form
  20. {
  21.  
  22. //declaring and object Called AppExcel
  23. private Excel.Application AppExcel = null;
  24.  
  25.  
  26. ArrayManipulator AM = new ArrayManipulator();
  27.  
  28. string strSource = null;
  29. string strRowCount = null;
  30. public string [,] arrySingle = null;
  31.  
  32.  
  33.  
  34. public Form1()
  35. {
  36. InitializeComponent();
  37. }
  38.  
  39.  
  40. //to take care of opening and picking the excel file
  41. private void btnExcel_Click(object sender, EventArgs e)
  42. {
  43.  
  44. exceldata.ShowDialog();
  45. strSource = exceldata.FileName;
  46. lblSource.Text = strSource;
  47.  
  48.  
  49. }
  50.  
  51. private void btnRow_Click(object sender, EventArgs e)
  52. {
  53.  
  54. //to check to see if user has selected an excel file
  55. if (strSource == "")
  56. {
  57. MessageBox.Show("Please Pick An Excel File", "Error");
  58. }
  59.  
  60. strRowCount = txtbxRowCount.Text;
  61. btnStart.Enabled = true;
  62. btnLabels.Enabled = true;
  63.  
  64. }
  65.  
  66.  
  67. private void btnStart_Click(object sender, EventArgs e)
  68. {
  69.  
  70.  
  71. //to check to see if user has selected an excel file
  72. if ((strSource == "") || (strSource == null))
  73. {
  74. MessageBox.Show("Please Pick An Excel File", "Error");
  75. }
  76.  
  77. //then creating and starting the application
  78.  
  79. InitializeComponent();
  80. AppExcel = new Excel.Application();
  81.  
  82. if (AppExcel == null)
  83. {
  84. MessageBox.Show("Could not start Excel");
  85. exceldata.ShowDialog();
  86. }
  87.  
  88.  
  89. //now declaring to start a new workbook readonly
  90. Excel.Workbook WB1 = AppExcel.Workbooks.Open(strSource, 0, true, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false,
  91. 0, true, 0, 0);
  92.  
  93.  
  94.  
  95. //to get the compile a list of worksheets
  96. Excel.Sheets WBsheets = WB1.Worksheets;
  97.  
  98. //get the first and only worksheet the 1 if for the first sheet in the workbook
  99. Excel.Worksheet sheet = (Excel.Worksheet)WBsheets.get_Item(1);
  100.  
  101. //prep the row count by subtracting one cause of 0 based counting
  102. int intRowCount = System.Convert.ToInt32(strRowCount);
  103.  
  104. strRowCount = System.Convert.ToString(intRowCount);
  105.  
  106. //here to prep the rows by adding a Colum 5 ("E")
  107. strRowCount = "E" + strRowCount;
  108.  
  109.  
  110. //here you define your range
  111. Excel.Range range = sheet.get_Range("A1", strRowCount);
  112. //here you pull the data out
  113. System.Array arryReturn = (System.Array)range.Cells.Value2;
  114.  
  115.  
  116.  
  117.  
  118. //good old cleanup
  119. arryReturn = null;
  120. arrySource = null;
  121.  
  122. //end of dangerous code
  123. #endregion
  124.  
  125.  
  126. //to show excel
  127. // AppExcel.Visible = true;
  128.  
  129.  
  130. //going to kill excel so it removes the deadlock on the file
  131. KillExcel();
  132.  
  133.  
  134. }
  135.  
  136. private void btnKillExcel_Click(object sender, EventArgs e)
  137. {
  138. //will call KillExcel procedure
  139. KillExcel();
  140. }
  141.  
  142. private void btnLabels_Click(object sender, EventArgs e)
  143. { //will build the schema for the array
  144. AM.arryTemp = new string[arrySingle.Length / 5, 5];
  145. //this will then copy the contents of the array ____MAKE NOTE_____
  146. Array.Copy(arrySingle, AM.arryTemp, arrySingle.Length);
  147. //Will start the multiplying process
  148. AM.Multiplexer();
  149. //Start the Write To Excel Process
  150. WriteToExcel();
  151.  
  152. }
  153.  
  154. public void WriteToExcel()
  155. {
  156. //then creating and starting the application
  157.  
  158. InitializeComponent();
  159. AppExcel = new Excel.Application();
  160.  
  161. if (AppExcel == null)
  162. {
  163. MessageBox.Show("Could not start Excel");
  164. exceldata.ShowDialog();
  165. }
  166.  
  167.  
  168. //now declaring to start a new workbook
  169. Excel.Workbook WB1 = AppExcel.Workbooks.Open(strSource, 0, false, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false,
  170. 0, true, 0, 0);
  171.  
  172. //to get the compile a list of worksheets
  173. Excel.Sheets WBsheets = WB1.Worksheets;
  174.  
  175. //get the first and only worksheet the 2 if for the first sheet in the workbook
  176. Excel.Worksheet sheet = (Excel.Worksheet)WBsheets.get_Item(2);
  177.  
  178. //will take the length of arryFinal and divide by five cause multi deimension array
  179. int intLenght = AM.arryFinal.Length / 5;
  180.  
  181.  
  182.  
  183.  
  184. //now that the array has then been fed and written to excel, the WorkBook must be saved to the hard drive
  185. sheet.SaveAs(strSource, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
  186. Missing.Value, Missing.Value, Missing.Value, Missing.Value);
  187. try
  188. {
  189.  
  190. //messagebox to show the process is done
  191. MessageBox.Show("The Multiplexing is complete.", "Completed");
  192. }
  193. catch
  194. {
  195. MessageBox.Show("Operation Cancled By User (Did Not Save Over)", "Error");
  196. }
  197. }
  198.  
  199. public void KillExcel()
  200. {
  201.  
  202. //this will fish out all the process that have excel
  203. //the secret is "process name w/o .exe"
  204. Process[] process = Process.GetProcessesByName("Excel");
  205. for (int i = 0; i < process.GetLength(0); i++)
  206. {
  207. //kills excel process
  208. process[i].Kill();
  209.  
  210.  
  211. }
  212. }
  213.  
  214. private void Form1_Load(object sender, EventArgs e)
  215. {
  216.  
  217. #region Licensing
  218. //pulls the hostname (LBMISTECH1) all caps too
  219. string strHostName = System.Environment.MachineName;
  220. // add the "\r\n" so it will match the line we will pull out of the text file
  221. strHostName = strHostName + "\r\n";
  222. //will assign where the file needs to go
  223. string strPath = @"c:\windows\system32\work.mul";
  224.  
  225. //see if file work.mul exists in sytem32 folder
  226. if (File.Exists(strPath))
  227. {
  228. MessageBox.Show("Welcome To Multiplexer.", " Written By Lee Hicks");
  229. }
  230. else
  231. {
  232. //this will execute if file is not present
  233. MessageBox.Show("Please reinstall application", "Missing reference");
  234. //will close the form
  235. this.Close();
  236.  
  237. }
  238.  
  239. //this will try to open the text file to see if anything exists
  240. try
  241. {
  242. //create a streamreader to read the text file
  243. StreamReader srWorkMul = File.OpenText(strPath);
  244. //dumb the contents from file to the string
  245. string strContents = srWorkMul.ReadToEnd();
  246. // test to see if contents of text file match the hostname
  247. if (strContents == strHostName)
  248. {
  249. //do nothing
  250. }
  251. else
  252. {
  253. MessageBox.Show("Please reinstall application", "Missing reference");
  254. //once again kill sthe app
  255. this.Close();
  256. }
  257.  
  258. }
  259. catch
  260. {
  261. MessageBox.Show("Please reinstall application", "Missing reference");
  262. //if the applications can't find the file to open will close it again
  263. this.Close();
  264.  
  265. }
  266. #endregion
  267.  
  268.  
  269. }
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279. }// end class
  280. }// 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 1:39 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 206
Reputation: plazmo is an unknown quantity at this point 
Solved Threads: 16
plazmo's Avatar
plazmo plazmo is offline Offline
Posting Whiz in Training

Re: Using Microsoft Excel 10.0 Libary Object -Dang .dlls

 
0
  #2
Apr 19th, 2006
i didnt really read your code so im not sure what your doing with the data. but anyways im sure all you need is ms office installed on the machine for it to work.

if all you are doing is reading and writing to a excel file you could try using oledb with jet 4.0 and the excel driver in the conn string. then that will let you read the excel file like a database.
Reply With Quote Quick reply to this message  
Join Date: Dec 2003
Posts: 2,414
Reputation: alc6379 has a spectacular aura about alc6379 has a spectacular aura about alc6379 has a spectacular aura about 
Solved Threads: 123
Team Colleague
alc6379's Avatar
alc6379 alc6379 is offline Offline
Cookie... That's it

Re: Using Microsoft Excel 10.0 Libary Object -Dang .dlls

 
0
  #3
Apr 19th, 2006
I'd have to agree with plazmo on this one.

You will probably have to have Office installed on all of the machines that you're planning on depolying to. I think that the Excel stuff you're doing relies upon COM, which in itself relies upon the regeistered presense of Excel/Office in order to do all of its work.

I hate to say your work was in vain, but if you had used oleDb with Jet4.0, as plazmo described, the only thing your clients would need is the correct version of .NET CLR installed on their machines.
Alex Cavnar, aka alc6379
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 88
Reputation: blacklocist is an unknown quantity at this point 
Solved Threads: 2
blacklocist blacklocist is offline Offline
Junior Poster in Training

Re: Using Microsoft Excel 10.0 Libary Object -Dang .dlls

 
0
  #4
Apr 19th, 2006
Well I already checked that, all the computers where I work have Office XP. The users would hunt me if I didn't cause they all like Excel.

Well I will just have to accept that my work is in vain. Well thanks for all the feed back and I am working oledb. Just real slow cause I have never used it before till now.

Also just something to chew on. For Microsoft being big into programming and make VS you would think since they pride their product Office that they would make it much much easier to write apps, especially for their developing software. Ohhh well
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC