Aspose word prob


#1

HI There

this is venkata reddy from singapore

actually for mail merge i wrote some in C#, which is working well.
but in cleint place they dont’ want to install msword in server. so i down loaded aspose word.

in my code i gave asposeword dll file referece, i try to change this dll classes. but some classes not there in this dll.

see below code in c#.net

private void MailMerge(object strTemplateName)

{

Word.ApplicationClass WordApp = new Word.ApplicationClass();

//object fileName = “c:/baskaran/merge1.doc”;

object mergefileName =VRmdOutPutFile;// “C:/Inetpub/wwwroot/KKMRTEST/Reminders/RemindersOutput/”+MMFileName;

object oMissing = System.Reflection.Missing.Value;

object oFalse = false;

object readOnly = false;

object isVisible = true;

Word.Document wrdDoc = WordApp.Documents.Open(ref strTemplateName, ref oMissing,ref readOnly, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref isVisible);

Word.MailMerge wrdMailMerge;

wrdMailMerge = wrdDoc.MailMerge;

wrdMailMerge.Destination = Word.WdMailMergeDestination.wdSendToNewDocument;

wrdMailMerge.Execute(ref oFalse);

WordApp.ActiveDocument.SaveAs(ref mergefileName,ref oMissing,ref oMissing,

ref oMissing, ref oMissing, ref oMissing,ref readOnly,

ref oMissing, ref oMissing, ref oMissing, ref oMissing);

wrdDoc.Close(ref oFalse, ref oMissing,ref oMissing);

System.Threading.Thread.Sleep(TimeDelay);

wrdMailMerge = null;

wrdDoc = null;

WordApp.Quit(ref oMissing, ref oMissing,ref oMissing);

WordApp = null;

}

This is with msword reference.
while using asposeword refence i am unable to get all classes like ActiveDocument.SaveAs, Documents.Open.

pls help me in this case.

waiting for your reply
mail me to venkat@gurusoft.com.sg


#2

Aspose.Word has classes similar to the ones found in MS Word object model and their methods and usage is similar, but not exact.

You cannot expect VBA code to compile without changes with Aspose.Word, but you can expect to feel comfortable with Aspose.Word object model if you used to program is MS Word objects.

There are examples in Aspose.Word API Documentation, for example the Document lass.

Also, see the demo projects source code that shows how to do mail merge and other things with Aspose.Word.


#3

HI Mr. Romank

thanks for the reply

i checked exampled code and applied here but not working.

i have one word file which is template ,one data file and one header file.

in mailmerge execute method how to specify my data file and and header file.


pls help me

thanks
kvreddy



#4

I’m not sure what do you mean by “header” file. What does it contain and what do you want to do with it?

To do a mail merge using Aspose.Word you only need a .doc file and some sort of data source such as DataTable, DataSet or an array of values.


#5

Hi Romank

in header file i specified all my field names

my data is in one file, while executing what should i do?
i means that,what are the paramater have to specify?

please follow my files

my templete file
-----------------

OUTSTANDING MEDICAL REPORT

1ST REMINDER

<?xml:namespace prefix = o ns = “urnTongue Tiedchemas-microsoft-comSurprisefficeSurpriseffice” /><oStick out tongue></oStick out tongue>

Date:?SysDate?

<oStick out tongue></oStick out tongue>

Dr. ?DocName?

<oStick out tongue></oStick out tongue>

Department: ?DeptName?

<oStick out tongue></oStick out tongue>

PATIENT’S NAME /HRN

?PatientName?/?HRN?

REQUESTER

?Requester?

REPORT NAME

?ReportName?

DATE REQUESTER SEND TO DOCTOR

?DateRequest?

DUE DATE (COMPLETION REPORT)

?DueDate?


Appreciate if we could have the completed report from you by ?EndDate? as requester is expecting the report from the hospital by ?R1DueDate?

my Data file (txt file)
--------------------

1|info@kkh.com.sg|sham@kkh.com.sg|ongph@kkh.com.sg|Delay in MR Preparation by Docotor|E:\Gurusoft\6000 Projects\6007\6007-01\Reminders\RDOC01|Manual|MR-0038-04|KKH|2004-07-16 00:00:00.000|NAIR SHAMINI|GENERAL OBSTETRICS & GYNAECOLOGY|NIRMALA D/O KANAGASABAI|S6847077C|American International Assurance Co Ltd -Group Hospital & Surgical Claims|ORDINARY MEDICAL REPORT (INSURANCE)|2004-06-29 17:06:59.000|2004-07-16 00:00:00.000|2004-07-16 00:00:00.000|2004-07-20 00:00:00.000
1|info@kkh.com.sg|lnsim@kkh.com.sg|ongph@kkh.com.sg|Delay in MR Preparation by Docotor|E:\Gurusoft\6000 Projects\6007\6007-01\Reminders\RDOC01|Manual|MR-0036-04|KKH|2004-07-16 00:00:00.000|SIM LEE NGOR|GENERAL OBSTETRICS & GYNAECOLOGY|WONG LAI KUIN|A0849022B|OTHERS|ORDINARY MEDICAL REPORT (INSURANCE)|2004-06-29 17:05:32.000|2004-07-16 00:00:00.000|2004-07-16 00:00:00.000|2004-07-20 00:00:00.000
1|info@kkh.com.sg||ongy@kkh.com.sg|Delay in MR Preparation by Docotor|E:\Gurusoft\6000 Projects\6007\6007-01\Reminders\RDOC01|Manual|MR-0039-04|KKH|2004-07-16 00:00:00.000|GOH SHEN LI|GENERAL OBSTETRICS & GYNAECOLOGY|CHUA SIEW FANG|S1669791E|Aviva Limited Healthcare Claims|ORDINARY MEDICAL REPORT (INSURANCE)|2004-06-30 13:18:58.000|2004-07-16 00:00:00.000|2004-07-16 00:00:00.000|2004-07-20 00:00:00.000
1|info@kkh.com.sg|sham@kkh.com.sg|ongph@kkh.com.sg|Delay in MR Preparation by Docotor|E:\Gurusoft\6000 Projects\6007\6007-01\Reminders\RDOC01|Manual|MR-0038-04|KKH|2004-07-16 00:00:00.000|NAIR SHAMINI|GENERAL OBSTETRICS & GYNAECOLOGY|NIRMALA D/O KANAGASABAI|S6847077C|American International Assurance Co Ltd -Group Hospital & Surgical Claims|ORDINARY MEDICAL REPORT (INSURANCE)|2004-06-29 17:06:59.000|2004-07-16 00:00:00.000|2004-07-16 00:00:00.000|2004-07-20 00:00:00.000
1|info@kkh.com.sg|lnsim@kkh.com.sg|ongph@kkh.com.sg|Delay in MR Preparation by Docotor|E:\Gurusoft\6000 Projects\6007\6007-01\Reminders\RDOC01|Manual|MR-0036-04|KKH|2004-07-16 00:00:00.000|SIM LEE NGOR|GENERAL OBSTETRICS & GYNAECOLOGY|WONG LAI KUIN|A0849022B|OTHERS|ORDINARY MEDICAL REPORT (INSURANCE)|2004-06-29 17:05:32.000|2004-07-16 00:00:00.000|2004-07-16 00:00:00.000|2004-07-20 00:00:00.000
1|info@kkh.com.sg||ongy@kkh.com.sg|Delay in MR Preparation by Docotor|E:\Gurusoft\6000 Projects\6007\6007-01\Reminders\RDOC01|Manual|MR-0039-04|KKH|2004-07-16 00:00:00.000|GOH SHEN LI|GENERAL OBSTETRICS & GYNAECOLOGY|CHUA SIEW FANG|S1669791E|Aviva Limited Healthcare Claims|ORDINARY MEDICAL REPORT (INSURANCE)|2004-06-30 13:18:58.000|2004-07-16 00:00:00.000|2004-07-16 00:00:00.000|2004-07-20 00:00:00.000


my header file (txt file)
-------------
VerNo|Femail|ToEmail|ccEmail|Subject|Attachment|Manual|MRID|BOID|SysDate|DocName|DeptName|PatientName|HRN|Requester|ReportName|DateRequest|DueDate|EndDate|R1DueDate

(nothing but which are fields used in my templete file.)

while execute mailmerge , it should generate file with above data.

your example
--------------
doc.MailMerge.Execute( _
New String() {“FullName”, “Company”, “Address”, “Address2”, “City”}, _
New Object() {fullNameEdit.Text, companyEdit.Text, addressEdit.Text, address2Edit.Text, cityEdit.Text})

instead of this code i have to specify data file name, so where should i mention data file name?

or give me your phone no, i can call u .

pls help me , sorry for the trouble. pls.

thanks
kvreddy

#6

You .doc file looks okay.

You need to load the data from the txt file yourself as Aspose.Word does not do that. Depending on the way you want to merge there are two options:

1. Load all data file into a DataTable object and then call MailMerge.Execute(DataTable). This will create a single document which contains result of the merge for every record.

2. Load the file line by line and split every line into field values and call MailMerge.Execute(string[], object[]). This way you can create separate document for each record. You will not load a document or copy it in memory for every record though, becuase mail merge replaces merge fields with data.

Normally, we don’t use header files in Aspose.Word. In your case it would probably be a good idea to read it and p*** to create an array of field names. This will be applicable for both scenarios.

It’s really easy actually, but let me know if you want me to create the actual code. Let me know which way you like it and whether you want C# or VB.NET code.


#7

good suggestion

but my data file is .txt file , how can i create data table with txt file?

if possible can you place code here.

pls help me

thanks
kvreddy


#8

Please place C# code


#9

HI RomanK
i resolved my problem.

thanks for the support.
helped me lot

Regards
kvreddy