一个超难的问题,最后100分了,解决马上给分,在线等 在asp.net里我想在点击一个BUTTON时,把数据库里的一条数据的某几个字段给搞到word中去,该怎么做呀小弟我想了好久没有想明白,一点思路都没有,求助各位了!!!!!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://msdn.microsoft.com/office/understanding/word/codesamples/default.aspx?pull=/library/en-us/odc_wd2003_ta/html/OfficeWordAutomatingTablesData.asp 我自己写的一个类~你看看public bool ExportWord( DataTable Table) { object Missing = System.Reflection.Missing.Value; int NumRows, NumColumns, rowIndex, colIndex; //±£´æwordÎļþµÄ·¾¶ object FileName = this.strDestinationFilePath; Word.ApplicationClass wordApp = new Word.ApplicationClass(); Word.Document myDoc; Word.Table oTable; rowIndex = 1; colIndex = 0; try { wordApp.Documents.Add(ref Missing,ref Missing,ref Missing, ref Missing); myDoc = wordApp.ActiveDocument; 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; //true:wordÎļþÏÔʾ false:wordÎļþ²»ÏÔʾ wordApp.Visible = false; myDoc.SaveAs(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); return true; } catch { return false; } finally { wordApp.Quit( ref Missing,ref Missing, ref Missing ); } } powerllr(笨笨的招财鸡)刚才那篇帖子就是我发的,麻烦再问你一下,当我把数据搞到word中去了后,里面有个表格,怎么样才能把word中的那个表格去掉还有我下在数据导入成功后提供下载个打开的功能没,该怎么做解决了这分都是你的了,哈哈 powerllr(笨笨的招财鸡)他在要挟你哟! 怎么样才能把word中的那个表格去掉请看http://61.186.252.131/Expert/topic/903/903407.xml?temp=.7777674还有我下在数据导入成功后提供下载个打开的功能没,该怎么做你知道那个Word文档路径吗? 搞个linkButton之类的。把地址属性设置成Word文档路径就KO 谁用.net写的方法生成dll文件?? 我给高分!在后台创建的dropdownlist控件为什么无法默认选中一项? 未将对象引用设置到对象的实例 怎么解决?? 一简单正则表达式的错误 如何实现ASP.NET 2.0下的报表打印问题? 帮帮我(一个文件名的提取) DATAGRID的问题! C#、C++、C语言之间有什么区别? 取DataGrid记录数总为0,急啊! 关于asp.net中的锁定页面 数据库访问问题 网站,别人用pc机可以浏览,用苹果机浏览不行,为什么?
public bool ExportWord( DataTable Table)
{
object Missing = System.Reflection.Missing.Value;
int NumRows, NumColumns, rowIndex, colIndex;
//±£´æwordÎļþµÄ·¾¶
object FileName = this.strDestinationFilePath;
Word.ApplicationClass wordApp = new Word.ApplicationClass();
Word.Document myDoc;
Word.Table oTable;
rowIndex = 1;
colIndex = 0;
try
{
wordApp.Documents.Add(ref Missing,ref Missing,ref Missing, ref Missing);
myDoc = wordApp.ActiveDocument;
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;
//true:wordÎļþÏÔʾ false:wordÎļþ²»ÏÔʾ
wordApp.Visible = false;
myDoc.SaveAs(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);
return true;
}
catch
{
return false;
}
finally
{
wordApp.Quit( ref Missing,ref Missing, ref Missing );
} }
刚才那篇帖子就是我发的,麻烦再问你一下,当我把数据搞到word中去了后,里面有个表格,怎么样才能把word中的那个表格去掉
还有我下在数据导入成功后提供下载个打开的功能没,该怎么做解决了这分都是你的了,哈哈
他在要挟你哟!
请看http://61.186.252.131/Expert/topic/903/903407.xml?temp=.7777674还有我下在数据导入成功后提供下载个打开的功能没,该怎么做
你知道那个Word文档路径吗? 搞个linkButton之类的。把地址属性设置成Word文档路径就KO