Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Office Word
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 9-Mar-11 0:59am
Edited 9-Mar-11 22:59pm
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
Comments
Ramalinga Koushik at 27-Jun-11 6:14am
   
Nice Link SA.
SAKryukov at 29-Jun-11 5:50am
   
Thank you, Ramalinga.
--SA
Ramalinga Koushik at 29-Jun-11 23:53pm
   
It's my Pleasure.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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.
  Permalink  
Comments
Ramalinga Koushik at 27-Jun-11 6:15am
   
Good Call Slacker.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
SAKryukov at 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 at 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 R. Bihy at 9-Mar-11 16:53pm
   
I agree, have my 5.
Richard MacCutchan at 10-Mar-11 3:43am
   
Thanks, I'll try and remember to return the favour.
SAKryukov at 9-Mar-11 17:08pm
   
I meant to say "Google for it" would actually be better.
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

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:
// 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);
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 562
1 Sergey Alexandrovich Kryukov 484
2 Maciej Los 325
3 DamithSL 233
4 Mathew Soji 195
0 OriginalGriff 7,168
1 Sergey Alexandrovich Kryukov 6,377
2 DamithSL 5,461
3 Manas Bhardwaj 4,876
4 Maciej Los 4,450


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 21 Feb 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100