string path = Application.StartupPath;
Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
app.Visible = true;
app.DisplayFullScreen = true;
Excel.Workbook wb = app.Workbooks.Add(1);
Excel.Worksheet ws = (Excel.Worksheet)wb.Worksheets[1];
app.ActiveWindow.DisplayGridlines = true;
Excel.Range ChartRange;
ws.Shapes.AddPicture(path + "\\Tareta_Image.jpg", Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoCTrue, 0, 0, 170, 28);
ws.Cells[4, 3] = "Key Events Report";
ws.Cells[4, 4] = "From:" + Date1.Text + " To:" + Date2.Text + "";
ws.Cells[5, 2] = "Asset Number";
ws.Cells[5, 3] = "Asset Description";
ws.Cells[5, 4] = "Event Description";
ws.Cells[5, 5] = "Event Date";
ChartRange = ws.get_Range("c4", "d4");
ChartRange.Font.Bold = true;
ChartRange.Font.Name = "Microsoft Sans Serif";
ChartRange.Font.Size = 11;
ChartRange.Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.FromArgb(90, 90, 90));
ChartRange = ws.get_Range("b5", "e5");
ChartRange.BorderAround(Excel.XlLineStyle.xlContinuous, Excel.XlBorderWeight.xlThin, Excel.XlColorIndex.xlColorIndexAutomatic,1);
ChartRange.Font.Bold = true;
ChartRange.Font.Name = "Microsoft Sans Serif";
ChartRange.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.FromArgb(97, 97, 97));
ChartRange.Font.Color=System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.FromArgb(255,255,255));
ChartRange.Interior.Pattern = Excel.XlPattern.xlPatternSolid;
ChartRange.Font.Size = 10;
int k = 7;
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
ws.Cells[k, 2] = Excel.XlHAlign.xlHAlignCenter;
ws.Cells[k, 2] = ds.Tables[0].Rows[i]["fldAssetNo"].ToString();
ws.Cells[k, 3] = ds.Tables[0].Rows[i]["fldAssetDescription"].ToString();
ws.Cells[k, 4] = ds.Tables[0].Rows[i]["fldEventDescription"].ToString();
ws.Cells[k, 5] = Convert.ToDateTime(ds.Tables[0].Rows[i]["fldEventDate"].ToString()).ToShortDateString();
k++;
}
k = k + 1;
ws.Cells[k, 3] = "***** End of the Report *****";
ws.Columns.AutoFit();
}
else
{
MessageBox.Show("No data to Show");
}
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
Response.Write("<table><tr><th align="center" colspan="6">Software List By System </th></tr></table>");
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
GV.RenderControl(hw);
Response.AddHeader("Content-Disposition", "attachment;filename=SoftwareListBySystem .xls");
Response.Write(tw.ToString());
Response.Flush();
Response.End();