Export to excel output modification
<p>I am using the following code to export a dataset from c# to excel. I am getting the following output:</p>

<pre><code>ABC | 1 | 2/15/2011 21:36 | Systems Analyst | Project Duration
ABC | 1 | 2/15/2011 21:36 | Systems Analyst | Skill of Team
ABC | 1 | 2/15/2011 21:36 | Systems Analyst | Process
</code></pre>

<p>What I would like to do, however, is output data in the following format, and add column headings. I would like to display NEGATIVE if the output for StoryCategoryID is 1 and POSITIVE if the output is 0. Please help!</p>

<pre><code>Story | Story Type | Date | Project Member | Tag 1 | Tag 2 | Tag 3

ABC | Negative | 2/15/2011 21:36 | Project Duration | Skill of Team | Process
</code></pre>

<p>Code:</p>

<pre><code>protected void btnExcelExport_Click(object sender, EventArgs e)
{

        string sql = null;
        string data = null;
        //string path = save_as.Text;

        int i = 0;
        int j = 0;

        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);

        //connectionString = "data source=servername;initial catalog=databasename;user id=username;password=password;";
        SqlConnection cnn = new SqlConnection(GetConnectionString());
        cnn.Open();
        sql = "SELECT s.Story, s.StoryCategoryID, s.CreationDate, m.CompanyRole, af.Name FROM Story s INNER JOIN ProjectIterationMember pm ON pm.ProjectIterationMemberID = s.ProjectIterationMemberID INNER JOIN Iterations i ON i.ProjectIterationID = pm.ProjectIterationID INNER JOIN Member m ON m.MemberID = pm.MemberID INNER JOIN ProjectStoryFactors psf ON psf.StoryID = s.StoryID INNER JOIN AgileFactors af ON af.AgileFactorID = psf.AgileFactorID WHERE i.ProjectID = '" + proj_id + "'";
        SqlDataAdapter dscmd = new SqlDataAdapter(sql, cnn);
        DataSet ds = new DataSet();
        dscmd.Fill(ds);

        for (i = 0; i &lt;= ds.Tables[0].Rows.Count - 1; i++)
        {
            for (j = 0; j &lt;= ds.Tables[0].Columns.Count - 1; j++)
            {
                data = ds.Tables[0].Rows[i].ItemArray[j].ToString();
                xlWorkSheet.Cells[i + 1, j + 1] = data;
            }
        }

        xlWorkBook.SaveAs("excelDocument" + DateTime.Now.Ticks + ".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");
    }
</code></pre>
