0

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;


    }





}
tnw
  • 13,521
  • 15
  • 70
  • 111
  • What's your question? What is the problem with your code so far? – tnw Apr 02 '14 at 17:26
  • code is fine just wanna increase the font size of certain cell – user3471683 Apr 02 '14 at 17:26
  • No still could not find the answer ...... – user3471683 Apr 02 '14 at 17:32
  • What line of code for you is not working. This is a very large block. changing the font size is a one liner. Post only the part of your code concerned with changing the font size and delete the rest. – Brad Apr 02 '14 at 17:47
  • Actually in this code is working but i just want to add the functionality where i can change the fontsize of a particular cell in excel keeping the rest of the font size standard as shown in the code . – user3471683 Apr 02 '14 at 17:51
  • 1
    I understand that, which is why the code you have posted is not relevant to the question you have and why it should be edited. Did the `Range.Cells.Font.Size=##` technique in the link I posted not work? What did you try? what is the result? Is there an error? – Brad Apr 02 '14 at 17:58
  • Thanks brad it really helped it wish u luck :-) – user3471683 Apr 05 '14 at 18:54

0 Answers0