(Word export problem) solved: Server exceptions. (The exception comes from hresult: 0 × 80010105 (rpc_e_serverfault ).

Source: Internet
Author: User
Symptom: generate a report in the Word format. During debugging, "server exceptions always occur. (Error from hresult: 0x80010105 (rpc_e_serverfault )"
Cause: Code Wordapp. Documents. Add (ref nothing, ref visible) , The last visibale parameter is set to false.
Solution: visible = true Using System;
Using System. Collections. Generic;
Using System. text;

Namespace Business
{
Public   Class Worddocument
{
Microsoft. Office. InterOP. Word. Application wordapp;
Microsoft. Office. InterOP. Word. Document worddoc;
Object Savechanges =   True ;
Object Visible =   True ; // This is where the problem occurs. If it is set to true, it will run normally.
Object Nothing = System. reflection. Missing. value;
Object Worddocpath;
Public Worddocument ( String Worddocpath)
{
This. Worddocpath=Worddocpath;
This. Open ();
}
Private   Void Open ()
{
If (System. Io. file. exists ( This . Worddocpath. tostring ()))
{
System. Io. file. Delete (This. Worddocpath. tostring ());
}

Wordapp =   New Microsoft. Office. InterOP. Word. applicationclass ();
Worddoc = Wordapp. Documents. Add ( Ref Nothing, Ref Nothing, Ref Nothing, Ref Visible );
}
Public   Void Append ( String Content, Int Level)
{
Worddoc. Paragraphs. Last. range. Text = Worddoc. Paragraphs. Last. range. Text + Content;
Switch (Level)
{
Case   1 :
Worddoc. Paragraphs. Last. range. Font. Bold =   3 ;
Worddoc. Paragraphs. Last. range. Font. Name =   " " ;
Worddoc. Paragraphs. Last. range. Font. Size =   16 ;
Break ;
Case   2 :
Worddoc. Paragraphs. Last. range. Font. Bold =   3 ;
Worddoc. Paragraphs. Last. range. Font. Name =   " " ;
Worddoc. Paragraphs. Last. range. Font. Size =   14 ;
Break ;
Case   3 :
Worddoc. Paragraphs. Last. range. Font. Bold =   3 ;
Worddoc. Paragraphs. Last. range. Font. Name =   " " ;
Worddoc. Paragraphs. Last. range. Font. Size =   12 ;
// Content = "" + content;
Break ;
Default :
Worddoc. Paragraphs. Last. range. Font. Bold =   0 ;
Worddoc. Paragraphs. Last. range. Font. Size =   12 ;
Worddoc. Paragraphs. Last. range. Font. Name =   " " ;
// Content = "" + content;
Break ;
}
// */

}
Public   Void Savedoc ()
{
Worddoc. saveas ( Ref   This . Worddocpath, Ref Nothing, Ref Nothing, Ref Nothing,
Ref Nothing, Ref Nothing, Ref Nothing, Ref Nothing, Ref Nothing, Ref Nothing,
Ref Nothing, Ref Nothing, Ref Nothing, Ref Nothing, Ref Nothing, Ref Nothing );
}
Public   Void Closedoc ()
{
Worddoc. Close (RefSavechanges,RefNothing,RefNothing );
Wordapp. Quit (RefSavechanges,RefNothing,RefNothing );
}
Private   Void Create ( String Worddocpath)
{
System. Io. fileinfo File= NewSystem. Io. fileinfo (worddocpath );
File. Create ();
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.