/// <summary>
/// DataGridView中选中的数据复制到Word
/// </summary>
/// <param name="ExportDgv">DataGridView</param>
/// <param name="WordTitle">word标题</param>
/// <returns></returns>
public bool OutputFileToWord(DataGridView ExportDgv, string WordTitle)
{
try
{
if (ExportDgv == null)
{
return false;
}
if (ExportDgv.Columns.Count == 0 || ExportDgv.Rows.Count == 0)
{
return false;
}
//复制数据到Clipboard
int I = ExportDgv.GetCellCount(DataGridViewElementStates.Selected);
if (I > 0)
{
//为了解决极少部分机器中文字符乱码问题
//一般为"区域选项,字符集设置不一样的问题
//Clipboard.SetDataObject(ExportGrid.GetClipboardContent());
Clipboard.SetText(ExportDgv.GetClipboardContent().GetData(DataFormats.Text).ToString());
}
else
{
return false;
}
//创建Word对象
object iMissing = System.Type.Missing;
Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
if (wordApp==null)
{
return false;
}
Microsoft.Office.Interop.Word.Document wordDoc = wordApp.Documents.Add(ref iMissing,ref iMissing,ref iMissing,ref iMissing);
//粘贴数据
wordDoc.ActiveWindow.Selection.PasteSpecial(ref iMissing, ref iMissing, ref iMissing, ref iMissing, ref iMissing, ref iMissing, ref iMissing);
wordApp.Caption = WordTitle;
wordApp.Visible = true;//显示粘贴的数据
return true;
}
catch
{
return false;
}
}
详细解决方案
DataGridView中选中的数据复制到Word
热度:45 发布时间:2024-01-22 03:23:04.0
相关解决方案
- word excel pdf在ie浏览器中打开,该如何解决
- jsp 导出 word 中的table宽度怎么设置
- (C# VS2008 WORD)关于AddOLEControl中第一个参数ClassType确确实实定
- (C# VS2008 WORD)关于AddOLEControl中第一个参数ClassType的确定,该怎么处理
- DataGridView 下拉框解决方案
- word 里头TAB键代表字符的个数
- dataGridView checkboxColumn有关问题
- word 里面TAB键代表字符的个数解决方案
- 用reportviewer导出Excel、PDF、Word,文件名乱码,求解决方案。解决方法
- wpf 打印(输出)变换 xps word pdf文件
- 用reportviewer导出Excel、PDF、Word,文件名乱码,求解决方案。该如何解决
- NET dataGridView 中怎么点击按钮后隐藏按钮
- IIS 调用Microsoft.Office.Interop.Word.Documents.Open 回到为null
- 生手 求教,Weboffice 操作 Word 文档.呃.分不多,只有这几分了。
- Word 标签是什么东西呀,如何弄到word里面去呀 多谢了, 马上给分
- 为什么小弟我用ms word object 12.0库只能以只读方式打开文档
- 请教哪位高手用过aspose.word
- Word.PrintOut,该怎么处理
- WORD 文件打开的有关问题
- 请问 DataGridView 数据更新
- 如何给asp:menu加上 Style="word-break:break-all"的属性?
- datagridview 如何实现表头标题合并
- datagridview 更新有关问题
- word 视图,该怎么处理
- word,该怎么处理
- word 2003用邮件合并合成文档后总页数怎么分节统计
- 打开OFFICE word 2007跟OFFICE word 2010,提示: the setup controller has encountered a p
- word 视图,该如何解决
- word cpu占用接近100%?解决办法
- word 2007 docx格式 自动只读解决方法