Advertisement
Guest User

Untitled

a guest
Jul 28th, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. {
  2. Response.Clear();
  3. Response.Buffer = true;
  4. Response.AddHeader("content-disposition", "attachment;filename=Report.csv");
  5. Response.Charset = "";
  6. Response.ContentType = "application/text";
  7. gvReport.AllowPaging = false;
  8. StringBuilder sBuilder = new System.Text.StringBuilder();
  9. for(int index = 0; index < gvReport.Columns.Count; index++)
  10. {
  11. sBuilder.Append(gvReport.Columns[index].HeaderText + ',');
  12. }
  13. sBuilder.Append("rn");
  14. for(int i = 0; i <gvReport.Rows.Count; i++)
  15. {
  16. for(int k = 0; k < gvReport.HeaderRow.Cells.Count; k++)
  17. {
  18. sBuilder.Append(gvReport.Rows[i].Cells[k].Text.Replace(",","") + ",");
  19. }
  20. sBuilder.Append("rn");
  21. }
  22. Response.Output.Write(sBuilder.ToString());
  23. Response.Flush();
  24. Response.End();
  25. }
  26.  
  27. var sBuilder = new StringBuilder();
  28. foreach (DataGridViewRow row in gridSchedules.Rows)
  29. {
  30. // RowHeader
  31. sBuilder.Append(String.Concat(row.HeaderCell.Value, ";"));
  32.  
  33. // Cells
  34. foreach (DataGridViewCell cell in row.Cells)
  35. {
  36. sBuilder.Append(String.Concat(cell.Value, ";"));
  37. }
  38. sBuilder.Append(Environment.NewLine);
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement