vs.net2005 中word 打印问题?

we_may 2009-04-12 12:58:26
我下载了一个c#开发的windows 应用程序,其中有一个页面涉及到word打印.具体就是把页面中许多的TextBox中的内容插入到word中的表格,部分代码如下:

private void but_Table_Click(object sender, EventArgs e)//按钮事件
{

object Nothing = System.Reflection.Missing.Value;
object missing = System.Reflection.Missing.Value;
//创建Word文档
Word.Application wordApp = new Word.ApplicationClass();
Word.Document wordDoc = wordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);
wordApp.Visible = true;

//设置文档宽度
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控件
int p1 = 0;
for (int i = 0; i < MyDS_Grid.Tables[0].Rows.Count; i++)
{
try
{
byte[] pic = (byte[])(MyDS_Grid.Tables[0].Rows[i][23]); //将数据库中的图片转换成二进制流
MemoryStream ms = new MemoryStream(pic); //将字节数组存入到二进制流中
pp.Image = Image.FromStream(ms); //二进制流Image控件中显示
pp.Image.Save(@"C:\22.bmp"); //将图片存入到指定的路径
}
catch
{
p1 = 1;
}
object rng = Type.Missing;
string strInfo = "职工基本信息表" + "(" + MyDS_Grid.Tables[0].Rows[i][1].ToString() + ")";
start = 0;
end = 0;
wordDoc.Range(ref start, ref end).InsertBefore(strInfo); //插入文本
wordDoc.Range(ref start, ref end).Font.Name = "Verdana"; //设置字体
wordDoc.Range(ref start, ref end).Font.Size = 20; //设置字体大小
wordDoc.Range(ref start, ref end).ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter; //设置字体局中

start = strInfo.Length;
end = strInfo.Length;
wordDoc.Range(ref start, ref end).InsertParagraphAfter();//插入回车

object missingValue = Type.Missing;
object location = strInfo.Length; //如果location超过已有字符的长度将会出错。一定要比"明细表"串多一个字符
Word.Range rng2 = wordDoc.Range(ref location, ref location);

wordDoc.Tables.Add(rng2, 14, 6, ref missingValue, ref missingValue);
wordDoc.Tables.Item(1).Rows.HeightRule = Word.WdRowHeightRule.wdRowHeightAtLeast;
wordDoc.Tables.Item(1).Rows.Height = wordApp.CentimetersToPoints(float.Parse("0.8"));

生成项目时,提示"Word.Tables并不包含Item的定义".已引用Word
请问这是怎么回事????
...全文
108 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
raines8231 2009-11-16
  • 打赏
  • 举报
回复
Word.Tables”并不包含“Item”的定义的解决办法 2009-05-03 14:25 C#调用WORD时出错如下: object missingValue = Type.Missing; object location = strInfo.Length; //如果location超过已有字符的长度将会出错。一定要比"明细表"串多一个字符 Word.Range rng2 = wordDoc.Range(ref location, ref location); wordDoc.Tables.Add(rng2, 14, 6, ref missingValue, ref missingValue); wordDoc.Tables.Item(1).Rows.HeightRule = Word.WdRowHeightRule.wdRowHeightAtLeast;//错误在这里 “Word.Tables”并不包含“Item”的定义 wordDoc.Tables.Item(1).Rows.Height = wordApp.CentimetersToPoints(float.Parse("0.8"));//错误在这里“Word.Tables”并不包含“Item”的定义 wordDoc.Tables.Item(1).Range.Font.Size = 10;//错误在这里“Word.Tables”并不包含“Item”的定义 wordDoc.Tables.Item(1).Range.Font.Name = "宋体";//错误在这里“Word.Tables”并不包含“Item”的定义解决办法:1、填加引用:Microsoft Office 11.0 Object Library ;2、把Tables.Item(1)改成Tables[1]。
来自百度空间

钛元素 2009-04-15
  • 打赏
  • 举报
回复
能直接调用打印界面么

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧