private void FnExportDataIntoExcel()
{
// get data from Database
dtDataToExport = objDBClass.GetDataFunction(objParam); // call Data access layer function to get
data from Database to export
if
(dtDataToExport != null
&&
dtDataToExport.Rows.Count > 0)
{
DataTable dataTable =
dtDataToExport;
//File Name
string DT =
DateTime.Now.ToString("yyyyMMdd_hhmmsssstt");
// Set up the Response
object...
this.Response.BufferOutput = false;
this.Response.Charset =
string.Empty;
this.Response.Clear();
this.Response.ClearContent();
this.Response.ClearHeaders();
this.Response.ContentType
= "application/vnd.ms-excel";
// Open the document OVER this window:
string contentDisposition
= "attachment; filename=" + "SalesReport_GST" +
"_" + DT + ".xls";
this.Response.AppendHeader("content-disposition",
contentDisposition);
// Create a table HTML
tag...
string textOutput =
"<table
border='1' bordercolor='black' rules='all' " +
"style='BORDER: 1px
double; BORDER-COLLAPSE: collapse;'>\r\n";
this.Response.Write(textOutput);
// Write out the column
headers...
textOutput = "<tr
height=17 style='height:12.75pt'>\r\n";
for (int i = 0; i <
dataTable.Columns.Count; i++)
{
textOutput +=
string.Format(
System.Globalization.CultureInfo.InvariantCulture,
"<th
align='left'>{0}</th>",
dataTable.Columns[i].ColumnName);
}
textOutput +=
"</tr>\r\n";
this.Response.Write(textOutput);
// Write out each row of
the DataTable...
textOutput =
string.Empty;
for (int i = 0; i <
dataTable.Rows.Count; i++)
{
System.Data.DataRow
dataRow = dataTable.Rows[i];
textOutput =
"<tr height=17 style='height:12.75pt'>\r\n";
// Loop through the
columns for each row and grab the values...
for (int j = 0; j
< dataTable.Columns.Count; j++)
{
string
dataRowText = dataRow[j].ToString().Trim();
// Remove any
tabs, carriage returns, or newlines from the value...
dataRowText =
dataRowText.Replace("\t", " ");
dataRowText =
dataRowText.Replace("\r", string.Empty);
dataRowText =
dataRowText.Replace("\n", " ");
textOutput +=
string.Format(
System.Globalization.CultureInfo.InvariantCulture,
"<td
align='left' style='mso-number-format:\\@;'>{0}</td>",
dataRowText);
}
textOutput +=
"</tr>\r\n";
this.Response.Write(textOutput);
}
// Close the HTML table tag...
textOutput =
"</table>\r\n";
this.Response.Write(textOutput);
// Close the Response
stream...
this.Response.Flush();
this.Response.Close();
// this.Response.End();;
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.SuppressContent = true;
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
else
{
//
call your function to show message like this
string msg = "No Records Found to
export";
// bgcolor =
"red";
//DisplayMessage(msg,
bgcolor);
}
}
|
ASP.NET
Introduction
Life Cycle
First Example
Event Handling
ServerSide
ServerSide Controls
CientSide
Basic Controls
Directives
Calendars
State Management
ServerSide Validators
Database Connection
Multiview
MongoDB
JQuery
jquery-history
jquery-example
jquery-selectors
jquery-effects
jquery-hide
jquery-show
jquery-toggle
jquery-fadein
jquery-fadeout
jquery-fadetoggle
jquery-fadeto
jquery-slideup-
jquery-text
jquery-mouseout
mouseup
blur
mouseover
unload
load
mousedown
hover
mouseleave
mouseenter
keyup
keypress
keydown
submit
change
select
focus
bind
width
height
innerheight
outerheight
wrap
serialize
serializearray
events
click
after
insertafter
prev
appendto
clone
remove
"> next-prev-jquery
jquery-detach
jquery-scrolltop
jquery-attr
jquery-prop
jquery-offset
jquery-position
jquery-addclass
jquery-hasclass
jquery-toggleclass
jquery-animate
jquery-delay
jquery-css
jquery-before
jquery-prepend
next-jquery-
loop-through-table
C#
C# Introduction
C#-namespaces
C#-strings
C#-Introduction
C#-history
C#-features
C#-hello world
C#-variable
C#-Variables
C#-data types
C#-operators
C#-reserve keywords
C#-control
C#-control statement-switch
C#-control statement-for loop
C#-control statement-while loop
C#-control statement-do-while loop
C#-control-statement
C#-control statement-continue statement
C#-control statement-goto statement
C#-control statement-comments types
C#-array
C#-passing array to function
C#-multidimensional arrays
C#-trycatch
C#-finally
C#-user defined exceptions
C#-io
C#-streamwriter
C#-streamreader
C#-serialization
C#-deserialization
C#-collections
C#-collections list
C#-collections hashset
C#-collections-sortedset
C#-stack
C#-collection-queue
C#-collections-sorteddictionary
C#-collections-sortedlist
C#-reflection
C#-delegates
C#-multithreading
C#-jagged-arrays
C#-object And class
C#-constructor
C#-destructor
C#-this
C#-static
C#-static-class
C#-static-
C#-static
C#-static constructor
C#-structs
C#-enum
C#-properites
C#-inheritance
C#-aggregation
C#-member-overloading
C#-method-overriding
C#-polymorphism
C#-polymorphism_13
C#-sealed keyword
C#-abstract classes
C#-abstration interface
C#-multithreading
HTML
Introduction
html-title.
doctype-html
html-div-tag.
html-pre-tag
html-code-tag
Introduction
html-label-tag
html-input-tag
tags
formatting
heading
paragraph
anchor
image
table
hr-tag
br-tag
script-tag
noscript-tag
Introductibold-tagon
html5-ntroduction
html-audio-tag
video-tag
canvas-tag
svg
drag-and-drop
marquee
lists
image
table-html
ordered-list
unordered-list
description-list
form-html
textarea
html-quotes
html-style
Java Script