I need to export word documents from a web app. I currently use NPOI for excel export, but it doesn't seem to cover word export.
I've found Aspose Word, is there other valid alternatives?
I need to be able to use a word template document, and bookmarks should preferably be supported.
If you don't mind writing some lines of code you can use OpenXML SDK. It allow you to create from scratch word, excel and powerpoint files. I used it in a project in wich the users uploaded docuemnt templates and then the app replace the bookmark with values taken from DB. The same thing with excel, but workin with cell coordinates
for exporting word documents from a web app, Spire.Doc may useful for you, doc and docx supported.
Related
My customer gave me some Word and Powerpoint documents which specify how certain 'reports' generated by our product are supposed to look like.
That means, I need to modify those documents (replace placeholders etc.) and then I need to export them as PDF.
How would you solve this problem in C# ?
TL;DR: Editing the office document is no problem at all, but exporting that document to PDF (using Interop) allegedly causes issues when running it as a web server application. That's the whole problem here.
I agree that Interop is not suitable for document manipulation in server environment. I would approach this problem by preparing MS Word template documents with placeholders for data. Then I would use c# to load the data for the reports and merge the data with templates to get final documents (docx, pdf, xps or various image formats). There are 3rd party toolkits which make it quite easy. Here is the code used by one such toolkit needed for merging xml data with the template to get a pdf document:
XElement customers = XElement.Load("Customers.xml");
DocumentGenerator dg = new DocumentGenerator(customers);
DocumentGenerationResult result = dg.GenerateDocument("MyTemplate.docx", "MyReport.pdf");
You can of course also use free libraries and SDKs based on OpenXML but you should expect a steep learning curve, lots of debugging and lots of time invested.
Wkthmltopdf might be an option.
A completely different "report approach" could be, to save those office documents with the placeholders as mht (That's MHTML a web archive format). This could be done directly in MS Office or even programatically.
The placeholders could be easily exchanged by string search and replace. The mht files could directly be used to show the report instead of the PDF. A clear disadvantage of the mht format, is the HTML formatting. With PDF you have a clear and fix positioning.
We are using this kind of report creation. There are some flaws, but it works and the customer could edit the mht templates directly by right-click Open-With the prefered MS Office flavor.
You can use report generators, like FastReport.Net for solving your problems. It can assign different data for placeholders and also allow export to PDF.
I'm currently working with Microsoft.Office.Interop.Word to open a .docx file and convert to PDF. In order to do that, I'm doing this :
Opening the .docx file with Microsoft.Office.Interop.Word.Documents.Open()
Exporting this document as a PDF with Microsoft.Office.Interop.Word._Document.ExportAsFixedFormat()
I used this method ("Call the Protect method of the Microsoft.Office.Interop.Word.Document that you want to protect") : https://msdn.microsoft.com/library/ms178793(v=vs.110).aspx
I have my PDF file, but I can open it in Microsoft Word and edit it... I don't want this PDF to be editable and I must use Word automation to make the PDF.
My question is in the title:
How to disable Word 2013 PDF edition?
It's not possible to change the way Word converts to PDF. There are some options that can be set, using the method you use, but the basic code can't be changed. If you want special things it might be worthwhile to invest in Adobe Acrobat and/Or its API. Since PDF is Adobe's file format its product will have all the special things - it doesn't license some of these things to third parties (such as Microsoft).
I have a dropdownlist in my application with items document, excel and powerpoint. When i click on each of them say for example excel, an excel sheet should open and I write in it and I should be able to save the file in gridview. How can I do that?
Take a look at the NPOI project. From the website:
[N]POI is an open source project which can help you read/write xls,
doc, ppt files. It has a wide application. For example, you can use it
to generate a Excel report without Microsoft Office suite installed on
your server and more efficient than call Microsoft Excel ActiveX at
background; you can also use it to extract text from Office documents
to help you implement full-text indexing feature (most of time this
feature is used to create search engines).
Once you've written a file, you can present it for download in your GridView. Is that what you're after?
In my program I generate some reports in FlowDocument and display it with DocumentViewer control.
Now I need to add more export opportunities. I use iTextSharp to export in PDF, and I can save to XPS natively. Can I save a document directly to any office formats, DOC or XLS. Or maybe someone knows of a good library for converting from PDF / XPS in DOC or XLS?
I found a solution. As I can't export to Doc from WPF automatically, I reproduced my page layout with DocX Library. This is really awesome and simple library that don't required MSOffice installed to create Word 2007/2010 files.
I'm not sure if you're looking for an answer, so I'll be brief. You can use the Microsoft Interop assemblies to create Word documents. It's no menial task, but in my opinion, it's easier than using iTextSharp. They come with Visual Studio.
To create XPS documents, you'll need to generate FixedDocument objects from your FlowDocument, but from there, it's only a few lines of code. Eric Sink has a nice article that you can find here. This is also mentioned in this question posted here.
The word documents I want to parse will have a known format, defined by a word template. Users will use the word template to create the document. I need to parse data, including values from drop downs, from the word document using C#. This will be done on a SharePoint 2010 server. What is the recommended way to do this? I've seen people mention Open XML SDK 2.0; should I use that? If so, do I need to convert the .docx to XML, then parse it? In some cases, I will also have to write to the Word document, how should this be done?
Preferably a solution will support Word 2010 and 2007 but if tools for 2010 are significantly better I'd like to know that as well. Thanks.
The file extension for Office Open XML is .docx. The .docx file can be described as an archive of several different files. Files that handle what fonts, styles, objects will exist in the word document. Those files itself will be describe as XML.