In my application i'm exporting datagridview data to excel sheet now i want to pass the combox and textbox selected values to excel sheet and i have to give title to my excel sheet as Report for my windows application how can i do that.
can any1 help me on this
i got code for exporting datagridview data to excel:
private void btnexcel_Click(object sender, EventArgs e)
{
Excel.Application xlApp ;
Excel.Workbook xlWorkBook ;
Excel.Worksheet xlWorkSheet ;
object misValue = System.Reflection.Missing.Value;
xlApp = new Excel.ApplicationClass();
xlWorkBook = xlApp.Workbooks.Add(misValue);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
int i = 0;
int j = 0;
for (i = 0; i <= dataGridView1.RowCount - 1; i++)
{
for (j = 0; j <= dataGridView1.ColumnCount - 1; j++)
{
DataGridViewCell cell = dataGridView1[j, i];
xlWorkSheet.Cells[i + 1, j + 1] = cell.Value;
}
}
xlWorkBook.SaveAs("csharp.net-informations.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();
releaseObject(xlWorkSheet);
releaseObject(xlWorkBook);
releaseObject(xlApp);
MessageBox.Show("Excel file created , you can find the file c:\\csharp.net-informations.xls");
}
private void releaseObject(object obj)
{
try
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
obj = null;
}
catch (Exception ex)
{
obj = null;
MessageBox.Show("Exception Occured while releasing object " + ex.ToString());
}
finally
{
GC.Collect();
}
}
}
}
Loading
VulpesPosted Jun 23, 2011, 5:16 AM
VulpesPosted Jun 23, 2011, 7:09 AM
SweetyPosted Jun 23, 2011, 5:29 AM
I want to give title as Report not for the sheet and aslo how can i make rows colourfull means look and feel..
SweetyPosted Jun 23, 2011, 4:25 AM
Posted Jun 23, 2011, 3:28 AM
Posted Jun 23, 2011, 3:01 AM
Please refer below site for export to excel and add the below lines for Dropdown value and textbox value.
Response.Write("Dropdown value");//Dropdown value
Response.Write("\n");
Response.Write("text box value");//text box value
Response.Write("\n");
add the above lines before first foreach statement starts, in the code snippet which is provided in the below url.
http://www.dotnetgallery.com/lab/resource44-Export-to-excel-from-DataTable-using-CNET.aspx
Thank you.