将网页的内容导入WORD,为什么图片没导进去呢?在线等,帮帮忙呀,已经弄N天了,再不出来,后果难料呀!
我做一个在线考试系统,因为笔试题中题目有的带有图片,我要将其一起导入WORD,方便用户编辑,可是不知为什么总是图片导不进去,变成红叉叉,大家帮我看看,在线等呀!
------解决方案--------------------//System.Text.StringBuilder outStr = str;
/*string outStr = str;
string spath = Server.MapPath( ". ") + @ "\doc\ " + "aaa " + ".doc ";
try
{
string strDirectory = Server.MapPath( ". ") + @ "\doc ";
if(!System.IO.Directory.Exists(strDirectory))
System.IO.Directory.CreateDirectory(strDirectory);
using(StreamWriter sw =new StreamWriter(spath,false,System.Text.Encoding.GetEncoding( "GB2312 ")))
{
sw.WriteLine(outStr);
sw.Flush();
sw.Close();
}
}
catch{
}
finally{
// sw.Close();
}
object Nothing=System.Reflection.Missing.Value;
object filename=@ "D:\gym\test\doc\aaa.doc ";
object objt=true;
Microsoft.Office.Interop.Word.Application wordApp=new Microsoft.Office.Interop.Word.ApplicationClass();
object format=Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocument;
Microsoft.Office.Interop.Word.Document wordDoc = null;
try
{
// 打开word
// Microsoft.Office.Interop.Word.Document thisDocument = null;
// Microsoft.Office.Interop.Word.FormFields formFields = null;
Microsoft.Office.Interop.Word.Application thisApplication = new Microsoft.Office.Interop.Word.ApplicationClass();
Object ConfirmConversions = false;
Object ReadOnly = true;
Object AddToRecentFiles = false;
Object PasswordDocument = System.Type.Missing;
Object PasswordTemplate = System.Type.Missing;
Object Revert = System.Type.Missing;
Object WritePasswordDocument = System.Type.Missing;
Object WritePasswordTemplate = System.Type.Missing;
Object Format = System.Type.Missing;
Object Encoding = System.Type.Missing;
Object Visible = System.Type.Missing;
Object OpenAndRepair = System.Type.Missing;
Object DocumentDirection = System.Type.Missing;
Object NoEncodingDialog = System.Type.Missing;
Object XMLTransform = System.Type.Missing;
//Microsoft.Office.Interop.Word.Document wordDoc =
wordDoc = thisApplication.Documents.Open(ref filename, ref ConfirmConversions,
ref ReadOnly, ref AddToRecentFiles, ref PasswordDocument, ref PasswordTemplate,
ref Revert,ref WritePasswordDocument, ref WritePasswordTemplate, ref Format,
ref Encoding, ref Visible, ref OpenAndRepair, ref DocumentDirection,
ref NoEncodingDialog, ref XMLTransform );
//图片
Microsoft.Office.Interop.Word.InlineShape oShape= wordDoc.Words.Last.InlineShapes.AddPicture( "D:\\gym\\test\\006.jpg ",ref Nothing,ref objt,ref Nothing);
//oShape.WrapFormat.Type =Microsoft.Office.Interop.Word.WdWrapType.wdWrapSquare;
//将htm文件save as成doc文件
filename = @ "D:\gym\test\doc\aaa111.doc ";
//wordDoc.Save();
//另存为
wordDoc.SaveAs(ref filename,ref format, 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);
wordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
}
finally
{
wordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
}*/