- #USING MICROSOFT WORD TEMPLATES WITH MULTIPLE PAGES PDF#
- #USING MICROSOFT WORD TEMPLATES WITH MULTIPLE PAGES CODE#
So, how can I use one template document to create multiple word documents at the same time. I have tried opening the template document multiple times (once for each DB record), but this opens a Word dialogue box prompting the user to open the second and subsequent documents as read only (not very elegant) and I get a Word Normal.dotm error when each of the documents is closed.
#USING MICROSOFT WORD TEMPLATES WITH MULTIPLE PAGES CODE#
I have successfully written code that does this for one record where I open a template file and replace items in the template document with DB data. Thank you in advance.I am developing a database application where users open a Word template document and merge this with database records. If (("Something"))Īppreciate any help on this. Object which = WdGoToDirection.wdGoToFirst object count = 0 Long pageCount = doc.ComputeStatistics(.WdStatistic.wdStatisticPages) ((_Application)word).Quit(ref oMissing, ref oMissing, ref oMissing) Īnother attempt on trying to loop and checking whether the current page contains a specific text. word has to be cast to type _Application so that it will find (ref saveChanges, ref oMissing, ref oMissing) Object saveChanges = WdSaveOptions.wdDoNotSaveChanges doc has to be cast to type _Document so that it will find the Close the Word document, but leave the Word application open. Ref oMissing, ref oMissing, ref oMissing, ref oMissing, Ref fileFormat, ref oMissing, ref oMissing, Object fileFormat = WdSaveFormat.wdFormatPDF Object outputFileName = (".docx", ".pdf") .Application word1 = new .Application() Range endRange = (ref what, ref which, ref count2, ref oMissing) ĮndRange.SetRange(startRange.Start, endRange.End - 1) Range startRange = (ref what, ref which, ref count, ref oMissing) Object which = WdGoToDirection.wdGoToFirst Ref oMissing, ref oMissing, ref oMissing, ref oMissing) Ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, Document doc = (ref filename, ref oMissing, Use the dummy value as a placeholder for optional arguments Object filename = (Object)wordFile.FullName Get list of Word files in specified directoryĭirectoryInfo dirInfo = new wordFiles = dirInfo.GetFiles("*.doc") C# doesn't have optional arguments so we'll need a dummy value Create a new Microsoft Word application object
#USING MICROSOFT WORD TEMPLATES WITH MULTIPLE PAGES PDF#
How to make the pdf Landscape and A5 and there will be a page break after each page. How to loop multiple pages in a document? I can extract a single range and create a PDF, but when I try to process multiple ranges, getting the page count it replaces the previous content when used () So my pdf ends up only with a single page.ģ. How to scan if a range has a certain word eg: Banana in our exampleĢ. I had a look at existing threads here and came up with a prototype as shown below. So end of the day you will have a PDF for Banana containing all the Banana details of several months, another PDF for Apples etc. So this program will process multiple documents of several months and create individual PDFs for each product. But a page will only have details about one product. Such as details for Banana, Apples, Oranges etc. For an example, lets say you have multiple product details for each month in a word document. I need to read several word documents each with multiple pages using C# and office Interop libraries, check whether each page contains a specific word, if so add all the pages containing the same word from multiple documents and create a new document and save as a pdf.