473,320 Members | 1,965 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Problems working with Word in C#

1
Actually I have encountered several problems working with Word.
Please see if you can help me resolve them.

My application creates documents (Microsoft.Interop.Word.Document) each one according to another template(.dot on the hard disc). Then I have to merge them and save as a single .doc (while the original formatting is saved). I do this in the following way:

Expand|Select|Wrap|Line Numbers
  1. Range rangeTrg = ((Document)(m_WordDocsArr[0])).Content;
  2. object brk = WdBreakType.wdSectionBreakNextPage;
  3. object rngEnd = WdCollapseDirection.wdCollapseEnd;
  4. rangeTrg.Collapse(ref rngEnd);
  5. for (int i = 1; i < m_WordDocsArr.Count; i++)
  6. {   
  7. rangeTrg.InsertBreak(ref brk);
  8. Range rangeSrc = ((Document)(m_WordDocsArr[i])).Content;   rangeTrg.FormattedText = rangeSrc.FormattedText;
  9. rangeTrg.Collapse(ref rngEnd);
  10. }
Problem #1:
If there is one document in m_WordDocsArr, afterwords when I open the .doc by doubleclicking it, Word opens it in Print Layout, if there is more than one document in m_WordDocsArr, Word opens it in Normal layout.
Why?

Problem #2:
The original templates I use have headers and footers.
Somewhy (???) the merged doc has the first document's headers and footers.
I tryed to save the headers and footers of the original docs before merging and assign them afterwords to each section, but the following code throws the exception:

Expand|Select|Wrap|Line Numbers
  1. ArrayList footers = new ArrayList();
  2. ....
  3. footers.Add(((Document)(m_WordDocsArr[i])).Sections.First.Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.FormattedText);
  4. .....
  5. int ih = 0;
  6. foreach (Section sec in ((Document)(m_WordDocsArr[0])).Sections)
  7. {   
  8. sec.Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary].LinkToPrevious = false;   
  9. sec.Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.FormattedText = ((Range)footers[ih]).Duplicate; //exception at run time (could not copy ranges)    ih++;
  10. }
So it is not so trivial for me to merge the documents with their original formatting?????
Please help me !!!???
Thanks a lot.
Sep 23 '08 #1
0 1233

Sign in to post your reply or Sign up for a free account.

Similar topics

18
by: jblazi | last post by:
I should like to search certain characters in a string and when they are found, I want to replace other characters in other strings that are at the same position (for a very simply mastermind game)...
3
by: Greg Andora | last post by:
Hello, I've had an ASP page that worked for at the minimum for a year and now it is acting very odd and I need some help to fix it. What my page does/did is creates a Word.Application object and...
13
by: Peter Jenkins | last post by:
http://www.safenz.org.nz/New/index.htm Only link working off this currently is the sitemap. I have all the access keys going except the skip navigation Please advise if any accessibility issues...
0
by: Raconteur | last post by:
Hi gang, Very sorry if this is in the wrong place, but I am at my wits end with this thing and am in DESPERATE need of some assistance, ANY assistance... I have a Service that I wrote that...
7
by: Timo Haberkern | last post by:
Hi there, i have some troubles with my TSearch2 Installation. I have done this installation as described in http://www.sai.msu.su/~megera/oddmuse/index.cgi/Tsearch_V2_compound_words...
0
by: serkan | last post by:
Guys, I am trying to get this password reset functionality wor for me but I am not successful at all. Please somebody help me. I get "Your password could not be reset - please try again later" so I...
3
by: Acolyte | last post by:
Alright, here's what I'm working on now. It's supposed to go through an inputted list of words, pick out actual words and create a numbered list of them, then, where it finds a number in the list, go...
10
by: Cliff | last post by:
Greetings, I have been trying to teach myself C++ over the past few weeks and have finally came across a problem I could not fix. I made a simple program that prints out a square or rectangle...
1
by: Franske | last post by:
Help! I am developing a Shared Add-in for Word 2003 in Visual Studio .Net 2005. If I build this it is working fine with my Word 2007 version but installing it on my notebook with Word 2003 it is...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.