This issue applies to the COM version of the ExcelApplication object as well as the .NET wrapper class (SAExcelApplicationDotNet). ExcelWriter COM automatically selects the first Worksheet in a Workbook when saving if it detects that there are no sheets currently selected in the file. However, this detection is not always accurate. ExcelWriter COM will preserve Chartsheets, but cannot tell whether one is selected. When determining whether any sheets are selected, it only looks at Worksheets, not Chartsheets. Therefore, if a Chartsheet is selected but no Worksheets are, ExcelWriter thinks there are no sheets selected and will select the first Worksheet.
A workaround for this issue is to use VBA macro code in the Excel Workbook to select the desired Chartsheet, which will cause all other Worksheets and Chartsheets to be deselected. For example, to select the first Chartsheet and deselect all other sheets:
Private Sub Workbook_Open()
Dim chart1 As Chart
Set chart1 = ActiveWorkbook.Charts(1)
chart1.Select
End Sub
This is not an issue with ExcelWriter .NET or Java, which both have full Chartsheet support. |