C # document viewer

I want to create a simple file viewer. What control should be used to view office documents (words, excel) in my application.

+4
source share
4 answers

Older versions of Office used to support OLE Embedding allow their contents to be displayed in the web browser of the DsoFramer control. These days are over, DsoFramer is no longer available, and Office ~ 2007 opens documents in its own program. You can no longer do this work.

+2
source

How to use a WebBrowser control to open Office documents in Visual C # 2005 or Visual C # .NET

If you are using a newer version of Office, you can work with documents through the OpenXML SDK. There are some OOXML-based libraries with a higher level of abstraction, such as DocX or OpenXML Document Viewer. But you have to implement the control of the viewer yourself.

+3
source

@ hans-passant: But I do this with the DsoFramer component. The component works great for both Word 2007 and Word 2010. There are many features that use this method. Greetings.

+2
source

Downloading a document to a local workstation worked for us. Store it somewhere in the user personal folders folder. Display using software installed on the system.

Get the path to your personal folder using the following command:

Environment.GetFolderPath(Environment.SpecialFolder.Personal) 

Download the desired file to this path.
Then copy the file to the file like this:

 if (File.Exists(fullLocalDocumentPath) == true) { System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.EnableRaisingEvents = false; proc.StartInfo.FileName = fullLocalDocumentPath; proc.Start(); } 

A configured OS will be used to open the file and display it (based on the file extension). This is not an ideal solution, but it works for us and can suit your needs.

Reservations:
will only display files with extensions that are displayed on the application.
Opens a copy of the application to display the file.
You must provide some mechanism to clear download files from a personal folder.

File extensions that often β€œwork” using this technique:
*. doc, * .docx, * .xls, .xlsx (docx and xlsx - Office 2007 and later)
.pdf (everyone has it installed, right?)
.xps (will work if .NET is installed, if a .NET program is running, this will not be a problem)
.txt
Can work:
* .pptx (requires a power point)
Work only if you have special software installed:
Visio, Autocad, etc. files


This may work even if the user does not have Office installed. The user just needs to install free applications for reading from MS.

0
source

Source: https://habr.com/ru/post/1313662/


All Articles