-----------------------------------------------------------
New Message on MumbaiUserGroup
-----------------------------------------------------------
From: cool
Message 2 in Discussion
New Message on MumbaiUserGroup
Problem in running for loop c#
Reply
Reply to Sender
Recommend
Message 1 in Discussion
From:
cool
Hi Guys,
I am writing a code to generate Excel file from a Data Table. In my data table
I am having 9500 rows and and 10 coulmns.
For writing in excel i am running 2 for loop one is for 4500 rows and in that
in that other loop for 10 columns. My problem is for execution of the code is
taking around 8 to 10 min time, which is too much. I am pasting my code below,
please let me know if anyone is having any sugestion in that.
private void GenerateExcelFileFromDataView(DataView oDView)
{
if (hdGenExcel.Value=="Show")
{
if
(File.Exists(Server.MapPath(strEmailExcelFileName)))
{
File.Delete(Server.MapPath(strEmailExcelFileName));
}
// Excel.Application application; //
Declaring variable in type of Excel
// Application
Excel.Application oApplication = new
Excel.Application();
Excel.Workbook book;//Declaring variable in
type of Excel Workbook
Excel.Worksheet sheet;//Declaring variable in
type of Excel WorkSheet
//This is to convert your sysdem data into
Global language.
//It is necessary when your system data in some
other Language.
System.Globalization.CultureInfo oldCI =
System.Threading.Thread.CurrentThread.CurrentCulture ;
System.Threading.Thread.CurrentThread.CurrentCulture =
new
System.Globalization.CultureInfo("en-US");
// This is to add new
excell work book into your new application.
book =
oApplication.Workbooks.Add(Type.Missing);
DataTable odt=new DataTable();
odt=oDView.Table;
sheet = (Excel.Worksheet)book.Worksheets[1];
sheet.Name = "Sheet1";
((Excel.Range)sheet.Cells[1,1]).Value2 ="#";
((Excel.Range)sheet.Cells[1,1]).Font.Bold=true;
((Excel.Range)sheet.Cells[1,2]).Value2 ="CA
Status";
((Excel.Range)sheet.Cells[1,2]).Font.Bold=true;
((Excel.Range)sheet.Cells[1,3]).Value2 ="CA
Date";
((Excel.Range)sheet.Cells[1,3]).Font.Bold=true;
((Excel.Range)sheet.Cells[1,4]).Value2 ="CA
Approval#";
((Excel.Range)sheet.Cells[1,4]).Font.Bold=true;
((Excel.Range)sheet.Cells[1,5]).Value2
="Product";
((Excel.Range)sheet.Cells[1,5]).Font.Bold=true;
((Excel.Range)sheet.Cells[1,6]).Value2
="Description";
((Excel.Range)sheet.Cells[1,6]).Font.Bold=true;
((Excel.Range)sheet.Cells[1,7]).Value2
="Submitter";
((Excel.Range)sheet.Cells[1,7]).Font.Bold=true;
((Excel.Range)sheet.Cells[1,8]).Value2 ="Pages";
((Excel.Range)sheet.Cells[1,8]).Font.Bold=true;
((Excel.Range)sheet.Cells[1,9]).Value2
="Project ID";
((Excel.Range)sheet.Cells[1,9]).Font.Bold=true;
((Excel.Range)sheet.Cells[1,10]).Value2
="Meeting Comments";
((Excel.Range)sheet.Cells[1,10]).Font.Bold=true;
/ for(int i = 1 ; i <= odt.Rows.Count ; i++)
/ {
/ for(int j = 1 ; j < odt.Columns.Count+1
; j++ )
/ {
/ //This is to add the Data which
retrieved from the database into your Excel Sheet.
/ if (j==1)
/ {
/
((Excel.Range)sheet.Cells[i+2,j]).Value2 = i;
/ }
/ else
/ {
/
((Excel.Range)sheet.Cells[i+2,j]).Value2 ="'" +
odt.Rows[i-1].ItemArray[j-1].ToString();
/
/ }
/ }
/
/ }
book.SaveCopyAs(Server.MapPath(strEmailExcelFileName));
book.Close(false,1,1);
oApplication.Quit();
NAR(sheet);
NAR(book);
NAR(oApplication);
GC.Collect();
hdGenExcel.Value="";
oApplication=null;
}
}
PPlease let me know if anyone can suggest me somthing to improve the
performance. I canont put this in aschn. process also, that is my restriction.
Please help if one can.
THanks
Vijay
View other groups in this category.
-----------------------------------------------------------
To stop getting this e-mail, or change how often it arrives, go to your E-mail
Settings.
http://groups.msn.com/mumbaiusergroup/_emailsettings.msnw
Need help? If you've forgotten your password, please go to Passport Member
Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help
For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact
If you do not want to receive future e-mail from this MSN group, or if you
received this message by mistake, please click the "Remove" link below. On the
pre-addressed e-mail message that opens, simply click "Send". Your e-mail
address will be deleted from this group's mailing list.
mailto:[EMAIL PROTECTED]