当前位置:编程学习 > C#/ASP.NET >>

【添加引用word 】但是版本有问题

添加了引用word   但是是2003版本的。如果是07的升级之后就所有里面调用的属性方法都错误了。
这个问题怎么修改呢。
发布之后程序点击 导出WORD的按钮的时候 提示这个错误

以下是我程序代码。
  //创建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"));
                wordDoc.Tables.Item(1).Range.Font.Size = 10;
                wordDoc.Tables.Item(1).Range.Font.Name = "宋体";

                //设置表格样式
                wordDoc.Tables.Item(1).Borders.Item(Word.WdBorderType.wdBorderLeft).LineStyle = Word.WdLineStyle.wdLineStyleSingle;
                wordDoc.Tables.Item(1).Borders.Item(Word.WdBorderType.wdBorderLeft).LineWidth = Word.WdLineWidth.wdLineWidth050pt;
                wordDoc.Tables.Item(1).Borders.Item(Word.WdBorderType.wdBorderLeft).Color = Word.WdColor.wdColorAutomatic;
                wordApp.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight;//设置右对齐

                //第5行显示
                wordDoc.Tables.Item(1).Cell(1, 5).Merge(wordDoc.Tables.Item(1).Cell(5, 6));
                //第6行显示
                wordDoc.Tables.Item(1).Cell(6, 5).Merge(wordDoc.Tables.Item(1).Cell(6, 6));
                //第9行显示
                wordDoc.Tables.Item(1).Cell(9, 4).Merge(wordDoc.Tables.Item(1).Cell(9, 6));
                //第12行显示
                wordDoc.Tables.Item(1).Cell(12, 2).Merge(wordDoc.Tables.Item(1).Cell(12, 6));
                //第13行显示
                wordDoc.Tables.Item(1).Cell(13, 2).Merge(wordDoc.Tables.Item(1).Cell(13, 6));
                //第14行显示
                wordDoc.Tables.Item(1).Cell(14, 2).Merge(wordDoc.Tables.Item(1).Cell(14, 6));

                //第1行赋值
                wordDoc.Tables.Item(1).Cell(1, 1).Range.Text = "职工编号:";
                wordDoc.Tables.Item(1).Cell(1, 2).Range.Text = MyDS_Grid.Tables[0].Rows[i][0].ToString();
                wordDoc.Tables.Item(1).Cell(1, 3).Range.Text = "职工姓名:";
                wordDoc.Tables.Item(1).Cell(1, 4).Range.Text = MyDS_Grid.Tables[0].Rows[i][1].ToString();

                //插入图片

                if (p1 == 0)
                {
                    string FileName = @"C:\22.bmp";//图片所在路径
                    object LinkToFile = false;
                    object SaveWithDocument = true;
                    object Anchor = wordDoc.Tables.Item(1).Cell(1, 5).Range;    //指定图片插入的区域
                    //将图片插入到单元格中
                    wordDoc.Tables.Item(1).Cell(1, 5).Range.InlineShapes.AddPicture(FileName, ref LinkToFile, ref SaveWithDocument, ref Anchor);
                }
                p1 = 0;

                //第2行赋值
                wordDoc.Tables.Item(1).Cell(2, 1).Range.Text = "民族类别:";
                wordDoc.Tables.Item(1).Cell(2, 2).Range.Text = MyDS_Grid.Tables[0].Rows[i][2].ToString();
                wordDoc.Tables.Item(1).Cell(2, 3).Range.Text = "出生日期:";
                try
                {
                    wordDoc.Tables.Item(1).Cell(2, 4).Range.Text = Convert.ToString(Convert.ToDateTime(MyDS_Grid.Tables[0].Rows[i][3]).ToShortDateString());
                }
                catch { wordDoc.Tables.Item(1).Cell(2, 4).Range.Text = ""; }
                    //Convert.ToString(MyDS_Grid.Tables[0].Rows[i][3]);
                //第3行赋值
                wordDoc.Tables.Item(1).Cell(3, 1).Range.Text = "年龄:";
                wordDoc.Tables.Item(1).Cell(3, 2).Range.Text = Convert.ToString(MyDS_Grid.Tables[0].Rows[i][4]);
                wordDoc.Tables.Item(1).Cell(3, 3).Range.Text = "文化程序:";
                wordDoc.Tables.Item(1).Cell(3, 4).Range.Text = MyDS_Grid.Tables[0].Rows[i][5].ToString();
                //第4行赋值
                wordDoc.Tables.Item(1).Cell(4, 1).Range.Text = "婚姻:";
                wordDoc.Tables.Item(1).Cell(4, 2).Range.Text = MyDS_Grid.Tables[0].Rows[i][6].ToString();
                wordDoc.Tables.Item(1).Cell(4, 3).Range.Text = "性别:";
                wordDoc.Tables.Item(1).Cell(4, 4).Range.Text = MyDS_Grid.Tables[0].Rows[i][7].ToString();
                //第5行赋值
                wordDoc.Tables.Item(1).Cell(5, 1).Range.Text = "政治面貌:";
                wordDoc.Tables.Item(1).Cell(5, 2).Range.Text = MyDS_Grid.Tables[0].Rows[i][8].ToString();
                wordDoc.Tables.Item(1).Cell(5, 3).Range.Text = "单位工作时间:";
                try
                {
                    wordDoc.Tables.Item(1).Cell(5, 4).Range.Text = Convert.ToString(Convert.ToDateTime(MyDS_Grid.Tables[0].Rows[0][10]).ToShortDateString());
                }
                catch { wordDoc.Tables.Item(1).Cell(5, 4).Range.Text = ""; }
--------------------编程问答-------------------- Interop.Word.dll  这个是 word的DLL文件  版本 是 8.1.0.0 --------------------编程问答-------------------- 要更新为07的dll,03的不行了 --------------------编程问答-------------------- 重新添加对word  dll的引用 --------------------编程问答-------------------- 添加  Microsoft.Office.Interop.Word.dll 12.0  --------------------编程问答-------------------- 但是添加之后 我代码里面 的 那些 属性方法都得从新写了?   擦  不是吧。。。。因为添加之后的话  就报错误了。。。。没有现在调用的东西了。。。 --------------------编程问答-------------------- 不需要重写吧,要不把03的那个dll保存下来。这样简单写  --------------------编程问答--------------------
引用 2 楼  的回复:
要更新为07的dll,03的不行了

我的问题就是更新之后   代码里面 word很多方法 属性什么的  都报错了。需要解决这个问题 --------------------编程问答--------------------
引用 6 楼 licai1210 的回复:
不需要重写吧,要不把03的那个dll保存下来。这样简单写


问题就是保存下来了    就发布之后 就错误了啊。 --------------------编程问答-------------------- 怎么个情况
--------------------编程问答-------------------- 请问这个问题解决了么,同问~求解决方案 --------------------编程问答-------------------- 一般不建议使用系统组建,,因为有局限性。。建议使用第三方组建  

比如

aspose.words 相关代码请自己搜索
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,