Free Support Forum - aspose.com

ASPOSE.Words in ASP

Received : 2007/10/09 05:28:29
Message : Hi,

I am using ASPOSE.Words in ASP page.
I have written the following code:

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

Dim WordTempl
Set WordTempl = Server.CreateObject("Aspose.Words.ComHelper")

'==Set WordTempl = Server.CreateObject("SoftArtisans.WordTemplate")

WordTempl.Open Server.MapPath("WordWriter/complianceviolationform.doc")
WordTempl.SetDataSource_1 "short_name", NAME
..........


in replacement to the following code:



NamesArr = Array("short_name","program_name","location","date_of_incident","meeting_event","agency","contact_host","meeting_planner","products","status","incident_to_report","cv_type","other","action_taken","cv_group")
ValuesArr = Array(NAME, PROJECTNAME,location,VIOLATION_DATE,MENAME,AGENCY,SPONSOR,PLANNER,PRODUCTS,CVStatus,DESCRIPTION,compliance,VIOLATION_OTHER,COMMENTS,VIOLATION_GROUP)

Set WordTempl = Server.CreateObject("SoftArtisans.WordTemplate")

WordTempl.Open Server.MapPath("WordWriter/complianceviolationform.doc")

WordTempl.SetDataSource ValuesArr, NamesArr


It gives me an error stating that SetDataSource is an invalid property. I have even tried SetDataSource_3, SetDataSource_5 and SetDatasoURCe_1
but it gives me the same error.

Please help me know the reason for this.
And also please look into the other changes I have done, and let me know in case of any errors found from your side.

THanks,
DOSHIS


This message was posted using Aspose.Live 2 Forum

Hi

Thanks for your request. If you want to perform mail merge then you can use the following code.

Dim convention_name

Dim city_name

Dim full_name

Dim PHONE_NUMBER

Dim Title

Dim Special

convention_name = "George"

city_name = "Washington"

full_name = "George Bush"

PHONE_NUMBER = "654646464"

Title = "Test"

Special = "1"

Dim helper

Set helper = CreateObject("Aspose.Words.ComHelper")

Dim Doc

Set Doc = helper.Open("E:\Projects\Aspos.words\Tests\TestTwo\bin\115_88619_AjayDeshmukh\site2\in.doc")

'Create new RecordSet

Dim rsParam

Set rsParam = CreateObject("ADODB.Recordset")

rsParam.Fields.Append "ConventionName", CInt(129), CInt(40), False

rsParam.Fields.Append "ConventionCity", CInt(129), CInt(40), False

rsParam.Fields.Append "SpecialInstructions", CInt(129), CInt(40), False

rsParam.Fields.Append "ConventionManagerName", CInt(129), CInt(40), False

rsParam.Fields.Append "ConventionManagerTitle", CInt(129), CInt(40), False

rsParam.Fields.Append "ConventionManagerPhone", CInt(129), CInt(40), False

rsParam.Open

'Fill RecordSet

rsParam.AddNew Array("ConventionName", "ConventionCity", "SpecialInstructions", "ConventionManagerName", "ConventionManagerTitle", "ConventionManagerPhone"), Array(convention_name,city_name, Special,full_name, Title, PHONE_NUMBER)

'Execute MeilMerge

Doc.MailMerge.ExecuteADO rsParam

'Save document

doc.Save "E:\Projects\Aspos.words\Tests\TestTwo\bin\115_88619_AjayDeshmukh\site2\out1.doc"

rsParam.Close()

I hope that it will help you.

Also, attach your template for testing.

Best regards.

Hi There,

Thanks for the reply.

But I am in a bit of doubt, as I will be using Datasource, Recordset to fill the word document on a button click event.

I am attaching the asp file I am using and the Word template documnet which needs to be filled on button click event and saved with a different file name. File name is generated in the code name it self.

Please let me know the changes I need to do in my file.

I tried my code (which I had previously sent) and also I am trying your code. But there is a slight confusion.

Please help me with this.

Waiting for your reply ASAP.

Thanks,

DOSHIS

Hi

Thanks for additional information. Try to use the following code to achieve what you want.

Dim NamesArr

Dim ValuesArr

Dim WordTempl

Dim helper

Set helper = CreateObject("Aspose.Words.ComHelper")

Dim rsParam

Set rsParam = CreateObject("ADODB.Recordset")

rsParam.Fields.Append "short_name", CInt(129), CInt(40), False

rsParam.Fields.Append "program_name", CInt(129), CInt(40), False

rsParam.Fields.Append "location", CInt(129), CInt(40), False

rsParam.Fields.Append "date_of_incident", CInt(129), CInt(40), False

rsParam.Fields.Append "meeting_event", CInt(129), CInt(40), False

rsParam.Fields.Append "agency", CInt(129), CInt(40), False

rsParam.Fields.Append "contact_host", CInt(129), CInt(40), False

rsParam.Fields.Append "meeting_planner", CInt(129), CInt(40), False

rsParam.Fields.Append "products", CInt(129), CInt(40), False

rsParam.Fields.Append "status", CInt(129), CInt(40), False

rsParam.Fields.Append "incident_to_report", CInt(129), CInt(40), False

rsParam.Fields.Append "cv_type", CInt(129), CInt(40), False

rsParam.Fields.Append "other", CInt(129), CInt(40), False

rsParam.Fields.Append "action_taken", CInt(129), CInt(40), False

rsParam.Fields.Append "cv_group", CInt(129), CInt(40), False

rsParam.Open

NamesArr = Array("short_name","program_name","location","date_of_incident","meeting_event","agency","contact_host","meeting_planner","products","status","incident_to_report","cv_type","other","action_taken","cv_group")

ValuesArr = Array(NAME, PROJECTNAME,location,VIOLATION_DATE,MENAME,AGENCY,SPONSOR,PLANNER,PRODUCTS,CVStatus,DESCRIPTION,compliance,VIOLATION_OTHER,COMMENTS,VIOLATION_GROUP)

rsParam.AddNew NamesArr, ValuesArr

Set WordTempl = helper.Open(Server.MapPath("WordWriter/complianceviolationform.doc")

‘Fill template

WordTempl.MailMerge.ExecuteADO rsParam

rsParam.Close()

Dim stream

Set stream = CreateObject("System.IO.MemoryStream")

WordTempl.Save_4 stream, 1

Response.Clear

'Specify the document type.

Response.ContentType = "application/msword"

'Other options:

'Response.ContentType = "text/plain"

'Response.ContentType = "text/html"

'Specify how the document is sent to the browser.

Response.AddHeader "content-disposition","attachment; filename=MyDocument.doc"

'Another option could be:

'Response.AddHeader "content-disposition","inline; filename=MyDocument.doc";

'Get data bytes from the stream and send it to the response.

Dim bytes

bytes = stream.ToArray()

Response.BinaryWrite(bytes)

Response.End

I hope that it will help you.

Best regards.