Free Support Forum - aspose.com

COM Wrapper for Aspose.Words

As far as I can tell I need a COM Wrapper for Aspose.Words to write ASP code to call Aspose.Words objects to search and replace merge fields, and coded values, inside Word documents. I've completed code in C# that does this, but when I search you site for help on "COM Wrapper" or "CCW" I get very limited results; only one example.

Below I've tried the one example I found, but ASP doesn't like it and the error follows.

<%
'// Open the word document
set objWord = Server.CreateObject("Aspose.Words.Words")
'// License the file
dim AsposeLicenseFile
AsposeLicenseFile = "C:\svn\branch\sg\www\reverse.seattlemortgage.com\Aspose\Aspose.Words.lic"
objWord.SetLicenseCOM AsposeLicenseFile
set doc = objWord.Open("c:\temp\test.doc")
%>

ASP Error Information:
Page: /AsposeCCW/DocUpload.asp
File: /AsposeCCW/DocUpload.asp [6]
Source:
Category: Server object
Description: Server.CreateObject Failed
Number: 0x800401F3 (-2147221005)
ASPCode:ASP 0177
ASPDescription: Invalid class string

Can anyone give me some direction?

Hi,

Actually you do not need to write an additional COM Wrapper as most of Aspose.Words classes and methods are exposed to COM and easily accessed from unmanaged code such as ASP pages. Please read the following article and let me know if it helps:

http://www.aspose.com/Products/Aspose.Words/Api/UtilizeAsposeWordsfromCOMClientsASPVBVBScript.html

Thank you. That's a good starting point.

Question: Is there a seperate set of API References, or documentation, for the Aspose.Words COM Wrapper besides Aspose.Words for .NET and Java?

No. Since Aspose.Words for .NET is involved when working from COM, please refer to the Aspose.Words for .NET documentation. If you have any additional questions, feel free to ask them here.

Thanks Dmitry.

And I do have another question.

Currently, I'm using .NET to replace the VbCrlf, or "\r\n", a.k.a. the "carriage return linefeed", characters with ControlChar.LineBreak and it works perfectly. Now I'm trying to do the same thing in straight ASP. Is there a COM Wrapper equivalent to ControlBreak.LineBreak?

It seems like the chr() function does the job. To insert a line break, use chr(11). You can obtain the values of the control characters in the documentation for the ControlChar class.

Thanks again, Dmitry. Works perfect. I was trying the Chr(13) and Chr(10) with no success.

Great job you guys.

Here's another one for you.

I've been trying to collect and display Merge Fields.

It appears that the document.MailMerge.GetFieldNames method works, but I have NOT been able to collect the output in any kind of ASP array or dim yet. I also have not been able to find any examples using the ComHelper class.

Also, I receive the following error when trying to do a ImportNode: "Wrong number of arguments or invalid property assignment: 'oGlobalDoc.ImportNode'".

Code follows:
For Each srcSection In oNxtDoc
set dstSection = oGlobalDoc.ImportNode(srcSection, True, 0)
oGlobalDoc.AppendChild(dstSection)
Next

I've tried taking the zero off the parameter list, but the I get: "Invalid procedure call or argument: 'oGlobalDoc.ImportNode'".

I could not get it to work either. Based on the information I gathered from the Web, there is some way to overcome the issue by involving ReDim and converting string to variant or something. I’ll try to play with it a bit more and if no luck, I will log it so that we could add a special helper method or overload for COM.

Regarding the second question, I succeeded to get it working this way:

For i = 0 To srcDoc.Sections.Count - 1
Set dstSection = dstDoc.ImportNode(srcDoc.Sections.Item(i), true)
dstDoc.AppendChild(dstSection)
Next

The For loop worked great using Sections.Items(i). Thank you so much.

Having any luck with capturing the MailMerge.GetFieldNames output yet?

Not so far. I would suggest that you look for a workaround in Web, for example here:

http://www.google.com/custom?hl=ru&cof=S%3Ahttp%3A%2F%2Fwww.winfx247.com%2F%3BL%3Ahttp%3A%2F%2Fwww.dotnet247.com%2F247reference%2Fi%2Fglogo.gif%3BLH%3A67%3BLW%3A467%3B&domains=www.dotnet247.com%3Bwww.winfx247.com%3Bwww.adminlife.com&q=string+array+interop+c%23&sitesearch=www.dotnet247.com

It seems like accessing an array of strings returned by a method is a problem in VBScript. So I have logged this as issue #3007 in our defect database so that we could implement a special version of the method for COM clients later.

Thanks.

Thanks Dmitry.

Would JavaScript make any difference?

I'm not sure how you would access Aspose.Words from JavaScript... it is widely used in dynamic HTML pages but honestly I have not heard that it can be leveraged as a COM client language. Please let me know the way if you've succeeded.

Thanks.

Below code still produces the "Type Mismatch" error, but maybe I'm just doing something wrong.

<%@ language="javascript" %>

http://www.w3.org/1999/xhtml" >

Testing Aspose CCW


<%

var BR="
"

Response.Write("HELLO WORLD" + BR)

var objWord = Server.CreateObject("Aspose.Words.ComHelper")
var LicenseFile = "C:\\Program Files\\Aspose\\Aspose.Words\\License\\Aspose.Words.lic"
var License = Server.CreateObject("Aspose.Words.License")
License.SetLicense(LicenseFile)

var doc = objWord.Open("C:\\test\\UploadDocs\\TestMergeFields.doc")

MergeFields = new Array(doc.MailMerge.GetFieldNames)

for (var i = 0; i < MergeFields.length; i++)
{
Response.Write(MergeFields[i] + BR)
}

%>


Oh I forgot it is available in ASP pages… Anyway, I’m not an expert in JavaScript, sorry. Obviously we should implement a better interoperability in the .NET part, at least because the research took that long (and with no luck so far).

Hi Dimtry,

I followed the VBScript example on Aspose.com and successfully called "document.MailMerge.ExecuteADO" through the ComHelper Class, however I'm not able to replace single MergeFields with "document.MailMerge.Execute".

Could this be related to the "GetFieldNames" issue?

Yes, that is probably related to type problem. You can use the following workaround to substitute single merge fields with data:

builder.MoveToMergeField("FieldName")

builder.Write("Some Data")

This code effectively substitutes single merge field with data.

Thanks Vladimir.
This would help if only I could first capture the MergeFields using GetFieldNames.