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.
'--- 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.
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.
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
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 .