Link to home
Start Free TrialLog in
Avatar of expertsexchangehunter
expertsexchangehunter

asked on

Save an Excel Spreadsheet from vb.net

I have a vb.net web app that creates  an Excel spreadsheet. I need to save the spreadsheet then open and display the spreadsheet and delete the file.
I have already coded everyhining but the save, open and display and delete.
The problem with this is besides creating the file it also creates a file like
34D6A000
that contains the spreadsheet also. This is niot wanted becasse when I want to delete the spreadsheet I won't know the files name to delete.
I need the missing code.

Thanks

With myExcel
                .SheetsInNewWorkbook = 1
                myExcelWB = .Workbooks.Add()
                myExcelWS = myExcelWB.Worksheets(1)
                'TO Display the column name in the the excel file.   
                For intColumn = 0 To ds.Tables(0).Columns.Count - 1
                    myExcelWS.Cells(1, intColumn + 1).Value = ds.Tables(0).Columns(intColumn).ColumnName.ToString
                Next
                'For displaying the column value row-by-row in the the excel file.         
                For intRow = 0 To ds.Tables(0).Rows.Count - 1
                    For intColumnValue = 0 To ds.Tables(0).Columns.Count - 1
                        myExcelWS.Cells(intRow + 2, intColumnValue + 1).Value = ds.Tables(0).Rows(intRow).ItemArray(intColumnValue).ToString
                        '                        myExcelWS.Cells(intRow + 1, intColumnValue + 1).Value = ds.Tables(0).Rows(intRow).ItemArray(intColumnValue).ToString
                    Next
                Next
                Dim dtmWorkDate As System.DateTime
 
                strFileName = "ExcelFile_" + fileNameUndex & ".xls"
 
                strFilePath = Application("PDF_Physical_FilePath")
                strExcelFile = strFilePath & strFileName
 
                .ActiveWorkbook().SaveAs(strExcelFile)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Wayne Taylor (webtubbs)
Wayne Taylor (webtubbs)
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial