Laurence -
Hope you are well. I have been struggling the last few days in getting Aspose.Excel to work in a Windows Form enviroment. I did the sample "Hello World" file and that works with out a problem, but I can not get it to pull data from a databae and then open the file.
Any help you can give would be greatly appreciated. I followed my logic that I do for ASP.Net and still had no luck getting it to work.
Thanks in Advance -
Steven
- Read data from your db and save to a datatable. Then you can use Cells. ImportDataTable method.
2. Open the file with MS Excel:
ProcessStartInfo psi = new ProcessStartInfo(file);
Process.Start(psi);
About 2, VB sample:
Dim psi as ProcessStartInfo = new ProcessStartInfo(file)
Process.Start(psi)
But is there anyway to use a designer file in windows forms? I need to popluate a template file that I already have built. Here is the code I was trying. Its in VB.
Also - It opens my file, and then it dumps all the data (9 rows) in Cell A1:A9 . There should be a total of about 20 columns and it only puts one row of data in A1 and then the second row in A2 etc...
Dim Excel1 As Excel = New Excel
Excel.SetLicense("C:\AsposeL\Aspose.Excel.Lic")
Dim BS_CMD As New SqlCommand
Dim BS_Reader As SqlDataReader
Dim BS_DS As New DataSet
BS_CMD.CommandText = "[Region_Yes_Report]"
BS_CMD.CommandType = System.Data.CommandType.StoredProcedure
BS_CMD.Connection = Me.SqlConnection1
Dim BS_DA As New SqlDataAdapter(BS_CMD)
Try
BS_DA.Fill(BS_DS)
Catch ex As Exception
MessageBox.Show(ex.ToString())
End Try
Dim DT As DataTable = BS_DS.Tables(0)
'Cell1.PutValue(DT)
Dim Sheet As Worksheet = Excel1.Worksheets(0)
Sheet.Cells.ImportDataTable(DT, True, 0, 0)
Sheet.Name = "DataDump"
Excel1.Save("C:\\TestMe.xls", SaveType.Default)
Dim Xcel_Test As ProcessStartInfo = New ProcessStartInfo("C:\\testme.xls")
Process.Start(Xcel_Test)
''''Dim Designerfile As String = "C:\\Reports\Chain_TotalUS.xls"
''''Excel.Open(Designerfile)
''''Dim DT As DataTable = BS_DS.Tables(0)
''''Dim Sheet As Worksheet = Excel1.Worksheets(3)
''''Sheet.Cells.ImportDataTable(DT, True, 0, 0)
'''''Cell1.PutValue(DT)
''''Sheet.Name = "Data"
'''''Excel1.Save("C:\\Chain_TotalUS.xls")
''''Excel1.Save("C:\\TestMe.xls", SaveType.Default)
''''Dim Jack As ProcessStartInfo = New ProcessStartInfo("C:\\testme.xls")
Sure you can open a designer file in a windows form application. You can use Excel.Open method after you initiate Excel object.