473,398 Members | 2,120 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

From C# to Excel 2007

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 2025
tlhintoq
3,525 Expert 2GB
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
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 Expert 2GB
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
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
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....
0
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...
0
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...
2
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...
1
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...
15
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...
2
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. ...
2
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...
1
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...
4
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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...
0
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 project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.