Hi Stack overflow Gurus
I'm trying to help my work automate some of the things we do here.
Scenario,
We work with excel a lot (dealing with tons of number). When all calculations are done, we have a word document we need to copy some of the numbers/ other info to. This document is then shared.
Hope,
I want to create an Add-in in Excel such that once the calculations are done for any of the spreadsheets, anyone on the team should just be able to click a button in the toolbar to auto-create the final document. (I would like it to open the file browser, so we can pick from different templates)
My basic knowledge,
Using bookmarks in the word template seems to be the way to go for creating tags to eventually replace.
I want the add-in to be installed in Excel
I have been reading up on Office Web add-ins, VSTO, VBA and not entirely sure which to go with. What i have learned so far
VBA seems to be at the document level, but i want this to be an add-in as it will apply to different external spreadsheets we will be getting. Not sure if my research is fully accurate though.
I am thinking I will have to use VSTO or the new Web add-ins. I'm not entirely sure if the new Web add-ins are supposed to be updated versions of VSTOs or they have different use cases. Could anyone shed some light on this for me please
Lastly, would VSTO or the new Web add-ins be able to accomplish what I'm trying to do?
Sorry for the noob questions, I'm very new to all of this and I'm trying to teach myself all of this.
Thank you.
Here is a quick example which allows you to get data from a cell (Excel) in Word:
Dim o As Object
Dim pgh As Paragraph
dim temp as string
Set o = CreateObject("excel.application")
o.Workbooks.Open ("c:\temp\test.xlsx")
o.ActiveWorkbook.Worksheets.Add.Name = "x"
o.ActiveWorkbook.Worksheets("x").Activate
temp = o.ActiveWorkbook.Worksheets("sheet1").Cells(3, 3)
o.Quit
Once the data is in Word it is fairly easy to put it where you want. You an do it the opposite way by having Excel place the data in Word.
Yes, VSTO is the right tool for adding custom functionality to an Office document – like reading a database into your workbooks and/or docking an interactive “Action Pane” beside your Word document. But before you get too deep into the woods with VSTO, maybe all you need is VB, Visual Studio, and Aspose.Cells and maybe Aspose Words for .Net. They have many well documented examples, the product can be downloaded and used before buying any license, and their sample code is a great way to get started with automating Office documents. Enjoy!
Related
I was hoping for a good point in the correct direction, as this is something I have never done, and googling is getting me tied in knots.
I want to create a word document (docx) from C# on a ASP.NET MVC application.
Populating a template with something like mail merge would be great.
I have spent day googling this and keep finding archived documentation.
The following examples are from 2012
https://msdn.microsoft.com/en-us/library/office/bb491088.aspx
Because you will generate documents on the server you should avoid Interop for document manipulation. You can use free libraries and SDKs based on OpenXML but this is difficult to learn and error prone.
It probably makes sense to choose one among 3rd party toolkits to get the job done quick and easy. Start by preparing MS Word template documents with placeholders for data. Then you can use c# to load the data for the reports and merge the data with templates to get final documents (docx, pdf, xps or image formats). Here is the code used by one such toolkit needed for merging data from the database with the template to get a pdf document:
IEnumerable<Customer> customers = DataAccess.GetCustomerById(15);
DocumentGenerator dg = new DocumentGenerator(customers);
DocumentGenerationResult result = dg.GenerateDocument("MyTemplate.docx", "MyReport.pdf");
You can also see these examples for more information.
Maybe Templater can be of help..
This is small library you can use to create word document on ASP.NET looking like mail merge...
Try demo http://templater.info/demo
First of all I want to say hi to the programming community, what I am looking for is a way to generate a report from my Windows Forms Application in word preferably, this report is basically a list of pre-configured days in a tour creation software I am creating.
I have searched everywhere and I cant seem to find information on how to start creating the report, I have all the information saved into a database, I just need to be able to get this information into word and ordered as it should be ordered.
I just want to be pointed in the right direction so I can research on it even further.
The exact thing I want to create is a word file that I wish I could share here so you can actually see what I mean.
Thank you for all your attention and help if possible.
I can point you in the right direction. Word documents are stored in a format called OpenXml which can be created and manipulated without actually using Word directly. That's good because you don't want to deal with code that actually starts an instance of Word and automates it (Interop.) It sort of works but it's not something I recommend dealing with ever.
OpenXml isn't fun either, but it's better. You can create your document "normally" using Word, save it, and then have your application use it as a template, opening a copy, populating some data, and then saving it.
Here's the reference for OpenXml with Word. I'm not saying it's pretty. It's not. The documentation is lacking. This page on adding text isn't linked from the previous page, even though many other topics are.
There are some nuget packages like this one that can help.
I once did a POC that did exactly what you're describing by opening and altering a document used a template using OpenXml. I'll see if I can dig up the code. But this is definitely a good direction to look in if Word is an absolute requirement.
This is a long shot, but can you output in HTML? If you can that's an even easier alternative.
Can you use Excel? That's also OpenXml but there's easier-to-use tools like EPPlus that simplify dealing with it, because it's not just the friendliest thing to work with.
An option that I would suggest is Crystal Reports. You can download the Crystal Reports add-in for Visual Studio for free from here. Crystal Reports is an easy way to perform reporting from various data sources including SQL. There are also a lot of free tutorials online for learning how to use CR. The syntax is a little strange, but it is easy enough to use.
The add-in allows you to create reports for your application and also build applications that can display, print, and export Crystal Reports.
You can export reports to .RTF (Rich Text Format) files. MS Word can open, edit, and convert RTF documents. It does a fairly decent job, but special formatting might take some work. This route is a ton easier than trying to write XML or anything else. I've written several reports designed for export to RTF. My boss runs the report, exports it, then edits it in Word. He loves the reports.
If you are planning on developing a lot of reports, purchasing the full version of Crystal Reports is well worth it. I believe they are on version 2016 currently.
If you do want to deal with automating Word, Microsoft's guide "Automating Applications Using the Office Object Model" Word-specific task content is here: https://msdn.microsoft.com/en-us/library/78whx7s6(v=vs.80).aspx
A larger example: https://support.microsoft.com/en-us/kb/316384
To begin, simply add an assembly reference to your project file for the correct Office Object Library (example: "Microsoft Word ##.0 Object Library"). Note that you must have Office installed to take this approach.
Good luck!
Is there a way to programmatically create PowerPoint presentations? If possible, I'd like to use C# and create PowerPoint 2003 presentations.
Yes, you can.
You will want to look into MSDN which has a pretty good introduction to it.
I might give you a word of warning, Microsoft Office interop is compatible with an API which is now more than 10 years old. Because of this, it is downright nasty to use sometimes. If you have the money to invest in a good book or two, I think it would be money well spent.
Here's a starting point for you. Use the search feature on MSDN MSDN Webpage. It's good for any Microsoft C# .NET style stuff.
Specifically in regards to your question, this link should help: Automate PowerPoint from C#. EDIT LINK NOW DEAD :(. These two links are fairly close to the original KB article:
Automate Powerpoint from C# 1/2
Automate Powerpoint from C# 2/2
Finally, to whoever downvoted this: We were all learning one day, how to do something as a beginner is most definitely programming related, regardless of how new someone might be.
OpenXML looks like the way to go from a web app.
Using the interop libraries is not recommended, as others have stated.
You can also look at Aspose Slides, a component for .NET and Java that makes it easy to generate powerpoint documents.
If you don't really need PowerPoint compatible output, consider using a markup language such as LaTeX with the Beamer package to produce a PDF of the presentation, or use HTML and javascript in a manner similar to Slidy. If you need fancy effects, it might still be easier to use SVG, and you'd have the benefit of getting output that can be reliably viewed with free software.
http://msdn.microsoft.com/hi-in/magazine/cc163471(en-us).aspx
Use this link. Although this is in VB.NET, C# supports the same.
You may also try out SlideMight, a tool for merging hierarchical data with PowerPoint templates.
SlideMight supports:
text substitution in text fields, tables and notes
image substitution, from raw data, files and URLs
images in tables nested
iterations over data to create slides
iterations to populate tables, possibly spanning multiple slides
special formatting for specific cell values
hyperlinks to generated slides
Input data format is at this time just JSON.
There are versions for Windows and Mac OS X.
More information is at http://www.SlideMight.com
Disclaimer:
I am the owner of Delftware Technology, the company that developed SlideMight.
And I am one of the developers.
You can use Essential Presentation product from Syncfusion Software Private Limited. This product can be used to
Create and manipulate PowerPoint presentations
Open, modify, and save existing PowerPoint presentations
Convert PowerPoint presentations to PDF or Image
More information is at https://help.syncfusion.com/file-formats/presentation/overview
Disclaimer:
I work for Syncfusion Software Private Limited
Our product is going to support Word(and PDF) report generation, and I'm investigating on which techniques to choose.
Currently what I know is Word automation and OpenXML SDK. There are pros & cons of each.
Do you have any experiences, suggestions or comments about these two or any other techniques? Or is there any third-party utilities/products(may be based on the previous two techniques or not) we can use? We want to analyze as many possible solutions as possible.
If you have the choice I'd go for OpenXML any day of the week.
It has quite a number of advantages over Office Automation.
The most interesting one for me is the fact that it can run on a server, where Office Automation can't (because you need an instance of office on the pc/server running your software). That brings us to my second point, it doesn't need an instance of Office to generate your documents, where Office automation needs one. (This is because office automation will run an instance of office in the background and perform all your actions on it).
Especially when we are talking about large documents or being able to generate quite a few at the same time, OpenXML will perform a lot better than Office Automation because of this.
To make a long story short, Office automation is a thing of the past, openXML is the future ;)
If you want to dive into OpenXML, take a peek here: OpenXML Developer
Good luck !
For PDF generation I used http://www.html-to-pdf.net in past. This provides good support and I assume can be used to generate word documents as well... Check out there website...
If you are using Web forms, I faced one issue with HTTPS - which I listed the solution here:
http://blogs.msdn.com/b/sajoshi/archive/2010/12/13/using-pdfconverter-http-www-html-to-pdf-net-with-https-in-asp-net-mvc.aspx
Docmosis offers a cloud service that can produce MS Word and PDF output via a simple api. The report or document templates are either Word or Open Office documents which can be edited and maintained by non-developers. Once uploaded to the system your application can then simply call the service and specify the data to inject into the document(s) as either JSON or XML. The result is then streamed back, emailed, or placed in storage for access later. Output can be doc, pdf, or html.
The service offers a wide range of templating features and so supports quite complex reporting requirements.
The best thing we found was that cosmetic changes to the output could be handled by the document authors and not the developers which saved us heaps of valuable time (not to mention saving the sanity of our developers).
www.docmosis.com
If you want to build your documents in code, the OpenXML SDK is definitely the way to go. It is a very well designed API that makes full use of LINQ type syntax. One you're up to speed on it you will find it very powerful and easy to use.
With that said, you then have all the logic of your document in code. And change requires a change in your code and that tends to become a pain over time. If you want a system where you design the document in Word you've got a couple of choices - and Word automation is the worst. Even Microsoft says don't do Office automation on a server.
One of the best choices where you design in Word is Windward Reports (disclaimer - I'm the CTO there). With Windward you get the power and ease of Word for your design and new documents or revisions of existing documents don't require a change in code. Other products that take this approach are XpertDoc and SoftArtisans (although both of them do have a code component with each template).
I need a way of generating a word document (from a template or something) and inserting an image at a specific place. Does anyone have any pointers on the best way to do this?
I worked on a project that used Office Automation in .NET 1.1 a few years ago, and it was really unspeakably poor. I'm assuming OA has either been improved or been superceeded by a better solution, but I'm not finding much advice on google.
Edit to clarify, this will be running on a web or sharepoint server
Alternatively, and if you do not need to generate word documents that will work with versions prior to Word 2007, you could use the OpenXML SDK to create your Word Document. It's all managed code and way easier in my opinion to use than OA.
Having done something very similar, I would advise against it. Office Automation within a server environment is buggy. Further the COM Interop requires an interactive user, i.e. there is no 'headless' mode.
Use OpenXML as suggested by Gimly, this would be cleaner approach.
Following line would add the image to word document.
wordDoc.InlineShapes.AddPicture(filePath, ref link, ref save, ref range);
Here, link should be false and save should be true. Range should be the location where you need to add image.
This link should help out dealing with the Interop.