Click here to Skip to main content
15,215,867 members
   

C#

 
GeneralRe: Killing a process Pin
EliottA8-Jun-09 9:38
MemberEliottA8-Jun-09 9:38 
GeneralRe: Killing a process Pin
CodingYoshi8-Jun-09 9:54
MemberCodingYoshi8-Jun-09 9:54 
AnswerRe: Killing a process Pin
EliottA8-Jun-09 9:36
MemberEliottA8-Jun-09 9:36 
GeneralRe: Killing a process Pin
CodingYoshi8-Jun-09 9:53
MemberCodingYoshi8-Jun-09 9:53 
GeneralRe: Killing a process Pin
EliottA8-Jun-09 9:56
MemberEliottA8-Jun-09 9:56 
GeneralRe: Killing a process Pin
CodingYoshi8-Jun-09 10:00
MemberCodingYoshi8-Jun-09 10:00 
GeneralRe: Killing a process Pin
EliottA8-Jun-09 10:01
MemberEliottA8-Jun-09 10:01 
GeneralRe: Killing a process Pin
CodingYoshi8-Jun-09 10:05
MemberCodingYoshi8-Jun-09 10:05 
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

GeneralRe: Killing a process Pin
EliottA8-Jun-09 10:07
MemberEliottA8-Jun-09 10:07 
GeneralRe: Killing a process Pin
CodingYoshi8-Jun-09 10:19
MemberCodingYoshi8-Jun-09 10:19 
GeneralRe: Killing a process Pin
EliottA8-Jun-09 10:26
MemberEliottA8-Jun-09 10:26 
GeneralRe: Killing a process Pin
CodingYoshi8-Jun-09 10:30
MemberCodingYoshi8-Jun-09 10:30 
GeneralRe: Killing a process Pin
EliottA8-Jun-09 10:36
MemberEliottA8-Jun-09 10:36 
AnswerRe: Killing a process Pin
yunusdemiray8-Jun-09 20:11
Memberyunusdemiray8-Jun-09 20:11 
GeneralRe: Killing a process Pin
CodingYoshi9-Jun-09 3:35
MemberCodingYoshi9-Jun-09 3:35 
QuestionC# Images on Forms Pin
markymarky8-Jun-09 9:08
Membermarkymarky8-Jun-09 9:08 
AnswerRe: C# Images on Forms Pin
Henry Minute8-Jun-09 9:52
MemberHenry Minute8-Jun-09 9:52 
GeneralRe: C# Images on Forms Pin
Luc Pattyn8-Jun-09 10:50
sitebuilderLuc Pattyn8-Jun-09 10:50 
GeneralRe: C# Images on Forms Pin
Henry Minute8-Jun-09 10:56
MemberHenry Minute8-Jun-09 10:56 
GeneralRe: C# Images on Forms Pin
Luc Pattyn8-Jun-09 11:03
sitebuilderLuc Pattyn8-Jun-09 11:03 
GeneralRe: C# Images on Forms Pin
Henry Minute8-Jun-09 12:23
MemberHenry Minute8-Jun-09 12:23 
GeneralRe: C# Images on Forms Pin
Luc Pattyn8-Jun-09 12:31
sitebuilderLuc Pattyn8-Jun-09 12:31 
GeneralRe: C# Images on Forms Pin
Henry Minute8-Jun-09 12:43
MemberHenry Minute8-Jun-09 12:43 
QuestionDeploying Visual c# application on Lan Pin
Akshaylamba8-Jun-09 8:46
MemberAkshaylamba8-Jun-09 8:46 
AnswerRe: Deploying Visual c# application on Lan Pin
Pete O'Hanlon8-Jun-09 9:36
subeditorPete O'Hanlon8-Jun-09 9:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.