2009-09-08 8 views

Répondre

0

fonctionnalité intégrée Utilisons Microsoft Word - "Fichier> Enregistrer en tant que page Web ..."

Ou, pour ce faire par programme, utilisez le _Document.SaveAs method dans le Microsoft.Office.Interop.Word namespace.

+0

est-il possible de créer un fichier HTML à partir de doc sans utiliser l'espace de noms Microsoft.Office.Interop.Word? –

+0

Pas que je sache; quel est le problème avec l'utilisation? – Donut

1
protected void Button1_Click(object sender, EventArgs e) 
{ 
if (FileUpload1.HasFile) 
{ 
// When we click Button1, the file we specify is uploaded to a temporary 
// folder, then converted into an html document... 
string folder_to_save_in = @"c:\temp\documents\"; 
string filePath = folder_to_save_in + FileUpload1.FileName; 
// This bit does the actual file upload: 
FileUpload1.SaveAs(filePath); 

// Here we set up a WOrd Application... 
Word.ApplicationClass wordApplication = new Word.ApplicationClass(); 

// Opening a Word doc requires many parameters, but we leave most of them blank... 
object o_nullobject = System.Reflection.Missing.Value; 
object o_filePath = filePath; 
Word.Document doc = wordApplication.Documents.Open(ref o_filePath, 
ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, 
ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, 
ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject); 

// Here we save it in html format... 
// This assumes it was called "something.doc" 
string newfilename = folder_to_save_in + FileUpload1.FileName.Replace(".doc", ".html"); 
object o_newfilename = newfilename; 
object o_format = Word.WdSaveFormat.wdFormatHTML; 
object o_encoding = Microsoft.Office.Core.MsoEncoding.msoEncodingUTF8; 
object o_endings = Word.WdLineEndingType.wdCRLF; 
// Once again, we leave many of the parameters blank. 
// See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbawd11/html/womthSaveAs1_HV05213080.asp 
// for full list of parameters. 
wordApplication.ActiveDocument.SaveAs(ref o_newfilename, ref o_format, ref o_nullobject, 
ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, 
ref o_nullobject, ref o_nullobject, ref o_encoding, ref o_nullobject, 
ref o_nullobject, ref o_endings, ref o_nullobject); 

// Report success... 
Label1.Text = "Uploaded successfully!"; 
// Finally, close original... 
doc.Close(ref o_nullobject, ref o_nullobject, ref o_nullobject); 
} 
} 

http://www.wherecanibuyit.co.uk/ASP/converting_word_doc_files_to_html.html

1

en utilisant l'espace de noms Microsoft.Office.Interop.Word, serveurs nécessite Microsoft Word pour être installé. Ce que je ne veux pas!

Questions connexes