我要用C#,NET 导出一个word文档。文档内容只要一个表格。

请高手赐教... 请高手赐教 展开
 我来答
xjysky1
2010-10-16
知道答主
回答量:7
采纳率:0%
帮助的人:10.5万
展开全部
楼上的 你能不能改写下这个例子啊? 我这个只能导出字符 不能导出表格
string title = "个人信息";
object titleLengh = title.Length;
string first = "\n 公司最近需要利用C#对项目进行编程,其" +
"中存在一个功能就是可自动生成WORD文档,但一直以来都" +
"找不到什么好办法,无奈之下,只有自已学着写一个了.";
object firstLengh = first.Length;
string second = "\n 如果能真正生成WORD文档的好处有:";
object secondLengh = second.Length;
string third = "\n1、根据数据库信息自动生成文档;";
object thirdLengh = third.Length;
string forth = "\n2、免去书写文档之苦;";
object forthLengh = forth.Length;
string fifth = "\n3、可以通过邮件方式传出文档。";
object fifthLengh = fifth.Length;
object missing;
object zero = 0;
object c = 10;
object one = 1;
object two = 2;
object tree = 3;
object four = 4;
object five = 5;
object six = 6;
object seven = 7;
object eight = 8;
object nine = 9;
object ten = 10;
Object Nothing = System.Reflection.Missing.Value;

Microsoft.Office.Interop.Word.ApplicationClass wa = new Microsoft.Office.Interop.Word.ApplicationClass();
Microsoft.Office.Interop.Word.Document WordDoc = wa.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);

missing = System.Reflection.Missing.Value;

wa.Visible = true;

wa.Documents.Add(ref missing, ref missing, ref missing, ref missing);

Microsoft.Office.Interop.Word.Range myRange = wa.ActiveDocument.Range(ref zero, ref zero);

object r = myRange;

Microsoft.Office.Interop.Word.Paragraph p = wa.ActiveDocument.Paragraphs.Add(ref r);

p.Range.InsertBefore(title);
//p.Range.Font.Size = 1;

Microsoft.Office.Interop.Word.Range titleRange = wa.ActiveDocument.Range(ref zero, ref titleLengh);

//titleRange.Font.Size = 1;
titleRange.Font.Name = "幼圆";

titleRange.Font.Color = Microsoft.Office.Interop.Word.WdColor.wdColorBlue;

//MessageBox.Show("NO.1");

//titleRange.Paragraphs.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;

Microsoft.Office.Interop.Word.Range firstR = wa.ActiveDocument.Paragraphs[1].Range;//.Item(2).Range;

Microsoft.Office.Interop.Word.Table table = WordDoc.Tables.Add(titleRange, 3, 3, ref Nothing, ref Nothing);

r = firstR;

p = wa.ActiveDocument.Paragraphs.Add(ref r);

firstR.Font.Size = 40;

firstR.Paragraphs.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;

//在表格第一单元格中添加自定义的文字内容
table.Cell(1, 1).Range.Text = "lllll";

firstR.InsertAfter(first);

//firstR.InsertParagraphAfter();

//firstR=wa.ActiveDocument.Paragraphs.Item(3).Range;
firstR.InsertAfter(second);
firstR.InsertAfter(third);
firstR.InsertAfter(forth);
firstR.InsertAfter(fifth);

Context.Response.Write("成功");
博思aippt
2024-07-20 广告
作为深圳市博思云创科技有限公司的工作人员,对于Word文档生成PPT的操作,我们有以下建议:1. 使用另存为功能:在Word中编辑完文档后,点击文件->另存为,选择PowerPoint演示文稿(*.pptx)格式,即可将文档内容转换为PPT... 点击进入详情页
本回答由博思aippt提供
百度网友9463fa8
2010-10-16 · TA获得超过164个赞
知道小有建树答主
回答量:257
采纳率:100%
帮助的人:121万
展开全部
public static void ExportWord(Control control, HttpResponse response, string fileName)
{
string strName = HttpUtility.UrlEncode(fileName);
response.Clear();
response.Buffer = true;
response.Charset = "utf-7";
response.AppendHeader("Content-Disposition", "attachment;filename=" + strName + ".doc");
response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-7");//设置输出流为简体中文
response.ContentType = "application/ms-word";//设置输出文件类型为Word文件。
response.AppendHeader("xml", @"<w:WordDocument><w:View>Print</w:View>
</w:WordDocument>");
System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN", true);
System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
if (control != null)
{
control.RenderControl(oHtmlTextWriter);//将服务器控件的内容输出
}
response.Write(oStringWriter.ToString());
response.End();
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式