我下载了一个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
请问这是怎么回事????
{ 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
请问这是怎么回事????
来自百度空间