Unable to update excel (.xls) file in WCF deployed on Windows server 2008 R2
This issue is specific to a case, when i am trying to update an existing excel file via WCF. Please note that i am able to read excel files and the issue only occurs when i try to update any excel file. Also, this update logic works perfectly fine on my development environment (WinXP where as production environment is Windows server 2008 R2).
I have tried the steps mentioned in Borgon's Blog (http://hopschwiiz.blogspot.com/2011/02/automating-excel-2007-on-windows-server.html) as well but without any luck.
I am using .Net 3.5, SQL Server 2008 & SL 3.0.
As requested have added the codes...
string[] strArray;
string fileName = null;
System.Array myvalues = null;
Microsoft.Office.Interop.Excel.Application ExcelObj = null;
try
{
fileName = System.Configuration.ConfigurationManager.AppSettings["FileLocation"].ToString();
fileName += "JobDetails.xls";
ExcelObj = new Microsoft.Office.Interop.Excel.Application();
Excel.Workbook theWorkbook = (Excel.Workbook)ExcelObj.Workbooks.Open(fi开发者_Python百科leName, 0, false, 5, "", "", true, Excel.XlPlatform.xlWindows, "", true, false, 0, false, true, false);
Excel.Sheets sheets = theWorkbook.Worksheets;
for (int sheetNum = 1; sheetNum <= sheets.Count; sheetNum++)
{
Excel.Worksheet worksheet = (Excel.Worksheet)sheets.get_Item(sheetNum);
for (int i = 8; i <= 50; i++)
{
Excel.Range range = worksheet.get_Range("A" + i.ToString(), "AI" + i.ToString());
myvalues = (System.Array)range.Cells.get_Value(Type.Missing);
strArray = ConvertToStringArray(myvalues);
if (strArray[1].Equals("PSA Id") && strArray[2].Equals("Member Name") && strArray[3].Equals("Project Name"))
{
int j = i;
worksheet.Cells[j, 5] = Month; // Updated Month in the excel file.
foreach (MemberShift item in listOfJobPlan)
{
j++;
worksheet.Cells[j, 2] = item.MemberID.ToString("D" + 6);
worksheet.Cells[j, 3] = item.MemberName;
worksheet.Cells[j, 4] = inGroupName;
}
break;
}
}
}
}
catch (Exception ex)
{
string Log = "DataService";
if ((!(EventLog.SourceExists(Log))))
EventLog.CreateEventSource(Log, Log);
EventLog logEntry = new EventLog();
logEntry.Source = Log;
logEntry.WriteEntry("Message : " + ex.Message + "\n StackTrace : " + ex.StackTrace, EventLogEntryType.Error);
return false;
}
finally
{
ExcelObj.Workbooks.Close();
}
return true;
Check to see what user the Website is running as and then make sure that user has the appropriate permissions to edit the files.
精彩评论