Asp.net word ecxel file online preview, asp. netecxel
Asp.net word ecxel file online preview
First, you must reference COM:
Microsoft Excel 10 Object Library
Microsoft Word 10 Object Library
Or more than 10 Class Libraries
I am using: Resource download: http://download.csdn.net/detail/panfuy/3247641 orAttachment
Microsoft Excel 10 Object Library
Microsoft Word 10 Object Library
The Code is as follows:
C # code
- Using System;
- Using System. Data;
- Using System. Configuration;
- Using System. Collections;
- Using System. Web;
- Using System. Web. Security;
- Using System. Web. UI;
- Using System. Web. UI. WebControls;
- Using System. Web. UI. WebControls. WebParts;
- Using System. Web. UI. HtmlControls;
- Using System. IO;
- Using System. Diagnostics;
- Using Word = Microsoft. Office. Interop. Word;
- Using Excel = Microsoft. Office. Interop. Excel;
- Using System. Reflection;
- Using Microsoft. Office. Interop. Excel;
- Public partial class upload_preview: System. Web. UI. Page
- {
- Protected void Page_Load (object sender, EventArgs e)
- {
- GenerationWordHTML ("E: // 20110502.doc"," E: // 20110502.html ");
- GenerationExcelHTML ("E: // 20110502.xls"," E: // 20110502.html ");
- }
- /// <Summary>
- /// Generate HTML and save the Ecxel File
- /// </Summary>
- /// <Param name = "FilePath"> path of the ecxel file to be generated </param>
- /// <Param name = "saveFilePath"> path for saving the HTML file after generation </param>
- /// <Returns> whether the generation is successful. If the generation succeeds, the value true; otherwise, the value false </returns>
- Protected bool GenerationExcelHTML (string FilePath, string saveFilePath)
- {
- Try
- {
- Excel. Application app = new Excel. Application ();
- App. Visible = false;
- Object o = Missing. Value;
- /// Open the file
- /* The following is Microsoft Excel 9 Object Library :*/
- /* _ Workbook xls = app. workbooks. open (FilePath, o, o );*/
- /* The following is Microsoft Excel 10 Object Library :*/
- _ Workbook xls = app. workbooks. open (FilePath, o, o );
- /// Convert the format and save it as HTML
- /* The following is Microsoft Excel 9 Object Library :*/
- /* Xls. SaveAs (saveFilePath, Excel. XlFileFormat. xlHtml, o, XlSaveAsAccessMode. xlExclusive, o, o );*/
- /* The following is Microsoft Excel 10 Object Library :*/
- Xls. SaveAs (saveFilePath, Excel. XlFileFormat. xlHtml, o, XlSaveAsAccessMode. xlExclusive, o, o );
- /// Exit Excel
- App. Quit ();
- Return true;
- }
- Catch
- {
- Return false;
- }
- Finally
- {
- // Close the excel process.
- Process [] myProcesses = Process. GetProcessesByName ("EXCEL ");
- Foreach (Process myProcess in myProcesses)
- {
- MyProcess. Kill ();
- }
- }
- }
- /// <Summary>
- /// Generate HTML and save the WinWord File
- /// </Summary>
- /// <Param name = "FilePath"> path of the word file to be generated </param>
- /// <Param name = "saveFilePath"> path for saving the HTML file after generation </param>
- /// <Returns> whether the generation is successful. If the generation succeeds, the value true; otherwise, the value false </returns>
- Private bool GenerationWordHTML (string FilePath, string saveFilePath)
- {
- Try
- {
- Word. ApplicationClass word = new Word. ApplicationClass ();
- Type wordType = word. GetType ();
- Word. Documents docs = word. Documents;
- /// Open the file
- Type docsType = docs. GetType ();
- Word. document doc = (Word. document) docsType. invokeMember ("Open", System. reflection. bindingFlags. invokeMethod, null, docs, new Object [] {FilePath, true, true });
- /// Convert the format and save it as HTML
- Type docType = doc. GetType ();
- /* The following is the Microsoft Word 9 Object Library :*/
- /* DocType. InvokeMember ("SaveAs", System. Reflection. BindingFlags. InvokeMethod, null, doc, new object [] {saveFilePath, Word. WdSaveFormat. wdFormatHTML });*/
- /* The following is the Microsoft Word 10 Object Library statement :*/
- DocType. InvokeMember ("SaveAs", System. Reflection. BindingFlags. InvokeMethod,
- Null, doc, new object [] {saveFilePath, Word. WdSaveFormat. wdFormatFilteredHTML });
- /// Exit Word
- WordType. InvokeMember ("Quit", System. Reflection. BindingFlags. InvokeMethod, null, word, null );
- Return true;
- }
- Catch
- {
- Return false;
- }
- Finally
- {
- // Close the winword process.
- Process [] myProcesses = Process. GetProcessesByName ("WINWORD ");
- Foreach (Process myProcess in myProcesses)
- {
- MyProcess. Kill ();
- }
- }
- }
- }
- Microsoft.Office.Interop.Excel_Word.dll.zip (589.3 KB)
Asp net web page, written in C # language. How can I preview successfully uploaded files such as word, excel, ppt, and txt online?
If there are no special requirements, call the saveas function of the office itself on the server and save it as html. The specific code Baidu office online preview, the first one is
Aspnet is similar to Baidu Library Online Preview word implementation
What is the purpose of Online Preview? If it is to prevent users from downloading, it is necessary to make it the same as Baidu Library. If you look at the web page, you can simply open it on the web page.
The Source Code cannot be provided to you, involving unit information. It can only tell you how to implement it: Use the virtual printing technology to print word into an image, convert it to swf, or convert word to pdf, and then convert the pdf to swf with pdfswf.exe. After converting to swf, use flexpager to browse. There are many materials on the Internet. You need to pay attention to this problem. The Document Style conversion is prone to major problems. We recommend that you use word to print it as an image, the disadvantage is that the file size is large but simple.