111,098
社区成员




string path = "D:\11.doc"
protected void Page_Load(object sender, EventArgs e)
{
ExpertControl(this, path);
object fileName = path;
object read_only = false;
object visible = true;
object isFalse = false;
// the way to handle parameters you don't care about in .NET
object missing = System.Reflection.Missing.Value;
//Open the document that was chosen by the dialog
ApplicationClass wordApp = new ApplicationClass();
wordApp.Visible = false;
Document aDoc = wordApp.Documents.Open(
ref fileName, ref missing, ref missing,
ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing);
aDoc.PageSetup.PageHeight = 1050.0F;
aDoc.PageSetup.PageWidth = 710.0F;
aDoc.PageSetup.TopMargin = 5;
aDoc.PageSetup.BottomMargin = 20;
aDoc.PageSetup.LeftMargin = 90;
aDoc.PageSetup.RightMargin = 50;
aDoc.Save();
System.Diagnostics.Process.Start(@path);
Response.End();
}
public void ExpertControl(System.Web.UI.Control source, string File)
{
Response.ContentType = "application/ms-word";
Response.Charset = "utf-8";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
//关闭控件的视图状态
source.Page.EnableViewState = false;
//初始化HtmlWriter
System.IO.StringWriter writer = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWriter = new System.Web.UI.HtmlTextWriter(writer);
source.RenderControl(htmlWriter);
StreamWriter streamwriter = new StreamWriter(File); //创建数据流
streamwriter.Write(writer.ToString()); //输出
streamwriter.Close(); //关闭流
}
aDoc.Save();
aDoc.Close();
System.Diagnostics.Process proc= System.Diagnostics.Process.Start(@path);
proc.Close();