C#.NET convert html to word avoid warnings by word object

R

rhitam

Hi all ,

I am trying to open an strict xhtml document by using word object and
trying to save as a word document. Below is my code :



public static void CreateWord(String HtmlFile)

{



object filename1 = HtmlFile;

object oMissing = System.Reflection.Missing.Value;


object oFalse = false;

Microsoft.Office.Interop.Word.Application oWord = new
Microsoft.Office.Interop.Word.Application();

Microsoft.Office.Interop.Word.Document oDoc = new
Microsoft.Office.Interop.Word.Document();

oDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref
oMissing, ref oMissing);

oWord.Visible = false;

oDoc = oWord.Documents.Open(ref filename1, ref oMissing,
ref readOnly, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing);

filename1 = @"C:\Testproject\Testproject\bin\Debug
\Report.doc";

object fileFormat =
Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocument;

oDoc.SaveAs(ref filename1, ref fileFormat, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing);

oDoc.Close(ref oFalse, ref oMissing, ref oMissing);

oWord.Quit(ref oMissing, ref oMissing, ref oMissing);



}

while executing above code , i get a warning like this :

"Linked style sheets are supported only in web format files. By
saving to this format , all links to style sheets would be lost"

How can i avoid such warnings through the program ? Also after i click
"continue" , a blank word document opens , even though i have
oWord.Visible =

false;

in my code

Any ideas ?
 
T

Tim Williams

In VBA-worl this kind of thing can often be avoided by setting

Application.DisplayAlerts = False

So you could try the C# equivalent.

Tim
 
R

rhitam

Tim,



i tried something like this :

oWord.DisplayAlerts =
Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;

But it is not working ... it still is giving the same warning
message.

What to do ?

-R
 
R

rhitam

Tim,

i tried something  like this :

oWord.DisplayAlerts =
Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;

But it is not working ... it still is giving the same warning
message.

What to do ?

-R

Hey , figured it out , used internal style instead :) So now no
such warnings, but while saving the the file , another dialog box
comes , saying "this file is in use by another aplication or user
(Normal.dot) . How to avoid something like that ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top