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.

    <span class="Apple-style-span" style="border-collapse:separate;font-family:'MS UI Gothic';font-size:16px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;orphans:2;text-indent:0px;text-transform:none;white-space:normal;widows:2;word-spacing:0px;"><span class="Apple-style-span" style="font-family:Tahoma;font-size:12px;white-space:pre;">http://discuss.itacumens.com/index.php?topic=29530.0</span></span>

    I hope it will help you.

    Thanks,

     

     

  • Replied 8 September 2017, 2:07 pm EST

    <SPAN style="FONT-FAMILY:Verdana;FONT-SIZE:10pt;">Hello,<o:p></o:p></SPAN>


    <SPAN style="FONT-FAMILY:Verdana;FONT-SIZE:10pt;"><o:p> </o:p></SPAN>


    <SPAN style="FONT-FAMILY:Verdana;FONT-SIZE:10pt;">Since your only requirement is to open the exported file, so you can try this code:<o:p></o:p></SPAN>


    <SPAN style="FONT-FAMILY:Verdana;FONT-SIZE:10pt;"><o:p> </o:p></SPAN>


    <SPAN style="FONT-FAMILY:Verdana;FONT-SIZE:10pt;">      If lbX = True Then
      MsgBox("Export Succeeded.!")<o:p></o:p></SPAN>


    <SPAN style="FONT-FAMILY:Verdana;FONT-SIZE:10pt;mso-fareast-language:ZH-TW;mso-bidi-font-family:'Courier New';mso-no-proof:yes;">System.Diagnostics.Process.Start(<SPAN style="COLOR:#a31515;">"D:\sample.xls"</SPAN>)</SPAN><SPAN style="FONT-FAMILY:Verdana;FONT-SIZE:10pt;">
                    Else<o:p></o:p></SPAN>

  • 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