|
Luc Pattyn wrote: AFAIK there ever is only one Excel process
You can use the .IgnoreRemoteRequests = true property to force excel to open in multiple instances for each workbook, so sometimes you would need a loop.
My question is if he opens excel in his code to generate reports, there is no need to terminate them abnormally, especially when a client may have unrelated excel instances open unrelated to his code. He can simply terminate them through his code by using .quit, can't he?
|
|
|
|
|
No, there are actually separate processes created. Excel 2003
CodingYoshi
Visual Basic is for basic people, C# is for sharp people. Farid Tarin '07
|
|
|
|
|
Why don't you just quit the excel instance through your code?
|
|
|
|
|
I tried Quit() along with setting it to null but the process still existed. Any other idea?
I am thinking of logging the time my app starts and then checking the start time of each process. If the start time is bigger than start time of app and created by the same user then I will kill it. But it is still possible, the user opened an excel file outside my app while my app is active so this is not the best solution.
CodingYoshi
Visual Basic is for basic people, C# is for sharp people. Farid Tarin '07
|
|
|
|
|
Did you try something along the lines of
Where _excelApplication = Excel.Application
_excelApplication.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(_excelApplication);
?
|
|
|
|
|
Just did both quit and ReleaseComObject methods but still there.
CodingYoshi
Visual Basic is for basic people, C# is for sharp people. Farid Tarin '07
|
|
|
|
|
Without seeing your code I'd say your out of luck.
|
|
|
|
|
Hope you can follow it through since I have written it in VB.NET.
This is just a wrapper. The parts which might be of interest to you are the constructor and the Create method.
Public Class ExcelBook
Implements IObservable
Private _parameters As Parameters
Private _repoHelper As RepositoryHelper
Private _sheets As Dictionary(Of String, Worksheet)
Private _workBook As Workbook
Private _xlApp As Application
Private _summarySheet As ExcelSheet
Public Sub New(ByVal params As Parameters)
Me._xlApp = New Application()
Me._workBook = Me._xlApp.Workbooks.Add()
Me._repoHelper = Nothing
Me._sheets = New Dictionary(Of String, Worksheet)(53)
Me._parameters = params
End Sub
Private Sub DeleteDefaultSheets()
Dim DeadSheet As Worksheet
DeadSheet = Me._workBook.Sheets("Sheet1")
DeadSheet.Delete()
DeadSheet = Me._workBook.Sheets("Sheet2")
DeadSheet.Delete()
DeadSheet = Me._workBook.Sheets("Sheet3")
DeadSheet.Delete()
End Sub
Public Sub Create()
Me.CreateRepositories()
Dim xSheet As ExcelSheet = Nothing
Dim sheetSpecs As Sheet = Nothing
Dim wSheet As Worksheet = Nothing
' If the report has a detail sheet and range is multiple for month or week or season then provide detail sheet specs to
' ExcelSheet constructor to create sheets with specification of the detail sheet
' First sheet must be reserved for the summary sheet
' After all detail sheets are finished, a summary sheet must be created.
Dim stepInfo As New StepEventArgs()
If (Me._parameters.Report.HasDetailSheet And Me._parameters.IsMultipleRanges) Then
' Details Sheets
sheetSpecs = Me._parameters.Report.DetailSheet
For Each repo As KeyValuePair(Of String, Repository) In Me._repoHelper
wSheet = CType(Me._workBook.Worksheets.Add(), Worksheet)
wSheet.Name = repo.Key
xSheet = New ExcelSheet(wSheet, sheetSpecs, repo.Value, False, Me._parameters, Me._workBook)
xSheet.Fill()
Me._sheets.Add(repo.Key, xSheet.SpreadSheet)
stepInfo.Message = repo.Key & " completed."
RaiseEvent StepCompleted(Me, stepInfo)
Next
Me.DeleteDefaultSheets()
' All detail sheets are done now do the summary
Dim repositoryTemplate As Repository = Nothing
For Each repo As KeyValuePair(Of String, Repository) In Me._repoHelper
repositoryTemplate = repo.Value
Exit For
Next
wSheet = CType(Me._workBook.Worksheets.Add(), Worksheet)
wSheet.Name = "Summary"
' Summary Sheet
sheetSpecs = Me._parameters.Report.SummarySheet
xSheet = New ExcelSheet(wSheet, sheetSpecs, repositoryTemplate, True, Me._parameters, Me._workBook)
Me._sheets.Add("Summary", xSheet.SpreadSheet)
Me._summarySheet = xSheet
Me._summarySheet.Fill()
stepInfo.Message = "Summary sheet completed."
RaiseEvent StepCompleted(Me, stepInfo)
Else ' Report has only one sheet
sheetSpecs = Me._parameters.Report.SummarySheet
wSheet = CType(Me._workBook.Worksheets.Add(), Worksheet)
Me.DeleteDefaultSheets()
wSheet.Name = "Summary"
xSheet = New ExcelSheet(wSheet, sheetSpecs, Me._repoHelper.Repository, False, Me._parameters, Me._workBook)
xSheet.Fill()
Me._sheets.Add("Summary", xSheet.SpreadSheet)
stepInfo.Message = "Summary sheet completed."
RaiseEvent StepCompleted(Me, stepInfo)
End If
Dim path As String = My.Settings.FilePath & "Report - " & Now.Hour.ToString() & "-" & Now.Minute.ToString() & Me._parameters.Div.ToString() & ".xls"
'path = Me._workBook.Name
Me.FreezeColumns(Me._sheets("Summary").Range("C8:C8"))
Me._workBook.SaveAs(path, Excel.XlFileFormat.xlExcel9795)
Me._xlApp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(Me._xlApp)
'Me._xlApp.DisplayAlerts = True
'Me._xlApp.ScreenUpdating = True
'Me._xlApp.Visible = True
End Sub
Private Sub AddToSummarySheet(ByVal spreadSheet As ExcelSheet)
' Ask the sheet to give you its formula in a dictionary for each column and row
End Sub
Private Sub CreateRepositories()
If (Me._parameters.TypeOfReport = ReportTypes.Year_To_Date_Weekly) Then
Me._repoHelper = New RepositoryHelperWeekly()
Me._repoHelper.CreateRepositories(Me._parameters)
End If
If (Me._parameters.TypeOfReport = ReportTypes.Year_To_Date_Monthly) Then
Me._repoHelper = New RepositoryHelperMonthly()
Me._repoHelper.CreateRepositories(Me._parameters)
End If
If (Me._parameters.TypeOfReport = ReportTypes.Year_To_Date_Seasonal) Then
Me._repoHelper = New RepositoryHelperSeasonally()
Me._repoHelper.CreateRepositories(Me._parameters)
End If
End Sub
Private Sub FreezeColumns(ByVal range As Range)
range.Select()
Me._xlApp.ActiveWindow.FreezePanes = True
End Sub
Public Event StepCompleted(ByVal sender As Object, ByVal e As StepEventArgs) Implements IObservable.StepCompleted
End Class
CodingYoshi
Visual Basic is for basic people, C# is for sharp people. Farid Tarin '07
|
|
|
|
|
next time, post your question in the vb.net forums, it really helps to know what language you are dealing with.
Secondly, use the pre tags.
Thirdly, this is how I did it (in vb.net)
Public Sub Terminate()
If _excelApplication IsNot Nothing Then
_excelApplication.DisplayAlerts = False
_excelApplication.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(_excelApplication)
_excelApplication = Nothing
_excelApplication.Finalize()
End If
End Sub
jeez.
|
|
|
|
|
Sorry about that. The reason I posted it here is because I did not think it will get to the point where I need to post code.
Still no luck. The process exists after doing all of the above.
EliottA wrote: Thirdly, this is how I did it (in vb.net)
You mean it worked for you? Finalize() is not a member of Excel.Application.
CodingYoshi
Visual Basic is for basic people, C# is for sharp people. Farid Tarin '07
|
|
|
|
|
Sorry, did not mean to throw that line in there.
CodingYoshi wrote: he reason I posted it here is because I did not think it will get to the point where I need to post code.
Still belongs in the VB.Net forum.
CodingYoshi wrote: The process exists after doing all of the above.
Err....ummm....does the process exist before execution...?
|
|
|
|
|
No, I manually check to make sure no process exists before the execution and I also kill all the instances programmatically just to reassure using this code:
foreach (Process p in Process.GetProcessesByName("EXCEL"))
{
p.Kill();
}
CodingYoshi
Visual Basic is for basic people, C# is for sharp people. Farid Tarin '07
|
|
|
|
|
Again that is horrible design, what if a client has excel running?
Create a new instance of excel, and set it's IgnoreRemoteRequests property to true, this will cause *your* instance of excel to operate under a new process.
|
|
|
|
|
How do you create excell processes?
System.Diagnostics.Process.Start("...") Something like that? If so save the process that you create.
List<Process> list = new List<Process>();
Process p = System.Diagnostics.Process.Start("...");
list.Add(p);
...
list[i].Kill();
|
|
|
|
|
No, the problem is to make excel spreadsheets you have to create a new instance of the application class and add workbooks to it. This creates a process and I am trying to kill the process which I created but no luck so far. Here is the snippet:
public void Constructor(Parameters params)
{
this._xlApp = New Application(); // This is the process I want to kill once I am finished creating the file.
this._workBook = Me._xlApp.Workbooks.Add();
this._repoHelper = null;
this._sheets = New Dictionary<String, Worksheet>(53);
this._parameters = params;
}
CodingYoshi
Visual Basic is for basic people, C# is for sharp people. Farid Tarin '07
|
|
|
|
|
Hi,
I'm kind of new to programming and to c# about 18 months c# and twice that with vba with bits of javascrip and, vbscript... and a hobbyist so it sounds a lot but it isn't!
Anyways I have never used images before in programming other than to swap a picture given a value in the code.
I now want to be able to have an image on a windows form that you can left click and a dialogue box appear that shows the position in pixels the mouse is on the image.
To be honest I'd be happy with just that. BUT really on the picture I want to have (probably the wrong word) but 'hotspots'/hot areas.
I am designing a form to be able to record where on a person has an injury. I want the user to be able to click say on the left shoulder of the person on the image and the program know that the user clicked on the left shoulder at the image pixel count of (100, 100) for example.
Would it be best to do this thru a browser displayed image that has a javascript script running on it and embedding in it somehow position (left shoulder) the user has clicked?
The reason why I want need the pixel count is because the results will be shown on a website.
Am I attempting too much? Could somebody please give me some direction?
Thank you in advance,
Mark
|
|
|
|
|
Take a look at The Hot Spot .NET Control[^], to see if it gives you any ideas.
A friend of mine did an application for Bronchoscopy using similar techniques in VB 3.0 some time ago.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Henry Minute wrote: in VB 3.0 some time three decades ago
ftfy
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
You exaggerate!
It was only about 13(ish) years ago.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Henry Minute wrote: about 13(ish) years ago
30(ish)?
it's all in the articulation
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Luc Pattyn wrote: it's all in the articulation
Since it featured a diagram of the human body, there was some degree of articulation, certainly.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Come to realize VB3.0 probably is more 13ishish, real PCs[^] not being around for 30 years yet.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Yes, it was about 1995-7, and given that it was VB, it was actually quite a nice app.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi
Actually I made a visual C# application & want it to Run on LAN with a Centralized database server so that my People can use the database situated at server from their client through a Client C# Application. How Can I do so.
is it simply making the setup file & then deploying into network machines....or is it some thing else...
regards
AKshay
Akshay Deep Lamba
|
|
|
|
|
Akshaylamba wrote: so that my People
Isn't that a bit Messianic?
You don't need to deploy your application on the LAN to use a database on the LAN.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|