You can view office files using the 'html-style view' function in a QQ mailbox. You can view office files by using the 'html-based view' function in a similar QQ mailbox. You can also use the 'html-based view' function in a similar QQ mailbox to view office files.
When we do some system download modules or internal mailboxes, some users may not install the office, but they urgently need to view the attachment content or even pictures, it is not realistic to download and install an office (Time required? In an internet cafe? In a friend's house ?), How can I view some commonly used attachments?
In fact, QQ mail has a very good function. It can view office files in HTML mode, such as Word documents, Excel tables, and PowerPoint slides. There are many ways to implement this function, for example, the use of SPS is one of the methods, but in most cases, we do not use SPS, or because the genuine software is too expensive, then how to use ASP. NET 2.0 (C #) to implement this function?
Note:CodeTest passed in vs2008, office2007, and WindowsXP. Four com references must be added to the project: Excel 12, word12, powerpoint12, and office12.
/// <Summary>
/// Convert the pptfile to HTML Format
/// </Summary>
/// <Param> pptfile path </param>
Public static void ppttohtmlfile (string pptfilepath)
{
Microsoft. Office. InterOP. PowerPoint. Application PPT = new Microsoft. Office. InterOP. PowerPoint. Application ();
Microsoft. Office. InterOP. PowerPoint. Presentation pptfile = NULL;
Try
{
// Obtain the HTML file name
String htmlfilename = pptfilepath. substring (0, pptfilepath. lastindexof (".") + ". html ";
// Open a PPT file
Pptfile = PPT. Presentations. Open (pptfilepath, Microsoft. Office. Core. msotristate. msotrue,
Microsoft. Office. Core. msotristate. msoctrue, Microsoft. Office. Core. msotristate. msofalse );
// Convert to HTML Format
Pptfile. saveas (htmlfilename, Microsoft. Office. InterOP. PowerPoint. ppsaveasfiletype. ppsaveashtml,
Microsoft. Office. Core. msotristate. msoctrue );
}
Finally
{
If (pptfile! = NULL)
{
Pptfile. Close ();
}
PPT. Quit ();
GC. Collect ();
}
}
/// <Summary>
/// Convert an Excel file to HTML Format
/// </Summary>
/// <Param> Excel file path </param>
Public static void exceltohtmlfile (string excelfilepath)
{
Microsoft. Office. InterOP. Excel. Application excelapp = new Microsoft. Office. InterOP. Excel. Application ();
Microsoft. Office. InterOP. Excel. Workbook obook = NULL;
// Default parameter
Object unknown = type. missing;
Try
{
// Target HTML file path
Object target = excelfilepath. substring (0, excelfilepath. lastindexof (".") + ". html ";
// Open in read-only mode for insurance purposes
Object readonly = true;
// Specify the Save As format (HTML)
Object format = Microsoft. Office. InterOP. Excel. xlfileformat. xlhtml;
// Open an Excel file
Obook = excelapp. workbooks. Open (excelfilepath, unknown, readonly,
Unknown, unknown,
Unknown, unknown, unknown );
// Convert the format
Obook. saveas (target, format, unknown,
Microsoft. Office. InterOP. Excel. xlsaveasaccessmode. xlnochange,
Unknown, unknown, unknown );
}
Finally
{
If (obook! = NULL)
{
Obook. Close (false, unknown, unknown );
}
Excelapp. Quit ();
GC. Collect ();
}
}
///
// convert a Word document to HTML format
///
// word document format
Public static void wordtohtmlfile (string wordfilepath)
{< br> Microsoft. office. interOP. word. application newapp = new Microsoft. office. interOP. word. application ();
Microsoft. office. interOP. word. document Doc = NULL;
// default parameter
Object unknown = type. missing;
try
{< br> // specify the original file and target file
Object source = wordfilepath;
object target = wordfilepath. substring (0, wordfilepath. lastindexof (". ") + ". html ";
// For the sake of insurance, read-only open
Object readonly = true;
// specify the Save As format (HTML)
Object format = Microsoft. office. interOP. word. wdsaveformat. wdformathtml;
// open the DOC file
Doc = newapp. documents. open (ref source, ref unknown, ref readonly,
ref unknown, ref unknown,
ref unknown, ref unknown, ref unknown, ref unknown);
// Convert the format
Doc. saveas (ref target, ref format,
Ref unknown, ref unknown,
Ref unknown, ref unknown, ref unknown );
}
Finally
{
If (Doc! = NULL)
{
// Close the document and wordProgram
Doc. Close (ref unknown, ref unknown, ref unknown );
}
Newapp. Quit (ref unknown, ref unknown, ref unknown );
GC. Collect ();
}
}