Open the excel file after export

Posted by: cvetx on 8 September 2017, 2:07 pm EST

  • Posted 8 September 2017, 2:07 pm EST

    How do ask and open the excel file right after the file is exported?


     Below is my current code.


        Public Sub Excel_Export(ByVal Save_File_Dialog As System.Windows.Forms.SaveFileDialog, ByRef Spread As FarPoint.Win.Spread.FpSpread, ByVal TabName As String)


            Dim lbX As Boolean


            With Save_File_Dialog
               
                .Filter = "Microsoft Excel|*.xls"
                .Title = "Save as Excel"
                .FileName = TabName & Microsoft.VisualBasic.Strings.Replace(Now.ToShortDateString, "/", "")
                .InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments



                If .ShowDialog() = DialogResult.OK Then
                    lbX = Spread.SaveExcel(.FileName, FarPoint.Win.Spread.Model.IncludeHeaders.ColumnHeadersCustomOnly)
                    If lbX = True Then
                        MsgBox("Export Succeeded.!")
                    Else
                        MsgBox("Export Failed.!")
                    End If
                End If


            End With
        End Sub

  • Replied 8 September 2017, 2:07 pm EST

    Hello,

    I made a slight change in your code to save the Spread to Excel using Stream.

            Dim lbX As Boolean
            With Save_File_Dialog
                .Filter = "Microsoft Excel|*.xls"
                .Title = "Save as Excel"
                .FileName = Microsoft.VisualBasic.Strings.Replace(Now.ToShortDateString, "/", "")
                .InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
                If .ShowDialog() = Windows.Forms.DialogResult.OK Then
                    Dim s As New System.IO.FileStream(.FileName, IO.FileMode.OpenOrCreate, IO.FileAccess.ReadWrite)
                    lbX = FpSpread1.SaveExcel(s, FarPoint.Excel.ExcelSaveFlags.NoFlagsSet)
                    s.Close()
                    If lbX = True Then
                        MsgBox("Export Succeeded.!")
                    Else
                        MsgBox("Export Failed.!")
                    End If
                End If
                str = .FileName
            End With

    It more looks like a VB.Net issue , you may refer to the below link for more information on FileStream to open the existing files.

    http://discuss.itacumens.com/index.php?topic=29530.0

    I hope it will help you.

    Thanks,

     

     

  • Replied 8 September 2017, 2:07 pm EST

    Hello,


     


    Since your only requirement is to open the exported file, so you can try this code:


     


          If lbX = True Then
      MsgBox("Export Succeeded.!")


    System.Diagnostics.Process.Start("D:\sample.xls")
                    Else

  • Replied 8 September 2017, 2:07 pm EST

    Thanks. That works.
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels