到网上找了很多的资料就是解决不了,希望高手解决下如题,就是在将数据库里面的数据导入到word中的时候出现的。为什么?如果可以解决的话,我加分500分!绝对守信!
解决方案 »
- Server.MapPath在发布的网站后的问题
- 问个c#回车事件的简单问题
- 急,急,急oracle join 语句出错??
- (Knight94(愚翁))大哥请帮忙 关于RichTextBox的拖动效果
- 如何判断一个object是某个具体的对象实例?
- 请教一个C#开发cs软件的问题
- aspxgridview里chekbox取值问题
- 求助:Response.writefile为什么只能输出10m以下的文件啊?
- 请问大家打包自己的应用程序都是用的什么软件呀?
- 在C# windows应用程序中如何实现提取有效文件名和文件路径
- 如何在设计界面改变Label的大小
- 在VS2005环境下 生成网站(编译) 时 报 数据错误(循环冗余检查)
# cunzhangok
#
# 等级:
# 可用分等级:贫农
# 总技术分:27
# 总技术分排名:165433
# 结帖率:74.07%
object missing = System.Reflection.Missing.Value;
//创建Word文档
Word.Application wordApp = new Word.ApplicationClass(); wordApp.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone; //重要非常重要!!!!!!否则程序会异常,应为在工作的过程中,默认要用户交互,可是用户确没有交互,所以就出错了
Word.Document wordDoc = wordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);
wordApp.Visible = false;
wordDoc.Activate(); //设置文档宽度
wordApp.Selection.PageSetup.LeftMargin = wordApp.CentimetersToPoints(float.Parse("2"));
wordApp.ActiveWindow.ActivePane.HorizontalPercentScrolled = 11;
wordApp.Selection.PageSetup.RightMargin = wordApp.CentimetersToPoints(float.Parse("2")); Object start = Type.Missing;
Object end = Type.Missing; PictureBox pp = new PictureBox(); //新建一个PictureBox控件
object rng = Type.Missing;
string strInfo = "学生信息";
start = 0;
end = 0;
object lg = strInfo.Length;
wordDoc.Range(ref start, ref end).InsertBefore(strInfo); //插入文本
wordDoc.Range(ref start, ref lg).Font.Name = "Verdana"; //设置字体
wordDoc.Range(ref start, ref lg).Font.Size = 30; //设置字体大小
wordDoc.Range(ref start, ref lg).ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft;//设置字体局中
start = strInfo.Length;
end = strInfo.Length;
wordDoc.Range(ref start, ref end).InsertParagraphAfter();//插入回车 object missingValue = Type.Missing;
object location = strInfo.Length;
Word.Range rng2 = wordDoc.Range(ref location, ref location);
int numberlunwen = 0;
int numbergrade = 0;
int numberhome = 0;
int numberstudy = 0;
int numberperson = 12;
//检索数据库看看 几人的信息是几行numberperson 发表的论文的数目记为:numberlunwen 查找个人的受奖励和惩罚的个数:numbergrade 查找家庭成员和社会关系个数numberhome 查找学习和工作记录numberstudy 根据这个记录生成最后的记录的总的个数
int totall = numbergrade + numberhome + numberlunwen + numberperson + numberstudy;
Word.Table table1 = wordDoc.Tables.Add(rng2, 28 + 13, 8, ref missingValue, ref missingValue); //建立一个table 这里应该又什么命令可以将每个格子里面的数据设置格式的但是在网上找的例子不太行
table1.Rows.HeightRule = Word.WdRowHeightRule.wdRowHeightAtLeast;
table1.Rows.Height = wordApp.CentimetersToPoints(float.Parse("1.2"));
table1.Range.Font.Size = 10;
table1.Range.Font.Name = "宋体"; //设置表格样式
table1.Borders.Item(Word.WdBorderType.wdBorderTop).LineStyle = Word.WdLineStyle.wdLineStyleSingle;
table1.Borders.Item(Word.WdBorderType.wdBorderTop).LineWidth = Word.WdLineWidth.wdLineWidth050pt;
table1.Borders.Item(Word.WdBorderType.wdBorderTop).Color = Word.WdColor.wdColorAutomatic;
table1.Borders.Item(Word.WdBorderType.wdBorderLeft).LineStyle = Word.WdLineStyle.wdLineStyleSingle;
table1.Borders.Item(Word.WdBorderType.wdBorderLeft).LineWidth = Word.WdLineWidth.wdLineWidth050pt;
table1.Borders.Item(Word.WdBorderType.wdBorderLeft).Color = Word.WdColor.wdColorAutomatic;
table1.Borders.Item(Word.WdBorderType.wdBorderHorizontal).LineStyle = Word.WdLineStyle.wdLineStyleSingle;
table1.Borders.Item(Word.WdBorderType.wdBorderVertical).LineStyle = Word.WdLineStyle.wdLineStyleSingle;
table1.Borders.Item(Word.WdBorderType.wdBorderHorizontal).LineWidth = Word.WdLineWidth.wdLineWidth050pt;
table1.Borders.Item(Word.WdBorderType.wdBorderHorizontal).Color = Word.WdColor.wdColorAutomatic;
table1.Borders.Item(Word.WdBorderType.wdBorderVertical).LineWidth = Word.WdLineWidth.wdLineWidth050pt;
table1.Borders.Item(Word.WdBorderType.wdBorderVertical).Color = Word.WdColor.wdColorAutomatic;
table1.Borders.Item(Word.WdBorderType.wdBorderBottom).LineStyle = Word.WdLineStyle.wdLineStyleSingle;
table1.Borders.Item(Word.WdBorderType.wdBorderBottom).LineWidth = Word.WdLineWidth.wdLineWidth050pt;
wordApp.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;//设置中对其
//下面是用户的基本信息 //第1行显示
table1.Cell(1, 7).Merge(table1.Cell(4, 8));
table1.Cell(1, 1).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
table1.Cell(1, 2).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
table1.Cell(1, 3).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
table1.Cell(1, 4).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
table1.Cell(1, 5).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
table1.Cell(1, 6).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
table1.Cell(1, 1).Range.Text = "姓名";
table1.Cell(1, 2).Range.Text = "数据库姓名";
table1.Cell(1, 3).Range.Text = "性别";
table1.Cell(1, 4).Range.Text = "数据库性别";
table1.Cell(1, 5).Range.Text = "出生日期";
table1.Cell(1, 6).Range.Text = "数据库出生日期";
//第2行显示
table1.Cell(2, 2).Merge(table1.Cell(2, 4));
table1.Cell(2, 1).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
table1.Cell(2, 2).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
table1.Cell(2, 3).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
table1.Cell(2, 4).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
table1.Cell(2, 1).Range.Text = "证件号码";
table1.Cell(2, 2).Range.Text = "数据库证件号码";
table1.Cell(2, 3).Range.Text = "政治面貌";
table1.Cell(2, 4).Range.Text = "数据库政治面貌";
我有747分,绝对守信!!!
搜word导出
解决方案:
在运行里面输入:
dcomcnfg在“服务”里找到这三个服务,都去启动Distributed Transaction CoordinatorRemote Procedure Call (RPC)Security Accounts Manager如果:Distributed Transaction Coordinator 启动不了
就先在运行里面输入:
msdtc -resetlog然后在开启:Distributed Transaction Coordinator
接着关闭服务组件窗体 ,并重新打开,这个时候每个组建就有属性了
然后:在命令行中输入:dcomcnfg,会显示出“组件服务”管理器
2、打开“组件服务->计算机->我的电脑->DCOM 配置”,找到“Microsoft Word文档”,单击右键,选择“属性”
在“属性”对话框中单击“标识”选项卡,选择“交互式用户””,关闭“组件服务”管理器。
如果你用的是wps,这里的Microsoft Word文档就是wps文档,操作一样的。好了问题解决。
Catch ex As Exception
System.Threading.Thread.Sleep(1000)方法二:
在给策略类赋值前,先select一下,保证当前cell处于active