Posted by scmay on Thu 6 Aug 04:18
report abuse | download | new post
- private void SaveToExcel()
- {
- IList personList = //Retrieve a list of details;
- string filename = "filename.xls";
- string path = "C:\filename.xls";
- GenerateExcel(personList , filename, path);
- }
- public void GenerateExcel(IList personList , string _fileName, string _locationName)
- {
- StreamWriter fout;
- try
- {
- strBuilder.Append(Environment.NewLine + "<table border =1 ><tr>");
- strBuilder.Append(Environment.NewLine + "<td>" + "ID" + "</td>");
- strBuilder.Append(Environment.NewLine + "<td>" + "Due Date" + "</td>");
- strBuilder.Append(Environment.NewLine + "<td>" + "BCMI" + "</td>");
- strBuilder.Append(Environment.NewLine + "</tr>");
- foreach (IPerson person in personList)
- {
- strBuilder.Append(Environment.NewLine + "<td>" + payment.ID + "</td>");
- strBuilder.Append(Environment.NewLine + "<td>" + payment.Name + "</td>");
- strBuilder.Append(Environment.NewLine + "<td>" + payment.Age + "</td>");
- strBuilder.Append(Environment.NewLine + "</tr>");
- }
- strBuilder.Append(Environment.NewLine + "</table>");
- fout.WriteLine(strBuilder.ToString());
- fout.Close();
- //Opens the workbook
- view.Write("<script language=\"Javascript\">window.open('OpenFilePage.aspx?fn=" + _locationName.Replace("\\", "\\\\") +
- "',\"ExportingExcel\");</script>");
- }
- catch (Exception e)
- {
- e.StackTrace.ToString();
- }
- }
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.