ASPOSE.Cells with ASP PAges

Received : 2007/09/26 00:08:49
Message : I am using ASPOSE.Cells to generate .xls files on my server.
I use a template .xls file which contains data markers.
This .xls file needs to be populated using datasource.

Following is the code I am using,

Dim License
Set License = Server.CreateObject("Aspose.Cells.License")
License.SetLicense "C:\Program Files\Aspose\Aspose.Cells\License\Aspose.Total.lic"

Dim objSAXLTmplt
Set objSAXLTmplt = Server.CreateObject("ASPOSE.Cells.WorkbookDesigner")

'--- Use the ExcelTemplate object's Open method to
'--- open the template simpletemplate.xls.

objSAXLTmplt.Workbook.Open_5 Server.MapPath(myTemplate)

'--- Set the template's datasource to the Recordset
'--- returned from the database. DataSource("Recordset")
'--- refers to the recordset specified by the template's
'--- data markers (&=$Recordset.ColumnName).

objSAXLTmplt.SetDataSource_5 myTemplate,(rs)


'--- Generate the spreadsheet, and open it in the browser.
'--- The Process method takes two parameters: the name and
'--- path of the generated spreadsheet, and an optional
'--- process method.


Dim myTempfile, myTempfileFullPath
myTempfile = generateFileName()
myTempfileFullPath = TempDir & myTempfile

'create the file, save it on disk
objSAXLTmplt.Process_3 'myTempfileFullPath, saProcessDefault

Dim stream
set stream = objSAXLTmplt.Workbook.SaveToStream()

Response.Clear
Response.ContentType = "http://gemsdev1.pfizer.com/Excelwriter/vnd.ms-excel"
Response.AddHeader "content-disposition","attachmnet; filename = rp_ReportMeetingPlanningStatus_template1.xls"

Dim bytes
bytes = stream.ToArray()

Response.BinaryWrite(bytes)

Set objSAXLTmplt = nothing

'--- Close Recordset

rs.Close
Set rs = Nothing


conn.Close
Set conn = Nothing


The problem I am facing is that the excel sheet gets generated but it doesnot get populated.
Kindly, suggest me the solution to this.

Thanks,
DOSHIS


This message was posted using Aspose.Live 2 Forum

Hi DOSHIS,

Thanks for considering Aspose.

Since Aspose.Cells does not support to set Recordset object (rs) as a data source for smart markers, so you cannot use in this way. i.e., objSAXLTmplt.SetDataSource_5 myTemplate,(rs), rather you may create multivalued variable(s) (kindly check my previous solution(s) and create your own....i.e. you may create marker(s) like &=$Var1 in the template excel file and in code set the data source like.... xls.SetDataSource_5 "Var1", objectwithvalues) to set it as a data source for the smart markers. In this way the smart markers get populated fine in the output excel file.

Alternatively you may create a wrapper class in .Net using some .Net supported language like (VB.Net) and write all the routines to load the template excel file and set the data source to fill the excel file with data for smart markers. Then register this class and call it in your .asp file. This approach is much easier for debugging too.

Thank you.

We use this line in our code

Response.AddHeader "content-disposition","attachmnet; filename = rp_ReportMeetingPlanningStatus_template1.xls"

In this code line, the filename given is hard coded. Whereas my problem is that my application needs a file name which is dynamically generated at run time and stored in a variable. Can I use this instead of this

Response.AddHeader "content-disposition","attachmnet; filename = myTempFileName"

Trying this it does not take the file name stored in the variable and instead takes myTempFileName as file name.

Can you please provide me with a solution for using a filename which is dynamically generated at run time.

Thank You,

DOSHIS

Hi,

I guess this query has gone un-noticed.

Please provide me with a solution to the doubt regarding ASPOSE.

Also, please let me know if any other clarifications are required from my end.

Thank You,

DOSHIS

Hi DOSHIS,

Thanks for considering Aspose.

Please consult and replace with the following code:

.

.

.

Dim myTempFileName
myTempFileName = "rp_ReportMeetingPlanningStatus_template1.xls"
Response.Clear
'Specify the document type
Response.ContentType = "application/vnd.ms-excel"
'Specify how the document is sent to the browser.
Response.AddHeader "content-disposition","attachment; filename=" & myTempFileName
'Get data bytes from the stream and send it to the response.
Dim bytes
bytes = stream.ToArray()
Response.BinaryWrite(bytes)
Response.End
.

.

Thank you.