Hi. Here's what i have done:
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.
Code:
using System;
using System.Collections;
using System.Reflection; // For Missing.Value and BindingFlags
using System.Runtime.InteropServices; // For COMException
using Excel = Microsoft.Office.Interop.Excel;
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();
}
}
}
Comment