hi...
Excel is not working on IIS server but without IIS is working.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Manj NPosted Aug 10, 2013, 6:48 AM
{
/*************************************
* On export click, select date range
* Generate weekley TimeSheet Report
************************************/
QueryRet Value = new QueryRet();
String StartCalDate;
String EndCalDate;
StartCalDate = ExpCalStart.SelectedDate.ToString();
EndCalDate = ExpCalEnd.SelectedDate.ToString();
if (StartCalDate == EndCalDate)
{
Weekview.SetActiveView(Blank);
lblerr.Text = "Please Select Range of Dates.";
lblerr.Visible = true;
}
else
{
ExcelApp = new Excel.Application();
ExcelApp.Visible = false;
ExcelWork = (Excel._Workbook)(ExcelApp.Workbooks.Add(Missing.Value));
string strCurrentDir = Server.MapPath("~/TimeSheets/");
RemoveFiles(strCurrentDir);//removes all .xls files in directory
DateTime Daylist;
String Query;
/********************************************************
* Select all WeekStartDates in the given range of dates
********************************************************/
Query = "SELECT DISTINCT WeekStartDate FROM TimeSheetBreakDown";
Query += " Where Date >= '" + StartCalDate + "' AND Date<='" + EndCalDate + "'";
ArrayList DistinctStart = Value.ExecuteQry(Query);
if (ExcelWork.Worksheets.Count <= DistinctStart.Count)
{
ExcelWork.Worksheets.Add(Missing.Value, Missing.Value, DistinctStart.Count - ExcelWork.Worksheets.Count + 1, Missing.Value);
}
for (int s = 0; s < DistinctStart.Count; s++)
{
/******************************************************
* For each of the week which come under date selected
* Generate One Excel Work Sheet
******************************************************/
try
{
Query = "SELECT distinct Date FROM TimeSheetBreakDown WHERE (WeekStartDate = '" + DistinctStart[s] + "' AND Day='1') order by date";
Daylist = DateTime.Parse(Value.SelectQry(Query));
/******************************************************************
* From the Distinct StartDate Get (Date of) Monday of that week
* From Monday Calculate other Days From TimeSpan
* ****************************************************************/
mon = Daylist;
tue = Daylist + new TimeSpan(1, 0, 0, 0);
wed = Daylist + new TimeSpan(2, 0, 0, 0);
thu = Daylist + new TimeSpan(3, 0, 0, 0);
fri = Daylist + new TimeSpan(4, 0, 0, 0);
sat = Daylist + new TimeSpan(5, 0, 0, 0);
sun = Daylist + new TimeSpan(6, 0, 0, 0);
}
catch (Exception X)
{
lblerr.Text = X.Message + " Looks like you are Exporting Blank TimeSheet";
lblerr.Visible = true;
}
finally
{
GC.Collect();
/**************************************************************
* Generates one Excel WorkSheet (Gives TimeSheet of that Week)
**************************************************************/
GenerateExcel(s + 1);
}
}
DistinctStartCount = DistinctStart.Count + 1;
SummarySheet();
ExcelApp.Visible = true;
ExcelApp.UserControl = true;
String FileName = "" + User.Identity.Name + ".xlsx";
ExcelWork.SaveCopyAs(strCurrentDir + FileName); /* getting error at this line */
String TimeSheetPath = (String)System.Configuration.ConfigurationManager.AppSettings["TimeSheetPath"].ToString();
string strMachineName = Request.ServerVariables["SERVER_NAME"];
Expgo.Text = "Download TimeSheet";
//TODO: CLean Up...
ExcelApp.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(ExcelRange);
System.Runtime.InteropServices.Marshal.ReleaseComObject(ExcelApp);
System.Runtime.InteropServices.Marshal.ReleaseComObject(ExcelSheet);
System.Runtime.InteropServices.Marshal.ReleaseComObject(ExcelWork);
ExcelSheet = null;
ExcelWork = null;
ExcelApp = null;
GC.Collect();
}
}
Anurag SarkarPosted Aug 10, 2013, 5:47 AM
Paste you code here so we can sort out the code ?
Manj NPosted Aug 10, 2013, 2:30 AM
Manj NPosted Aug 10, 2013, 12:10 AM
so, this is my last question.. please help me...