What I've done:
I am trying to be able to open an excel file in a windows form so that I can create a disposable pivot table. I have tried a few options that I've found on Google but I've run into a brick wall.
One option that I found was to open in wpf user control document viewer, while I can open the file I cannot edit it.
I have not figured out a way to edit the excel file.
My Question: I need to display a blank excel sheet inside a windows form, then I will need to add a pivot table to the sheet that is embedded inside the windows form where when the form closes it disregards the sheet that was open in the form. What is the best way to do this?
For all tasks related to programmatic construction or manipulation of Office documents, the Open XML SDK is the proper solution. All other APIs are either limited in scope (other 3rd-party Excel writer APIs support only a subset of the features of Excel documents) or have issues being used programmatically (Office automation is notoriously error-prone and should NEVER be used in a server environment). The Open XML SDK allows you to directly create and manipulate the data structure that is the Office document. It does not require Office to be installed. Additionally, the Open XML Productivity tool (also available via the download link below) will allow you to open an existing document and see EXACTLY the code required to construct EXACTLY that document. Very useful!
Download: https://www.microsoft.com/en-us/download/details.aspx?id=30425
Related
Im making a Sharepoint Application. I want to save documents in my sharepoint and open it with Word online(office online/ word web app).
When I open a document in Word online I want to force that a office add-in also starts. Here is an example:
I already manage to open the documents in Word Online. But I havent manage to force the office add-in. Is this posible?
I do not believe it is possible to force an add-in to load automatically right now. The model is that the user must actively open it each time the document is loaded. The exception here are Content add-ins which are embedded into the document as a piece of content.
Please mark the answer as 'answered' if it answers your question.
I would like to develop some add-in. This add-in should use open xml (not everything is doable using VSTO + Open XML is much faster), BUT is there any possibility to edit opened document? For example I have opened PowerPoint presentation (or Word doc/Excel spreadsheet) and I would like to replace some text using Open XML, can I read it (from that what I read, reading is possible) and update without closing that file, using Open XML of course? If yes, how to do it?
There is some feeddata() method, memory streams, but I do not know how to use it. Could anyone show some example?
Below code works for me:
Word.Document doc = Globals.ThisAddIn.Application.ActiveDocument;
string XML = doc.Content.WordOpenXML;
// XML Changes
doc.Content.InsertXML(XML);
var fileFullName = Globals.ThisAddIn.Application.ActiveDocument.FullName;
Globals.ThisAddIn.Application.ActiveDocument.Close(WdSaveOptions.wdSaveChanges, WdOriginalFormat.wdOriginalDocumentFormat, true);
//edit document using OpenXml here
Globals.ThisAddIn.Application.Documents.Open(fileFullName);
This works for Word documents.
The purpose of VSTO and Open XML are different.
VSTO is basically extending office to your purpose where you run addin in the context of the Office application. And you can make use of Com interops as they are already available.
Open XML is used for automation like generating or editing docs, workbooks where you dont have office application installed. for eg in Asp.net server you dont need to install Office but use Open XML for creating, editing docs, spreadsheets or ppt.
In your case if you going for VSTO approach you dont need to use Open XML sdk. Use the available find and replace functionality in the corresponding interops.
After replace dont forget to save the doc, xls or ppt
Word
Excel
Powerpoint
I have been struggling the last few hours trying to get an excel spreadsheet/workbook to be displayed on a Windows form using Visual Studio 2012, C#. I can retrieve the data from the workbook and display it on the form, but I need the functionality of Excel in the application, including stuff like Filtering, Conditional Formatting, Formulas, etc.
I have read up quite a lot, and as I understand it, there are no controls in Visual Studio to embed these (Office) files due to licencing, which makes sense. I have found a solution though, to display the file in a WebControl (I am sure I will be able to work with this), but when I try to load the excel file in the web control, it prompts the user to either open or save the file, and when 'Open File' is chosen, the file is opened using Microsoft Excel.
As I understand it, this happens because the ContentType (Mime type, Excel ContentType) of the file needs to be set in the browser (I need to do more research on this as I am not yet familiar with this concept, ).
The resources I am using:
Logic to save the contents to an Excel File: EPPlus
I was working from the following project, among others: Winforms Excel Example
The latter is almost exactly what I want to achieve, but keeps on asking to save or open the file, rather than just displaying it in the WebControl
Any help on this matter would be greatly appreciated.
There're commercial WinForms libraries from DevExpress, Syncfusion and Infragistics. I'm using DevExpress. I'd suggest their WinForms Spreadsheet control inspired by Excel. They also have Spreadsheet File API for .NET and Spreadsheet UI controls for ASP.NET, MVC, WPF, ASP.NET Core and Bootstrap.
You can try their free 30-day trial and see if DevExpress UI controls suit your needs.
Use DataGridView and program a functionnality if it doesn't have it!
OR
Use Excel COM to create an instance of Excel.
Suppose in .NET (don't care what language) I want to show a user a PDF, Word and Excel file together. I am trying to replicate a document process where a user might have a PDF file and he would like to attach a WORD file and an Excel file let's say to make a stack of documents (that I would save in some directory). Then he would like to click on a button and see a stack of these documents in 1 application of some sort.
How can I display the stack of documents WITHOUT first opening WORD, then openinig EXCEL and then openining ADOBE ACROBAT - this would be really annoying for the user. I would like one unified application or some idea to mimic one in .NET that can just show all 3 documents as if they were printed one after the other on paper. (I hope I am explaining this clearly)
The only thing I can think of to do this would be to leverage some sort of PDF conversion process to create one PDF file containing all three of these documents in "printed" (page-by-page) form, and then show that. The one application I can think of that could show all of these files is a web browser with appropriate Office and Acrobat viewer plugins, and you might find it difficult to leverage that, as browser preference and other user OS settings can cause various strategies for application launching to fail.
I would convert the documents in PDF and develop a pdf viewer inside your application.
I would use a ready made library for that, don't reinvent the wheel.
For example: http://www.quickpdflibrary.com/products/quickpdf/index.php
i have a single powerpoint slide that we use for reporting. This slidehas some tables and some textboxes with bulletted lists
We are trying to see if we can update this powerpoint slide (update text in textbox and update text in tables) using C# as we now have a lot of the data that we manually add to this slide in a SQL database.
so i basically need to:
load up current presentation and this single slide (treat it like a template)
access textboxes and clear current text
enter new text from my data source (happens to be SQL server)
update tables
save as specific filename
what is the best way of doing this from C#. i want to basically have a button in a webpage or a winforms app that kicks off the steps above.
Update
Looking for a FREE solution if possible (a few answers below are paid third party libraries)
If you are working with any PowerPoint file formats (including the default one used by PowerPoint 2003), you have to use Microsoft Office & PowerPoint Interops. There are probably some third party libraries, but I'm not sure they will be very helpful in this particular situation, except if you don't want to or can't install Microsoft Office on the server.
If you use only the new PowerPoint 2007 format or 2003/2007 XML format, then changing the XML directly may be the easiest way, thus this does not require Microsoft Office to be installed on the server.
You may want to look at Aspose for .NET. It provides a ton of libraries for interfacing with Office file formats.