When loading the stream with loadOptions (where it sets the worskheet indexes), it still loads all the worksheets, and the output pdf contains all three pages, where as I expected only the first sheet. Am I doing anything wrong here:
Dim fileBytes As Byte()
Dim retFileName As String = "OutputFile.pdf"
fileBytes = Function2ReturnFileInByteArray()Dim fileStream As New memoryStream(fileBytes)
'Define a new Workbook.
Dim workbook As Workbook'Set the load data option with selected sheet(s).
Dim dataOption As New LoadDataOption()
dataOption.SheetIndexes = New Integer() {0} '---> ONLY LOAD SHEET 1'Load the workbook with the spcified worksheet only.
Dim loadOptions As New LoadOptions(LoadFormat.Auto)
loadOptions.LoadDataOptions = dataOption
loadOptions.LoadDataOnly = False'Creat the workbook.
workbook = New Workbook(fileStream, loadOptions)'Perform your desired task.
workbook.SaveOptions.SaveFormat = SaveFormat.Pdf
workbook.SaveOptions.CreateDirectory = Trueworkbook.Save(HttpContext.Current.Response, Path.GetFileNameWithoutExtension(retFileName) & ".pdf", ContentDisposition.Inline, workbook.SaveOptions)
'End response to avoid unneeded html after xls
HttpContext.Current.Response.End()
I hav etried removing the sheets that I do not want, and that has worked, but that is a workaround I would not prefer taking, due to the variable number of sheets and the sheet that i would want to be converted to pdf. Why does loadOptions -- SheetIndexes does not work?