Name SaveFileDialog is not declared

Hi there

I have just purchased Aspose.cells and am learning. On the first lesson "hello world" I get the above error. Code is pasted form the aspose screen as follows

<%@ Page Language="VB" %>

<%@ Import Namespace="Microsoft.VisualBasic" %>

<%@ Import Namespace="System.Data" %>

<%@ Import Namespace="Aspose.Words" %>

<%@ Import Namespace="Aspose.Cells" %>

<script runat="server">

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)

'Instantiating a Workbook object

Dim workbook As Workbook = New Workbook()

'Adding a new worksheet to the Excel object

workbook.Worksheets.Add()

'Obtaining the reference of the newly added worksheet by passing its sheet index

Dim worksheet As Worksheet = workbook.Worksheets(0)

'Adding a string value to the cell

worksheet.Cells("A1").PutValue("Hello World")

'Adding a double value to the cell

worksheet.Cells("A2").PutValue(20.5)

'Adding an integer value to the cell

worksheet.Cells("A3").PutValue(15)

'Adding a boolean value to the cell

worksheet.Cells("A4").PutValue(True)

'Adding a date/time value to the cell

worksheet.Cells("A5").PutValue(DateTime.Now)

'Setting the display format of the date

worksheet.Cells("A5").Style.Number = 15

'Saving the Excel file

workbook.Save(saveFileDialog1.FileName, FileFormatType.Default)

End Sub

Hi,

If you are using WinForm project in VS.NET, kindly place the SaveFileDialog component from toolbar to form's component tray and name it as "saveFileDialog1". it will work fine.

If you are using ASP.NET project, SaveFileDialog won't be available, so you may change the last line to:

'Save in default format and send the file to user so that he may open the file in
'some application or save it to some location
workbook.Save("Report.xls", FileFormatType.Default, SaveType.OpenInExcel, Response)

Please check:

Thank you.


Sorry - that was silly of me. It is now fixed. Could you now help me with two issues;

1. How do I include the license no in the code so the evaluation statement stops appearing?

2. How can I invoke a dialog box for a "save as" option, and also display the worksheet on the screen?

Thank you

<%@ Page Language="VB" %>

<%@ Import Namespace="Microsoft.VisualBasic" %>

<%@ Import Namespace="System.Data" %>

<%@ Import Namespace="Aspose.Cells" %>

<script runat="server">

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)

'Instantiating a Workbook object

Dim workbook As Workbook = New Workbook()

'Adding a new worksheet to the Excel object

workbook.Worksheets.Add()

'Obtaining the reference of the newly added worksheet by passing its sheet index

Dim worksheet As Worksheet = workbook.Worksheets(0)

'Adding a string value to the cell

worksheet.Cells("A1").PutValue("Hello World")

'Adding a double value to the cell

worksheet.Cells("A2").PutValue(20.5)

'Adding an integer value to the cell

worksheet.Cells("A3").PutValue(15)

'Adding a boolean value to the cell

worksheet.Cells("A4").PutValue(True)

'Adding a date/time value to the cell

worksheet.Cells("A5").PutValue(DateTime.Now)

'Setting the display format of the date

worksheet.Cells("A5").Style.Number = 15

'Saving the Excel file

workbook.Save(Server.MapPath("/reports/test1"), SaveType.OpenInExcel)

End Sub

Thank you for thsi. Sorry I did not see your reply before I sent my second request.

All I need now is, if you can help me invoke the license.

Thanks for your very fats help

By the way I am using ASP.NET 2.0 with VB.Net

Regards

Jonathan

Hi Jonathan,

Please check for how to set license of Aspose.Cells:

No worries :-) Aspose.Cells works fine on any .NET frameworks (1.x, 2.0, 3.x etc.)

Feel free to contact us any time if we can be of any help related to your technical inquies.

Good Day!

Hi Armad

Sorry to keep bugging you. I have got the previous issues sorted out.

I am now trying to access a MS-Access database and collect data for one specific record.

Could you tell me how I should structure the code. On the code below I keep getting an error

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 42:         myCommand.Parameters("@ID").Value = CStr(Request.Form("ID1"))
Line 43:         
Line 44:         worksheet.Cells.ImportFromDataReader(dataReader, True, 0, 0, True)
Line 45:         dataReader = myCommand.ExecuteReader()
Line 46: 

<%@ Page Language="VB" %>

<%@ Import Namespace="Microsoft.VisualBasic" %>

<%@ Import Namespace="System.Data" %>

<%@ Import Namespace="Aspose.Words" %>

<%@ Import Namespace="Aspose.Cells" %>

<script runat="server">

Dim instance As OleDbCommand

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)

'Instantiate an instance of license and set the license file through its path

Dim license As Aspose.Cells.License = New Aspose.Cells.License()

license.SetLicense("Aspose.Cells.lic")

Dim myCommand As OleDbCommand

Dim dataReader As System.Data.OleDb.OleDbDataReader = Nothing

'Instantiating a Workbook object

Dim workbook As Workbook = New Workbook()

'Adding a new worksheet to the Workbook object

workbook.Worksheets.Add()

'Obtaining the reference of the newly added worksheet by passing its sheet index

Dim worksheet As Worksheet = workbook.Worksheets(0)

'Adding a string value to the cell

worksheet.Cells("A1").PutValue("Test Report")

'Adding a date/time value to the cell

worksheet.Cells("D1").PutValue(DateTime.Now)

'Setting the display format of the date

worksheet.Cells("D1").Style.Number = 15

Dim connection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("/fpdb/passliabcapture.mdb"))

connection.Open()

myCommand = New OleDbCommand("SELECT ID, Surname, RunDate, ActionDate, Description, TransType, Fin_TotalMnthPremium, Rejecteddebit, Cashdebitraised, Balance, EscapeFileNo FROM [trans] WHERE [ID] = @ID", connection)

'Importing the contents of the data reader to the worksheet

myCommand.Parameters.Add(New OleDbParameter("@ID", OleDbType.VarChar, 200))

myCommand.Parameters("@ID").Value = CStr(Request.Form("ID1"))

worksheet.Cells.ImportFromDataReader(dataReader, True, 0, 0, True)

dataReader = myCommand.ExecuteReader()

'Saving the Excel file

workbook.Save("Report.xls", FileFormatType.Default, Aspose.Cells.SaveType.OpenInExcel, Response)

End Sub

Hi,

Please make sure that dataReader object should be filled properly with records first before using the ImportFromDataReader method.

Please interchange the line of code i.e.,

.

.

dataReader = myCommand.ExecuteReader()

worksheet.Cells.ImportFromDataReader(dataReader, True, 0, 0, True)

'Saving the Excel file

workbook.Save("Report.xls", FileFormatType.Default, Aspose.Cells.SaveType.OpenInExcel, Response)

Thank you.

Thanks it works now