Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

 

I am writing a Windows service in C# 4.0.

The application functions as follows:

1) Reads a input stream from some other application

2) Saves the stream in a .tmp file

3) Opens the .tmp in excel object

4) Copies all contents in all worksheet and pastes it as values

5) Save the file

6) Return the .tmp file contents as stream to calling application

 

I am using Excel 2007

 

Well, 90/100 times it works fine, but on few occasions when the execution code hits the Excel.SaveAs(outputFilename), the executionseems to be at stand still. No exception, no alert, nothing.

The Excel instance is seen in the task manager.

 

I am at lost to understand what could be the issue.

 

applicationProcess.Workbooks.Open(outFileName);

excelLogger.writeLogFile("After opening file in Excel");

wrkSht = (Microsoft.Office.Interop.Excel.Worksheet)applicationProcess.Worksheets[1];

excelLogger.writeLogFile("After loading worksheet");

wrkSht.Select();

applicationProcess.CalculateFull();//this method will invoke the Ctrl+Alt+F9 of excel ( i.e execute all formulae in all sheets of excel)

wrkSht.UsedRange.Copy();

excelRng = wrkSht.UsedRange;

excelRng.PasteSpecial(XlPasteType.xlPasteValues, XlPasteSpecialOperation.xlPasteSpecialOperationNone, System.Type.Missing, System.Type.Missing);

excelLogger.writeLogFile("After pasting first sheet's data as value");

wrkSht.Range["A1"].Select();

applicationProcess.Workbooks[1].SaveAs(outFileName.Replace(".tmp","_1.tmp"));

excelLogger.writeLogFile("After Save");

applicationProcess.Workbooks.Close();

 

I am acquiring the excel instance as:

application.Interactive = false;

application.Visible = false;

 

As I mentioned above the code work most of times, but on few occasions the SaveAs call suspends the execution.

There is no exception generated, nothing, it is as if the code is stuck at that line.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...