Forum Discussion

mireles's avatar
mireles
New Contributor II
8 days ago
Solved

How to save the outputs of ExportCubeViewGridsToExcelFile() to a .xlsx file?

I've tried to implement this function as per the Business Rules Editor snippet:

Dim objByte() As Byte() = BRApi.CubeViews.Process.ExportCubeViewGridsToExcelFile(si, custSubstVarsForAllCubeViews, cubeViewNamesAndVars)

However, I've had a few problems with this, the main one being that I've been unable to save whatever it returns to an Excel file. Here's what I've tried:

Dim fileName As String = "test.xlsx"
Dim filePath As String = $"Documents/Users/{StringHelper.RemoveSystemCharacters(si.UserName,False,False)}"

Dim XFfileDataInfo As New XFFileInfo(FileSystemLocation.ApplicationDatabase,fileName,filePath)
Dim XFfileData As New XFFile(XFfileDataInfo, String.Empty, objByte)
BRApi.FileSystem.InsertOrUpdateFile(si, XFfileData)

Whenever I run this code the output file is an XML. How do I save this to a .xlsx file?

  • Which download button are you using?

    Button 1 downloads in 'OneStream format' i.e. xml. Button 2 downloads in file format eg xlsx

  • MarcusH's avatar
    MarcusH
    Contributor III

    I think you need to tell OS that the file has contents. Try this: 

    Dim fileName As String = "test.xlsx"
    Dim filePath As String = $"Documents/Users/{StringHelper.RemoveSystemCharacters(si.UserName,False,False)}"
    
    Dim XFfileDataInfo As New XFFileInfo(FileSystemLocation.ApplicationDatabase,fileName,filePath)
    XFfileDataInfo.ContentFileContainsData = True
    XFfileDataInfo.ContentFileExtension = XFfileDataInfo.Extension
    Dim XFfileData As New XFFile(XFfileDataInfo, String.Empty, objByte)
    BRApi.FileSystem.InsertOrUpdateFile(si, XFfileData)

     

    • mireles's avatar
      mireles
      New Contributor II

      Hi Marcus, thank you so much for your reply! Unfortunately the file is still being saved as an XML. To clarify, when I download it to my computer it is saved as an XML. When I try to open it from the OneStream file explorer it does open in Excel but with no content.

      • MarcusH's avatar
        MarcusH
        Contributor III

        Which download button are you using?

        Button 1 downloads in 'OneStream format' i.e. xml. Button 2 downloads in file format eg xlsx