I have some C# code that merges one file into yet another. It it is a quite straight ahead process:
In my project I utilize this code twice. The 1st opportunity I produce a data that has to do with 300 webpages long, That opportunity it operates great.
The only remedy i can easily think about is actually to experience the brand new data and also apply types once again.
The second time is considerably larger – the resulting documents mores than 15,000 webpages long – and during that scenario the trouble occurs. The paragraph styling is actually all lost – all paragraphs come via as Ordinary. (What I appreciate is header paragraphs sustaining their “Header 1” or even “Header 2” or “Header 3” classifications.
the problem still accompanies the larger documents (yet with the smaller files it works fine – the styles persist after the insertfile(). thanks for the referral regarding the second documents. Since yesterday I also made an effort carrying out a wildcard find/replace – which functions utilizing word on my personal computer. Doing it with find object in interop fails (only along with the big reports) – I receive an exception information that the service is actually not available. My latest try out is actually knotting through the paragraphs and also applying styles as required through message information – works yet extremely sluggish. Still searching for a much better means.
I trying out documents sizes a little bit of but gave up after still obtaining the trouble at 5,000 web pages. Your recommendation to use the WordOpenXML SDK was actually outstanding. The combine currently possesses 2 actions – I merge the data making use of Word OpenXML, and also then I use word interop to improve the tabulation (which belongs to why i need the heading designs). Looping with all paragraphs functions – however consumes 6 hrs to finish, and also I need to have to keep doctor active or even I get “item erased” wreck (your messages somewhere else helped on that particular exception). New process takes approximately 40 moments. TOC takes most opportunity
In each situations file1 coincides, as well as the insertfile is generated elsewhere using word interop – and also the code that generates those file coincides as the code in both the much smaller and also bigger models. The file characteristics as well as the attributes of the material is all the very same – yet I lose the “Header” types in the greater model.
Based on the comment from C. Meister over I attempted OpenXML, which was actually excellent. – utilizing OpenXML. And also the second opens the document in word interop, updates the Table of Material as well as establishes some environments the way I wish them, and conserves the file.
Pinvoke mentiones the AccessibleObjectFromWindow signature. That being pointed out, the resulting available object performs not give me along with far more information than the method presently does.
Having actually carried out a fair little bit of first analysis, I believe what is actually demanded is the Windows Ease Of Access API.
As you’ll observe in the comments above I made an effort numerous points. A functioning service was to loophole by means of all paragraphs and also replace styles located on a wildcard match. Performing that required being sure the document remained energetic (I carried out that by including a trigger line in the loophole). It took over 6 hours to accomplish – which was actually certainly not realistic.
Yet you can open this huge documents in Word as well as the styles are kept? A feasible faster technique would be actually to break this up right into smaller files just before importing. An additional feasible method that is actually possibly a LOT much faster would certainly be actually to leverage the WordOpenXML report layout, utilizing the Open XML SDK to carry out this job as opposed to the “interop”.