I am having difficulties trying to format my excel export. The header (Motor Parts) is displayed correctly but the column headers are displaying above the motor Parts header. I think it is an issue with iMaxYCoordinate but I can't see a problem.
Code:
#Region "Exports to Excel"
Private Sub btnExportToExcel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExportToExcel.Click
Dim dialog As DialogResult = MessageBox.Show("Are you sure you want to generate the excel?", "Delete confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If dialog = DialogResult.No Then
'Do not generate Excel
Else
'Generate the Excel
Dim oExcelApp As Excel.Application
Dim oWkBk As Excel.Workbook
Dim oSheet As Excel.Worksheet
Dim oRnge As Excel.Range
Dim iMaxXCoordinate As Integer = 0
Dim iMaxYCoordinate As Integer = 0
' Start Excel and get Application object.
oExcelApp = CreateObject("Excel.Application")
oExcelApp.Visible = True
' Get a new workbook.
oWkBk = oExcelApp.Workbooks.Add
oSheet = oWkBk.ActiveSheet
'*************EXPORT MOTOR PARTS TO EXCEL*************
'If motors controllers exist, add that section to excel
If lstMotorController.Count > 0 Then
iMaxYCoordinate = 2
oSheet.Range("A" & iMaxYCoordinate, "I" & iMaxYCoordinate).Merge()
oSheet.Cells(HeaderRow, 1).value = "MOTOR PARTS"
With oSheet.Range("A" & iMaxYCoordinate, "I" & iMaxYCoordinate)
.Font.Bold = True
.Font.Size = "12"
.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter
.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter
.Interior.ColorIndex = 35
End With
End If
' Format A3:I3 as bold, vertical alignment = center.
With oSheet.Range("A" & iMaxYCoordinate, "I" & iMaxYCoordinate)
.Font.Bold = True
.Font.Size = "12"
.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter
.Borders.Color = Color.Black
.Interior.ColorIndex = 35
End With
'Add each motor to the excel
For iCount As Integer = 0 To lstMotorController.Count - 1
iMaxYCoordinate = iMaxYCoordinate + 1
oSheet.Cells(iMaxYCoordinate, PartSections.PartNumber) = lstMotorController.Item(iCount).MotorControllerPartNumber
oSheet.Cells(iMaxYCoordinate, PartSections.Manufacturer) = lstMotorController.Item(iCount).MotorControllerManufacturer
oSheet.Cells(iMaxYCoordinate, PartSections.Description) = lstMotorController.Item(iCount).MotorControllerDescription
oSheet.Cells(iMaxYCoordinate, PartSections.Vendor) = lstMotorController.Item(iCount).MotorControllerVendor
oSheet.Cells(iMaxYCoordinate, PartSections.Quantity) = lstMotorController.Item(iCount).MotorControllerQuantity
oSheet.Cells(iMaxYCoordinate, PartSections.Price) = lstMotorController.Item(iCount).MotorControllerPrice
oSheet.Cells(iMaxYCoordinate, PartSections.ExtPrice) = "=E" & iMaxYCoordinate & "*F" & iMaxYCoordinate
Next
With oSheet.Range("A" & iMaxYCoordinate, "G" & iMaxYCoordinate)
End With
'*****************END EXPORT MOTOR CONTROLLERS TO EXCEL*************
'Add each motor to the excel
For iCount As Integer = 0 To lstMotorDisconnect.Count - 1
iMaxYCoordinate = iMaxYCoordinate + 1
oSheet.Cells(iMaxYCoordinate, PartSections.PartNumber) = lstMotorDisconnect.Item(iCount).MotorDisconnectPartNumber
oSheet.Cells(iMaxYCoordinate, PartSections.Manufacturer) = lstMotorDisconnect.Item(iCount).MotorDisconnectManufacturer
oSheet.Cells(iMaxYCoordinate, PartSections.Description) = lstMotorDisconnect.Item(iCount).MotorDisconnectDescription
oSheet.Cells(iMaxYCoordinate, PartSections.Vendor) = lstMotorDisconnect.Item(iCount).MotorDisconnectVendor
oSheet.Cells(iMaxYCoordinate, PartSections.Quantity) = lstMotorDisconnect.Item(iCount).MotorDisconnectQuantity
oSheet.Cells(iMaxYCoordinate, PartSections.Price) = lstMotorDisconnect.Item(iCount).MotorDisconnectPrice
oSheet.Cells(iMaxYCoordinate, PartSections.ExtPrice) = "=E" & iMaxYCoordinate & "*F" & iMaxYCoordinate
Next
With oSheet.Range("A" & iMaxYCoordinate, "G" & iMaxYCoordinate)
End With
'************END EXPORT MOTOR DISCONNECT TO EXCEL**********
'Add each motor to the excel
For iCount As Integer = 0 To lstProtection.Count - 1
iMaxYCoordinate = iMaxYCoordinate + 1
oSheet.Cells(iMaxYCoordinate, PartSections.PartNumber) = lstProtection.Item(iCount).ProtectionPartNumber
oSheet.Cells(iMaxYCoordinate, PartSections.Manufacturer) = lstProtection.Item(iCount).ProtectionManufacturer
oSheet.Cells(iMaxYCoordinate, PartSections.Description) = lstProtection.Item(iCount).ProtectionDescription
oSheet.Cells(iMaxYCoordinate, PartSections.Vendor) = lstProtection.Item(iCount).ProtectionVendor
oSheet.Cells(iMaxYCoordinate, PartSections.Quantity) = lstProtection.Item(iCount).ProtectionQuantity
oSheet.Cells(iMaxYCoordinate, PartSections.Price) = lstProtection.Item(iCount).ProtectionPrice
oSheet.Cells(iMaxYCoordinate, PartSections.ExtPrice) = "=E" & iMaxYCoordinate & "*F" & iMaxYCoordinate
Next
With oSheet.Range("A" & iMaxYCoordinate, "G" & iMaxYCoordinate)
End With
'************END EXPORT MOTOR protection TO EXCEL**********
Bookmarks