hi all,
i m working in desktop application in C#, in which i m using ms word for reports generating. i m getting problem with ms word version means ms office 97, 2000, 2002, 2003, 2007 all behaving with different. as method
WordApp.Documents.Open()
required different no of argument parameter for different version,
how can we use this application usable for all version of ms office without any problem
pls help me thanks
Loading
Amit ChoudharyPosted Dec 7, 2009, 4:43 AM
Hope this helps you...
ishika singhPosted Dec 7, 2009, 3:18 AM
Amit ChoudharyPosted Dec 7, 2009, 3:02 AM
i think you are using some Tool to read the files if you have different namespaces for each DLL and if you are able to read the file info at run time then you can use the checking version and calling the functions of that particular namespace. please tell this information about that...
Optionally you can also try the following code if you are able to read all file using the code then no probs...
Use this program to read the Microsoft Word file.
---------------------
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Microsoft.Office.Interop;
using System.Reflection;
namespace ReadWordFile
{
class Program
{
[STAThread]
static void Main()
{
Microsoft.Office.Interop.Word.ApplicationClass wordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
object file = "C:\\local\\mywordfile.doc"; // Specify path for word file
object nullobj = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Document doc = wordApp.Documents.Open(ref file, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj, ref nullobj);
doc.ActiveWindow.Selection.WholeStory();
doc.ActiveWindow.Selection.Copy();
IDataObject data = Clipboard.GetDataObject();
string allText = data.GetData(DataFormats.Text).ToString();
doc.Close(ref nullobj, ref nullobj, ref nullobj);
wordApp.Quit(ref nullobj, ref nullobj, ref nullobj);
Console.WriteLine(allText);
}
}
}
if you get the problem solved then please mark the answer..
ishika singhPosted Dec 7, 2009, 2:29 AM
WordDoc = new Word.Document();
WordApp = new Word.ApplicationClass();
WordDoc=WordApp.Documents.Open(ref filename, ref missing, ref readOnly,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
WordApp.Visible = true;
if we include reference of ms word XP dll than we open file as
WordDoc=WordApp.Documents.Open(ref filename, ref missing, ref readOnly,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing);
WordApp.Visible = true;
similarly if we include word 2003 dll
than no of paramete inceases
So i want a application which can usable for all type of ms office version,
so which Word DLL reference i should include, or any other method
thanks hope all u understand my prob thanks
Amit ChoudharyPosted Dec 7, 2009, 1:47 AM
Create different overload for all versions of MS word versions in your function
WordApp.Documents.Open();
with their options and you can also do this as
Place first argument in the all functions those are common in all version and then you can put the different types of argument....simple
if it is your answer then please mark it ..... else your welcome for any further queries.