社区
C#
帖子详情
winfrom中怎么样导出word文档
woshilaihua
2009-10-29 05:15:57
我有一些字符串..
本来可以到处Excel的
但是现在要到出word文档..
求高手帮下忙..
最好能贴点代码出来.........
...全文
288
11
打赏
收藏
winfrom中怎么样导出word文档
我有一些字符串.. 本来可以到处Excel的 但是现在要到出word文档.. 求高手帮下忙.. 最好能贴点代码出来.........
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
11 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
woshilaihua
2009-10-30
打赏
举报
回复
谢谢
[ wuyq11 的回复:]
我找了段替换的代码,导出了固定的格式word..
现在又来了个问题. 我有张图片该怎么样插入word文档里面了...
wuyq11
2009-10-29
打赏
举报
回复
public static void ExportData(DataGridView srcDgv,string fileName)//导出数据,传入一个datagridview和一个文件路径
{
string type = fileName.Substring(fileName.IndexOf(”.”)+1);//获得数据类型
if (type.Equals(”xls”,StringComparison.CurrentCultureIgnoreCase))//Excel文档
{
Excel.Application excel = new Excel.Application();
try
{
excel.DisplayAlerts = false;
excel.Workbooks.Add(true);
excel.Visible = false;
for (int i = 0; i < srcDgv.Columns.Count; i++)//设置标题
{
excel.Cells[2, i+1] = srcDgv.Columns[i].HeaderText;
}
for (int i = 0; i < srcDgv.Rows.Count; i++)//填充数据
{
for (int j = 0; j < srcDgv.Columns.Count; j++)
{
excel.Cells[i + 3, j + 1] = srcDgv[j, i].Value;
}
}
excel.Workbooks[1].SaveCopyAs(fileName);//保存
}
finally
{
excel.Quit();
}
return;
}
if (type.Equals(”doc”, StringComparison.CurrentCultureIgnoreCase))
{
object path = fileName;
Object none=System.Reflection.Missing.Value;
Word.Application wordApp = new Word.Application();
Word.Document document = wordApp.Documents.Add(ref none, ref none, ref none, ref none);
Word.Table table= document.Tables.Add(document.Paragraphs.Last.Range, srcDgv.Rows.Count+1, srcDgv.Columns.Count, ref none, ref none);
try
{
for (int i = 0; i < srcDgv.Columns.Count; i++)//设置标题
{
table.Cell(1, i + 1).Range.Text = srcDgv.Columns[i].HeaderText;
}
for (int i = 0; i < srcDgv.Rows.Count; i++)//填充数据
{
for (int j = 0; j < srcDgv.Columns.Count; j++)
{
table.Cell(i + 2, j + 1).Range.Text = srcDgv[j, i].Value.ToString();
}
}
document.SaveAs(ref path, ref none, ref none, ref none, ref none, ref none, ref none, ref none, ref none, ref none, ref none, ref none, ref none, ref none, ref none, ref none);
document.Close(ref none, ref none, ref none);
}
finally
{
wordApp.Quit(ref none, ref none, ref none);
}
}
}
WORD 操作
chengzq
2009-10-29
打赏
举报
回复
也可以使用Office组件,自己写代码也可以。
chengzq
2009-10-29
打赏
举报
回复
[Quote=引用楼主 woshilaihua 的回复:]
我有一些字符串..
本来可以到处Excel的
但是现在要到出word文档..
求高手帮下忙..
最好能贴点代码出来.........
[/Quote]使用水晶报表,很方便的。
kingkongzhang
2009-10-29
打赏
举报
回复
好像有第三方的类库吧
woshilaihua
2009-10-29
打赏
举报
回复
我要导出word文档...winform应用程序啊....
jsoner
2009-10-29
打赏
举报
回复
protected void outport_Click(object sender, EventArgs e)
{
Export("application/ms-excel", "xxx.dox");
}
private void Export(string FileType, string FileName)
{
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF7;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
Response.ContentType = FileType;
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
GV_cg.RenderControl(hw);
//DataList1.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{
}
jsoner
2009-10-29
打赏
举报
回复
/// <summary> /// 导出Excel /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Button1_Click(object sender, EventArgs e) { Export("application/ms-excel", "Employee information.xls"); } /// <summary> /// 定义导出Excel的函数 /// </summary> /// <param name="FileType"></param> /// <param name="FileName"></param> private void Export(string FileType, string FileName) { Response.Charset = "GB2312"; Response.ContentEncoding = System.Text.Encoding.UTF8; Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString()); Response.ContentType = FileType; this.EnableViewState = false; StringWriter tw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(tw); GridView1.RenderControl(hw); Response.Write(tw.ToString()); Response.End(); } /// <summary> /// 此方法必重写,否则会出错 /// </summary> /// <param name="control"></param> public override void VerifyRenderingInServerForm(Control control) { } protected void Button2_Click(object sender, EventArgs e) { //Export("application/ms-excel", "Employee.doc"); Export("application/ms-word", "员工信息.doc");//都可以 }
jsoner
2009-10-29
打赏
举报
回复
这里好多的.自己找找吧.不写了.
Winform自动生成
Word文档
.rar
这个"Winform自动生成
Word文档
.rar"的压缩包提供了一个解决方案,主要用于WinForm应用程序
中
创建和
导出
Word文档
。以下是关于这个主题的详细知识讲解: 1. **WinForm**: WinForm是.NET Framework提供的一种用于...
实现winform文字
导出
到word
// 保存
Word文档
doc.SaveAs("output.docx", WdSaveFormat.wdFormatXMLDocument); doc.Close(); wordApp.Quit(); } ``` 在上面的代码
中
,我们首先创建了一个Word应用程序实例,然后添加一个新的文档。接着,...
WinForm
导出
文件为Word、Excel、文本文件的方法
在.NET框架
中
,WinForm应用程序可以利用不同的库和API来
导出
数据到Word、Excel和文本文件。在本文
中
,我们将深入探讨如何实现这个功能,主要关注提供的代码片段。 首先,我们看到`ExportFile`类,它包含了四个静态...
C# winform 图片+图片描述
导出
到word
在实际操作
中
,开发者可以参考这些文件来运行和测试代码,确保图片和描述能够正确
导出
到
Word文档
。 总之,这个项目为C# WinForms开发者提供了一种解决方案,帮助他们在应用程序
中
集成图片和描述的Word
导出
功能。...
C# 用spire
导出
word
在本案例
中
,我们将探讨如何使用Spire库在WinForm应用
中
实现
Word文档
的
导出
功能。Spire是一个功能强大的组件集,它为开发人员提供了在C#
中
处理Microsoft Office文档的能力,无需依赖Office安装。 首先,为了能够...
C#
111,098
社区成员
642,554
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章