如何将WEB页面中的数据保存为一个word文件,在线等急急。。。。。 怎么保存WEB页面的数据到一个WORD文件中去????在线等 急,能否给出代码,谢谢。请各位高手帮忙。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以先保存为一个html文件,然后用word打开,然后存成word文件 直接用word打开,然后存成.doc文件就可以了。protected void ConvertToHtml(string SrcFilePath,string TargetFilePath){ Word.Application app=new Word.Application(); app.Visible=false; Object o=Missing.Value; object docFile=SrcFilePath; _Document doc=app.Documents.Open(ref docFile,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o); object fileName=TargetFilePath; object format=Word.WdSaveFormat.wdFormatDocument; //word format doc.SaveAs(ref fileName,ref format,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o); object t=true; app.Quit(ref t,ref o,ref o);} #region 数据集生成Word文件/// <summary>/// 数据集生成Word文件/// </summary>private void ToWord(){ object Missing = System.Reflection.Missing.Value; int NumRows, NumColumns, rowIndex, colIndex; object FileName = "c:\\liu.doc"; //保存word文件的路径// Office.CommandBar MyBar; //工具栏 Word.ApplicationClass wordApp = new Word.ApplicationClass(); Word.Document myDoc; Word.Table oTable; DataTable Table = new DataTable(); rowIndex = 1; colIndex = 0; wordApp.Documents.Add(ref Missing,ref Missing,ref Missing, ref Missing); myDoc = wordApp.ActiveDocument; Table = MyBind(); oTable = myDoc.Tables.Add(myDoc.Range(ref Missing, ref Missing),NumRows=Table.Rows.Count + 1, NumColumns=Table.Columns.Count,ref Missing,ref Missing); //将所得到的表的列名,赋值给单元格 foreach(DataColumn Col in Table.Columns) { colIndex = colIndex + 1; oTable.Cell(1, colIndex).Range.InsertAfter(Col.ColumnName); } //得到的表所有行,赋值给单元格 foreach(DataRow Row in Table.Rows) { rowIndex = rowIndex + 1; colIndex = 0; foreach(DataColumn Col in Table.Columns) { colIndex = colIndex + 1; oTable.Cell(rowIndex, colIndex).Range.InsertAfter(Row[Col.ColumnName].ToString()); } } oTable.Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleDashDot; oTable.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleDot; wordApp.Visible = false; //true:word文件显示 false:word文件不显示 myDoc.SaveAs(ref FileName,ref Missing,ref Missing,ref Missing,ref Missing,ref Missing,ref Missing,ref Missing,ref Missing,ref Missing,ref Missing); } #endregion #region DataGridToWord /// <summary> /// DataGridToWord /// </summary> /// <param name="ctl">DataGrid控件</param> private void DataGridToWord(System.Web.UI.Control ctl) { HttpContext.Current.Response.Clear(); HttpContext.Current.Response.Charset =""; HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename=liu0910.doc"); HttpContext.Current.Response.ContentEncoding =System.Text.Encoding.GetEncoding("GB2312"); //更改ContentType的值为ms-word即可实现导出到Word HttpContext.Current.Response.ContentType ="application/ms-word";//image/JPEG;text/HTML;image/GIF;vnd.ms-excel/msword ctl.Page.EnableViewState =false; System.IO.StringWriter tw = new System.IO.StringWriter() ; System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter (tw); ctl.RenderControl(hw); HttpContext.Current.Response.Write(tw.ToString()); HttpContext.Current.Response.End(); } #endregion 求个正则 请教一下asp.net发布时iis的配置问题 正则-如何提取域名的中间部分? 有关Dundas Chart和数组的问题,请高手帮忙解答 请大家帮看看我的网站是否可以访问 请教关于altlas在使用上的问题! [探讨]如何在MyHttpHandler中使用服务器控件 [急]如何获得__doPostBack传过来的数组(分不够再加) 我再问 小问题 在线等待 !!!!!!!!!!!! 帮我看看错在哪了?aspx页面调用cs文件函数出错! 存储过程(急) 求解:DataGrid的更一种显示方法。
{
Word.Application app=new Word.Application();
app.Visible=false;
Object o=Missing.Value;
object docFile=SrcFilePath;
_Document doc=app.Documents.Open(ref docFile,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o);
object fileName=TargetFilePath;
object format=Word.WdSaveFormat.wdFormatDocument; //word format
doc.SaveAs(ref fileName,ref format,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o);
object t=true;
app.Quit(ref t,ref o,ref o);
}
/// <summary>
/// 数据集生成Word文件
/// </summary>
private void ToWord()
{
object Missing = System.Reflection.Missing.Value;
int NumRows, NumColumns, rowIndex, colIndex;
object FileName = "c:\\liu.doc"; //保存word文件的路径
// Office.CommandBar MyBar; //工具栏
Word.ApplicationClass wordApp = new Word.ApplicationClass();
Word.Document myDoc;
Word.Table oTable;
DataTable Table = new DataTable(); rowIndex = 1;
colIndex = 0;
wordApp.Documents.Add(ref Missing,ref Missing,ref Missing, ref Missing);
myDoc = wordApp.ActiveDocument;
Table = MyBind();
oTable = myDoc.Tables.Add(myDoc.Range(ref Missing, ref Missing),NumRows=Table.Rows.Count + 1, NumColumns=Table.Columns.Count,ref Missing,ref Missing); //将所得到的表的列名,赋值给单元格
foreach(DataColumn Col in Table.Columns)
{
colIndex = colIndex + 1;
oTable.Cell(1, colIndex).Range.InsertAfter(Col.ColumnName);
} //得到的表所有行,赋值给单元格
foreach(DataRow Row in Table.Rows)
{
rowIndex = rowIndex + 1;
colIndex = 0;
foreach(DataColumn Col in Table.Columns)
{
colIndex = colIndex + 1;
oTable.Cell(rowIndex, colIndex).Range.InsertAfter(Row[Col.ColumnName].ToString());
}
} oTable.Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleDashDot;
oTable.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleDot;
wordApp.Visible = false; //true:word文件显示 false:word文件不显示
myDoc.SaveAs(ref FileName,ref Missing,ref Missing,ref Missing,ref Missing,ref Missing,ref Missing,ref Missing,ref Missing,ref Missing,ref Missing);
}
#endregion
#region DataGridToWord
/// <summary>
/// DataGridToWord
/// </summary>
/// <param name="ctl">DataGrid控件</param>
private void DataGridToWord(System.Web.UI.Control ctl)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Charset ="";
HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename=liu0910.doc");
HttpContext.Current.Response.ContentEncoding =System.Text.Encoding.GetEncoding("GB2312");
//更改ContentType的值为ms-word即可实现导出到Word
HttpContext.Current.Response.ContentType ="application/ms-word";//image/JPEG;text/HTML;image/GIF;vnd.ms-excel/msword
ctl.Page.EnableViewState =false;
System.IO.StringWriter tw = new System.IO.StringWriter() ;
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter (tw);
ctl.RenderControl(hw);
HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();
}
#endregion