473,657 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

From C# to Excel 2007

26 New Member
Hi. Here's what i have done:

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections;
  3. using System.Reflection; // For Missing.Value and BindingFlags
  4. using System.Runtime.InteropServices; // For COMException
  5. using Excel = Microsoft.Office.Interop.Excel;
  6.  
  7. namespace MSExcelApp
  8. {
  9.     /// <summary>
  10.     /// Summary description for ExcelAuto.
  11.     /// </summary>
  12.     public class ExcelAuto
  13.     {
  14.         private Excel.Application ExcelApp;
  15.         private Excel.Workbook objBook;
  16.         private Excel.Worksheet objSheet;
  17.         private Excel.Range range;
  18.         string strAttendeeList, strAbsenteeList, strCopiesToList;
  19.         int totActionItems;
  20.         object oMissing, oTemplate;
  21.         private string strTitle;
  22.  
  23.         public ExcelAuto()
  24.         {
  25.             //
  26.             // TODO: Add constructor logic here
  27.             //
  28.         }
  29.         public void CreateFile(ArrayList array)
  30.         {
  31.             object missing = System.Reflection.Missing.Value;
  32.             object fileName = "normal.dot";
  33.             object newTemplate = false;
  34.             object docType = 0;
  35.             object isVisible = true;
  36.  
  37.             ExcelApp = new Excel.ApplicationClass();
  38.             ExcelApp.Visible = true;
  39.             objBook = ExcelApp.Workbooks.Add(missing);
  40.             objSheet = (Excel.Worksheet)objBook.Sheets["Sheet1"];
  41.             objSheet.Name = "It's Me";
  42.  
  43.            objSheet.Cells[1, 1] = "Details";
  44.             objSheet.Cells[2, 1] = "Voltage : "+ array[0].ToString();
  45.             objSheet.Cells[3, 1] = "EmployeeID : "+ array[1].ToString();
  46.  
  47.             objSheet.get_Range("A1", "A1").Font.Bold = true;
  48.             objSheet.get_Range("A1", "A6").EntireColumn.AutoFit();
  49.             objSheet.get_Range("A1","A7").BorderAround(Excel.XlLineStyle.xlContinuous,Excel.XlBorderWeight.xlMedium,
  50.                             Excel.XlColorIndex.xlColorIndexAutomatic,Excel.XlColorIndex.xlColorIndexAutomatic);
  51.         }
  52.  
  53.             static void Main() 
  54.         {
  55.             Application.Run(new Form1());
  56.         }
  57.  
  58.         private void btnCreate_Click(object sender, System.EventArgs e)
  59.         {
  60.             ExcelAuto excel = new ExcelAuto();
  61.             ArrayList array = new ArrayList();
  62.             bool filled = true;
  63.  
  64.             if ( ( 1.016).ToString().Length.Equals(0) )
  65.             {
  66.                 errorProvider.SetError(1.016,"cannot be empty" );
  67.                 filled = false;
  68.             }
  69.             if( ( 00180000 ).ToString().Length.Equals(0) )
  70.             {
  71.                 errorProvider.SetError( 00180000,"cannot be empty" );
  72.                 filled = false;
  73.             }
  74.  
  75.  
  76.             if ( filled == true )
  77.             {
  78.                 array.Insert(0,1.016);
  79.                 array.Insert(1,00180000);
  80.  
  81.  
  82.                 excel.CreateFile(array);
  83.             }
  84.         }
  85.  
  86.         private void button2_Click(object sender, System.EventArgs e)
  87.         {
  88.             Application.Exit();
  89.         }
  90.     }
  91. }
  92.  
  93.  
I have to convert the data of voltage and employeeeID, 1.016 and 00180000 respectively to be displayed in excel. It has to be in console. Can you please check the code. There's some errors but i don't know how to mend them. Thanks.
Jan 12 '10 #1
4 2030
tlhintoq
3,525 Recognized Expert Specialist
There's some errors but i don't know how to mend them. Thanks.
Help the volunteers to help you: What are the errors and on what line #'s?
Jan 12 '10 #2
rshin2020
26 New Member
Line 65: Class, struct, or interface method must have a return type
Line 133: Type or namespace definition, or end-of-file expected

All I need is to display the data in excel. It has to be in console not windows application. Thanks.
Jan 13 '10 #3
tlhintoq
3,525 Recognized Expert Specialist
Line 65: Class, struct, or interface method must have a return type
Line 133: Type or namespace definition, or end-of-file expected
You don't have 133 lines of code here. There are only 93 if you count the last to blank lines.
Jan 13 '10 #4
rshin2020
26 New Member
the last one refers to the curly braces at the end. I dont know whats wrong there.
Jan 13 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

18
4400
by: gonzlobo | last post by:
No, I don't want to destroy them (funny how the word 'decimate' has changed definition over the years) :). We have a data acquisition program that saves its output to Excel's ..xls format. Unfortunately, the programmer was too stupid to write files the average user can read. I'd like some advice on how to go about: 1. Reading a large Excel file and chop it into many Excel files (with only 65535 lines per file)
0
1355
by: thought.contagion | last post by:
I need to determine if Excel 2007 is installed. For Office 2003, we had the component ID for Excel 2003 and could use the msi.dll to enumerate and that would tell us if it was installed: iRet = MsiGetComponentPath(sProductCode.Trim, sComponentID, sPath, iLen) sProductCode is the Office 2003 Product Code, sComponentID is the Excel 2003 component ID. sPath would hold the path to excel.exe.
0
1712
by: silverear | last post by:
Hello everybody, I have written an application that is running as an Office project within Excel in C#. I created a setup project for my tool. When I install my program on a machine that has Excel 2003 everything is fine. If there is only Excel 2007 the installation will fail. If there are both (Excel 2003 and 2007) installed, the installation is also ok. My tool is running fine with Excel 2007, but I can't install it on a machine...
2
8913
by: Ch Pravin | last post by:
Hi All: I am having the following xml which i need to convert to excel using xslt. Please help me out. Afghanistan.xml <?xml version="1.0" encoding="utf-16"?> <Languages BuildVersion="1,5,0815,0 " CountryName="Afghanistan" > <Language locale="English">
1
1259
by: cloh | last post by:
I have a form in Access that generates an Excel Workbook with multiple worksheets. Each worksheet is unique to a particular location. The top row of each sheet shows the dates, the left-most column has the times of the day in 5 minute intervals. Let's say the dates range from 7/01/2007 to 9/01/2007 The aim of the form is to eventually create a chart for each date that the user wants. On the form, I get the user to input either a single date...
15
5342
by: =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?= | last post by:
Hi All, We are in the process of Upgrade Excel 2003 (Office 2003) to Excel 2007 (Office 2007) for one of web application. This web application is using Excel (Pivot Table) reports. With Excel 2003 application (Reports) works ok. But when Office 2003 is upgraded to Office 2007 Excel reports stops working. It Log the error “Exception from HRESULT: 0x800A03EC.” In database.
2
1824
by: mwilliams4 | last post by:
I have an Access 2003 table that I want to generate into tabbed Excel 2003 workbooks using a button on a form. The tables would need to overwrite everytime that the button would be pressed. Table name: Datatable (data) Field1: Customer (Bob, Dan, Joe) Field2: Model (Ace, Cat, San) Field3: YrMo (2007-01, 2007-02, 2007-03)
2
5184
budigila
by: budigila | last post by:
Hiya peeps, Okies, I have been trying to work this out for a while now to no avail... I am a beginner to this whole coding thing but have made great strides in my project. Basically what I am trying to do is to convert an .xml using a .xsl to and using a java script to output it into a readable format within excel. I have been able to successfully use a javascript to combine my .xml and .xsl but cannot figure out how to have it output to...
1
2734
by: chuch0117291 | last post by:
Hi, i have a form with the main details of a vendor and and contract description and a budget reference(PK). Within this form, i have a sub form which includes cost details for that specific vendor but also has the same budget reference hence the link. I would like to create a command button to be able to export the data from the main form to an excel spreadsheet and the data from the sub form to excel spreadsheet tab2 from the click of a...
4
2430
by: Ted Theo | last post by:
hello cdma enthusiasts. long time no speak. i have an .adp which is connected to a sql 2k back end from which i need to export a table to a tab delimited text file. the export text wizard apparently doesn't allow you to store export specs (makes sense since it has no local storage) so i'm not sure the TransferText method is going to do the trick. i need to do this in VBA. any suggestions? it's been a while since i've been active in...
0
8324
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8842
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8740
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8513
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7352
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1733
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.