rshin2020 0 Report post Posted January 8, 2010 Hi. I have to write a simple program to display a console application for:String - Voltage, EmployeeIDNumber - 1.016, 00180000Here's what ive done:using System;using System.Collections.Generic;using System.Text;namespace ConsoleApplication1{ class Program { static void Main(string[] args) { double p = 1.016; int q = 00180000; Console.WriteLine("Voltage: {0}", p); Console.WriteLine("EmployeeID: {1}", q); } }}I seem to get an error but don't know where the error is. Could someone please help me to correct the code. I also need to convert the data to be displayed in Excel 2007. How do I do that. I'm really new to C#.net. Please help, thanks. Quote Share this post Link to post Share on other sites
johnburn 6 Report post Posted January 8, 2010 To create Excel file, you can use System.IO.Packaging classes (.NET 3.0).This might give you some ideas:http://www.codeguru.com/csharp/.net/net_asp/tutorials/article.php/c13123/ Quote Share this post Link to post Share on other sites
rshin2020 0 Report post Posted January 8, 2010 Based on the code below, which part do I change? And from what I have read, it said that: 'Start by adding a new worksheet called "Tinned Goods" and adding some basic data and a simple calculation'. Meaning, do i have to type an example in a spreadsheet in excel? Or how? using OfficeOpenXml; // namespace for the ExcelPackage assemblyb&FileInfo newFile = new FileInfo(@"C:\mynewfile.xlsx");using (ExcelPackage xlPackage = new ExcelPackage(newFile)) { b& }ExcelWorksheet worksheet = xlPackage.Workbook.Worksheets.Add("Tinned Goods");// write some titles into column 1worksheet.Cell(1, 1).Value = "Product";b&worksheet.Cell(4, 1).Value = "Peas";worksheet.Cell(5, 1).Value = "Total";// write some values into column 2worksheet.Cell(1, 2).Value = "Tins Sold";ExcelCell cell = worksheet.Cell(2, 2);cell.Value = "15"; // tins of Beans soldstring calcStartAddress = // we want this for the formula cell.CellAddress;worksheet.Cell(3, 2).Value = "32"; // tins of Carrots soldb&worksheet.Cell(5, 2).Formula = string.Format(SUM({0}:{1})", calcStartAddress, calcEndAddress);Hope can help. Thanks. Quote Share this post Link to post Share on other sites
rshin2020 0 Report post Posted January 12, 2010 Still no reply. Anyway, here's what i have done. I need it in a console format. How do I do it using this code?using System;using System.Collections;using System.Reflection; // For Missing.Value and BindingFlagsusing System.Runtime.InteropServices; // For COMExceptionusing Excel = Microsoft.Office.Interop.Excel;using System.ComponentModel;using System.Data;namespace MSExcelApp{ /// <summary> /// Summary description for ExcelAuto. /// </summary> public class ExcelAuto { private Excel.Application ExcelApp; private Excel.Workbook objBook; private Excel.Worksheet objSheet; private Excel.Range range; string strAttendeeList, strAbsenteeList, strCopiesToList; int totActionItems; object oMissing, oTemplate; private string strTitle; public ExcelAuto() { // // TODO: Add constructor logic here // } public void CreateFile(ArrayList array) { object missing = System.Reflection.Missing.Value; object fileName = "normal.dot"; object newTemplate = false; object docType = 0; object isVisible = true; ExcelApp = new Excel.ApplicationClass(); ExcelApp.Visible = true; objBook = ExcelApp.Workbooks.Add(missing); objSheet = (Excel.Worksheet)objBook.Sheets["Sheet1"]; objSheet.Name = "It's Me"; objSheet.Cells[1, 1] = "Details"; objSheet.Cells[2, 1] = "Voltage : "+ array[0].ToString(); objSheet.Cells[3, 1] = "EmployeeID : "+ array[1].ToString(); objSheet.get_Range("A1", "A1").Font.Bold = true; objSheet.get_Range("A1", "A6").EntireColumn.AutoFit(); objSheet.get_Range("A1","A7").BorderAround(Excel.XlLineStyle.xlContinuous,Excel.XlBorderWeight.xlMedium, Excel.XlColorIndex.xlColorIndexAutomatic,Excel.XlColorIndex.xlColorIndexAutomatic); } static void Main() { Application.Run(new Form1()); } private void btnCreate_Click(object sender, System.EventArgs e) { ExcelAuto excel = new ExcelAuto(); ArrayList array = new ArrayList(); bool filled = true; if ( ( 1.016).ToString().Length.Equals(0) ) { errorProvider.SetError(1.016,"cannot be empty" ); filled = false; } if( ( 00180000 ).ToString().Length.Equals(0) ) { errorProvider.SetError( 00180000,"cannot be empty" ); filled = false; } if ( filled == true ) { array.Insert(0,1.016); array.Insert(1,00180000); excel.CreateFile(array); } } private void button2_Click(object sender, System.EventArgs e) { Application.Exit(); } }} Quote Share this post Link to post Share on other sites