I have used this code to export in the excel with some condition happened quit well but i wanna increase the font size of the certain cell
public partial class generatereport : Form
{
Connect c = new Connect();
public generatereport()
{
InitializeComponent();
}
private void generatereport_Load(object sender, EventArgs e)
{
String str = "select distinct(projectname) from flat_master_sales";
MySqlDataAdapter sda = new MySqlDataAdapter(str, c.connection);
DataTable dt = new DataTable();
sda.Fill(dt);
if (dt.Rows.Count > 0)
{
comboBox1.DataSource = dt;
comboBox1.DisplayMember = "projectname";
comboBox1.ValueMember = "projectname";
}
}
private void button1_Click(object sender, System.EventArgs e)
{
Microsoft.Office.Interop.Excel.Application excelApp = null;
try
{
excelApp = new Microsoft.Office.Interop.Excel.Application();
excelApp.Application.Workbooks.Add(Type.Missing);
excelApp.Columns.ColumnWidth =27;
excelApp.Rows.RowHeight = 85;
excelApp.StandardFontSize = 8;
excelApp.StandardFont = "Calibri";
int a = 1, b = 1;
for (int i = 1; i < dataGridView1.Rows.Count; i++)
{
for (int j = 1; j <2; j++)
{
int total;
int value =4;
string stat = "VACANT";
if (dataGridView1.Rows[i - 1].Cells[5].Value.ToString() == "N" && dataGridView1.Rows[i - 1].Cells[6].Value.ToString() == "Y")
{
value = 3;
}
if (dataGridView1.Rows[i - 1].Cells[5].Value.ToString() =="Y" && dataGridView1.Rows[i - 1].Cells[6].Value.ToString() == "Y")
{
stat = "CANCELLED";
excelApp.Cells[a, b].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.LightGreen);
}
if (dataGridView1.Rows[i - 1].Cells[5].Value.ToString() == "N" && dataGridView1.Rows[i - 1].Cells[6].Value.ToString() == "Y")
{
stat = "SOLD";
excelApp.Cells[a,b].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.LightGray);
}
total = Convert.ToInt32(dataGridView1.Rows[i - 1].Cells[7].Value) + Convert.ToInt32(dataGridView1.Rows[i - 1].Cells[8].Value) + Convert.ToInt32(dataGridView1.Rows[i - 1].Cells[9].Value);
excelApp.Cells[a, b] = "WING:" + dataGridView1.Rows[i - 1].Cells[0].Value + " " + "FLAT:" + dataGridView1.Rows[i - 1].Cells[1].Value + " " + "FLOOR:" + dataGridView1.Rows[i - 1].Cells[2].Value + "\n" + "NAME:" + dataGridView1.Rows[i - 1].Cells[value].Value.ToString() +"\n"+"STATUS:"+stat+ "\n" + "S-AREA:" + dataGridView1.Rows[i - 1].Cells[7].Value + " " + "B-AREA:" + dataGridView1.Rows[i - 1].Cells[8].Value + " " + "C-AREA:" + dataGridView1.Rows[i - 1].Cells[9].Value + "\n" + "FLOWER BED:" + dataGridView1.Rows[i - 1].Cells[10].Value +" " + "BALCONY:" + dataGridView1.Rows[i - 1].Cells[11].Value + "\n" + "TERRACE:" + dataGridView1.Rows[i - 1].Cells[12].Value + " " + "TOTAL AREA:" + total;
j++;
b++;
if (b % 7 == 0)
{
a++; b = 1;
}
}
}
MessageBox.Show("Excel files has been created please save the file before creating a new one !");
excelApp.Visible = true;
excelApp.ActiveWorkbook.SaveCopyAs("C:\\test.xls");
// excelApp.ActiveWorkbook.
excelApp.ActiveWorkbook.Saved = true;
}
catch (Exception ex)
{
MessageBox.Show("Error occured Please call Customer support !" +ex.Message);
}
finally
{
if (excelApp != null)
{
}
}
}
private void button2_Click(object sender, EventArgs e)
{
}
public void button2_Click_1(object sender, EventArgs e)
{
string str = "select wing,flatno,floorno,Customername,projectname,cancelstatus,status,superbuiltuparea,builtuparea,carpetarea,flowerbed,balcony,terrace from flat_master_sales where projectname='" + comboBox1.SelectedValue + "'";
MySqlDataAdapter sda = new MySqlDataAdapter(str, c.connection);
DataTable dt = new DataTable();
sda.Fill(dt);
dataGridView1.DataSource = dt;
}
}