
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Excel;
namespace Excel1
{
public partial class Form1 : Form
{
public const int INTERIORCOLOR = 13;
public const int FONTCOLOR = 2;
public Form1()
{
InitializeComponent();
}
Excel.Application oXL = new Excel.Application();
Excel.Workbook oBook;
Excel.Worksheet oSheet;
public void EmployeeReportGeneration(SqlConnection con)
{
int noOfRecords = 0;
oBook = oXL.Workbooks.Add(Type.Missing);
try
{
if (oBook.Worksheets.Count>1)
{
oSheet = (Excel.Worksheet)oBook.Sheets[1];
oXL.Visible = true;
SqlDataAdapter da = new SqlDataAdapter("select * from employee", con);
DataSet ds = new DataSet();
da.Fill(ds);
Range rg = oSheet.get_Range("B2", "E2");
rg.Select();
rg.Font.Bold = true;
rg.Font.Name = "Arial";
rg.Font.Size = 12;
rg.Cells.ColumnWidth = 68;
rg.WrapText = true;
rg.MergeCells = true;
rg.HorizontalAlignment = Excel.Constants.xlCenter;
rg = oSheet.get_Range("B2", Type.Missing);
rg.Value2 = "Employee Records";
rg.Interior.ColorIndex = INTERIORCOLOR;
rg.Font.ColorIndex = FONTCOLOR;
rg = oSheet.get_Range("B3", Type.Missing);
rg.Cells.ColumnWidth = 17;
rg.Font.Bold = true;
rg.Font.Name = "Verdana";
rg.Font.Size = 10;
rg.Interior.ColorIndex = 9;
rg.Font.ColorIndex = 2;
rg.Value2 = "Employee ID";
rg = oSheet.get_Range("C3", Type.Missing);
rg.Cells.ColumnWidth = 17;
rg.Font.Bold = true;
rg.Font.Name = "Verdana";
rg.Font.Size = 10;
rg.Interior.ColorIndex = 9;
rg.Font.ColorIndex = 2;
rg.Value2 = "Employee Name";
rg = oSheet.get_Range("D3", Type.Missing);
rg.Cells.ColumnWidth = 15;
rg.Font.Bold = true;
rg.Font.Name = "Verdana";
rg.Font.Size = 10;
rg.Interior.ColorIndex = 9;
rg.Font.ColorIndex = 2;
rg.Value2 = "Employee Sal";
rg = oSheet.get_Range("E3", Type.Missing);
rg.Cells.ColumnWidth = 19;
rg.Font.Bold = true;
rg.Font.Name = "Verdana";
rg.Font.Size = 10;
rg.Interior.ColorIndex = 9;
rg.Font.ColorIndex = 2;
rg.Value2 = "Employee Desg";
int x = 4;
int i = 0;
noOfRecords = ds.Tables[0].Rows.Count;
while (i < name = "Employees" sa = "B" rg =" oSheet.get_Range(sA.ToString()," value2 =" ds.Tables[0].Rows[i][0].ToString();" bold =" true;" colorindex =" 9;" colorindex =" 2;" sb = "C" rg =" oSheet.get_Range(sB.ToString()," value2 = "'" colorindex =" INTERIORCOLOR;" colorindex =" FONTCOLOR;" sc = "D" rg =" oSheet.get_Range(sC.ToString()," value2 =" ds.Tables[0].Rows[i][2].ToString();" colorindex =" INTERIORCOLOR;" colorindex =" FONTCOLOR;" sd = "E" rg =" oSheet.get_Range(sD.ToString()," value2 =" ds.Tables[0].Rows[i][3].ToString();" colorindex =" INTERIORCOLOR;" colorindex =" FONTCOLOR" rowcount="0;" total =" 0;" rowcount =" 4;" row = "D" rg =" oSheet.get_Range(row.ToString()," total =" total" totaldisplay = "C" rg =" oSheet.get_Range(totalDisplay," value2 = "Total" colorindex =" 5;" bold =" true;" colorindex =" 2;" totalrow = "D" rg =" oSheet.get_Range(totalRow," value2 =" total;" colorindex =" 5;" colorindex =" 2;" numberformat = "Rs0,00" mycharts =" (Excel.ChartObjects)oSheet.ChartObjects(Type.Missing);" mychart1 =" MyCharts.Add(100," ochart =" MyChart1.Chart;" chartrg =" oSheet.get_Range(" haslegend =" true;" position =" Excel.XlLegendPosition.xlLegendPositionLeft;" colorindex =" 5;" hastitle =" true;" text = "Employee Record Chart" excstring =" ex.Message" con =" new" security="yes;data" source="DEV09;database="smple">

1 comment:
really its very useful i got good solution by using this code
Post a Comment