Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
4.33/5 (3 votes)
See more:
I am working on word automation . our system requires open word file and read file content and translate it to another language , then save each content its places.

I am thinking, word file includes pure text , table , and picture so on. how do I know the start position of table, picture as well as pure text section?

I reviewed articles about word automation. most of them about creating document and insert data something like that. when I read data from word file , it return the pure text as well as text in table. I need to read them separate ways with knowing what I am reading now .

what I need to do is : there is a word file ,
first open it
then from the beginning read pure text if there is pure text at beginning, then knowing the content of table if there a table after pure text section. in short I need to read data in sequence and make their content save them exact position.
how could I do that?

let's make my question simple.
if there is doc file, content like this :

//doc file-begin
I am from earch . my name is tom.
tabel1
there is a table before me and after me.
table2

//doc file - end
how can I read the first sentences without reading other parts?
how can do I know I read the first sentences and I am going to read table1?
then, read the second sentences, after that read table?
when I read doc file it returned the entire content of file. I need to read each part sepearatly.
is there somebody have experience in this matter? pls, help?

could any one help me ?

I thank you for your kind help and wait for right answer or tips
Posted
Updated 9-Mar-11 21:59pm
v3

As you're new to the topic, I'm not sure you need exactly Word automation, which is only one approach to Word-related programming. Better start from this point: http://msdn.microsoft.com/en-us/library/ee342218.aspx[^].

—SA
 
Share this answer
 
Comments
[no name] 27-Jun-11 6:14am    
Nice Link SA.
Sergey Alexandrovich Kryukov 29-Jun-11 5:50am    
Thank you, Ramalinga.
--SA
[no name] 29-Jun-11 23:53pm    
It's my Pleasure.
I used the replacing methods, since I don't know how to save the format of word file ,it is better to analys it at sentences level and replace every single sentences by its translation. one more reason is there is no avaiable solution for that perpouse.
 
Share this answer
 
Every MS Office product has an object model. A table in a Word document is nothing more than an object of a class. Google the object model for a Word document and you will see a lot of hits for this...I don't know all of them off the top of my head. I usually do Office Automation through VBA when speaking to other Office products but the new VSTO is supposed to be better.

I also think that SA above provided a great link to look at as well.

Good luck.
 
Share this answer
 
Comments
[no name] 27-Jun-11 6:15am    
Good Call Slacker.
This is quite a big subject and you need to learn about the Interop[^] assemblies and how to get access to the Office types and their subsidiary objects.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 9-Mar-11 15:43pm    
This is a bit too general; and does not hint where to start.
You see, this is not exactly a case where you say "Google for it", so the Question makes sense as it is not clear where to start. You reference is not really helping. So, my 4. Please see my Answer.
--SA
Richard MacCutchan 9-Mar-11 16:28pm    
I did not say "Google for it", I gave a list of MSDN links offering various articles on the subject that the OP needs to understand in order to achieve their objective. I don't see why your one answer is better than any of the ones I offered.
Manfred Rudolf Bihy 9-Mar-11 16:53pm    
I agree, have my 5.
Richard MacCutchan 10-Mar-11 3:43am    
Thanks, I'll try and remember to return the favour.
Sergey Alexandrovich Kryukov 9-Mar-11 17:08pm    
I meant to say "Google for it" would actually be better.
--SA
Hi,

if you already have some kind of translation mechanism then you can do it easily with this C# / VB.NET Word library that doesn't use C# Word Automation.

Here is a sample C# code:
C#
// Use the component in free mode.
ComponentInfo.SetLicense("FREE-LIMITED-KEY");

// Create an input document.
// You don't have to do this if you already have an input document.
// This code is only provided as a reference how input document could look like.
var document = new DocumentModel();
document.Sections.Add(new Section(document, new Paragraph(document, "Hello World!")));
// Instead use:
// Load an input document.
// var document = DocumentModel.Load("Document.docx", LoadOptions.DocxDefault);

// Iterate over all Runs in the document and translate their text.
foreach (Run run in document.GetChildElements(true, ElementType.Run))
	run.Text = TranslateTextSnippet(run.Text);

// Save the document to a file.
document.Save("Document.docx", SaveOptions.DocxDefault);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900