hello guys how r u ??
my question is that, i am getting data from database into dataset, and now i want to write my dataset into excel file , while i was trying to export gridview into excel but the problem was that i have one column of CODE into my database table with values like 001, 002, 003 and so on but in excel file CODE column is showing 1, 2, 3 not with zero while i want CODE value with zeros ... i hope you got my point what i m trying to do..
replyy soon
Thanks
Loading
Faisal AnsariPosted Jan 6, 2013, 11:17 PM
venkata kumarPosted Jan 5, 2013, 5:03 AM
this
if (dataGridView1.Rows.Count > 0)
{
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
xlApp = new Excel.ApplicationClass();
xlApp.Visible = true;
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");
}
instead of grid view give data set