Notes
Notes - notes.io |
{
// Create a DataTable to hold your data (you can replace this with your actual data)
DataTable dataTable = new DataTable();
foreach (DataControlFieldHeaderCell headerCell in GridView1.HeaderRow.Cells)
{
dataTable.Columns.Add(headerCell.Text);
}
foreach (GridViewRow row in GridView1.Rows)
{
DataRow dataRow = dataTable.NewRow();
for (int i = 0; i < row.Cells.Count; i++)
{
dataRow[i] = row.Cells[i].Text;
}
dataTable.Rows.Add(dataRow);
}
// Export DataTable to Excel
if (dataTable != null && dataTable.Rows.Count > 0)
{
// Generate Excel content and save it to a memory stream
using (var package = new ExcelPackage())
{
var worksheet = package.Workbook.Worksheets.Add("Sheet1");
worksheet.Cells["A1"].LoadFromDataTable(dataTable, true);
worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns();
// Specify the custom file name (you can modify this as needed)
string customFileName = "exported_data_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx";
// Save the Excel package to a memory stream
byte[] fileBytes = package.GetAsByteArray();
// Set the content type and headers for the response
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + customFileName);
// Write the file bytes to the response stream
Response.BinaryWrite(fileBytes);
Response.Flush();
Response.End();
Label16.Visible = true;
Label16.Text = customFileName + " нэртэй excel file амжилттай татагдлаа!";
}
}
else
{
// Handle the case where the DataTable is empty or null
// You can show a message to the user or take appropriate action
}
}
|
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team