zq198972510 2015-06-16 14:02 采纳率: 100%
浏览 1994
已采纳

在ASP.net中操作word的问题

在ASP.net中操作word时,需要保存功能,我已经引用了Microsoft Word 12.0 Object Library组件,但是在调用Document的SaveAs方法时,没有这个方法,只用一个SaveAs2方法,求解决!下面是全部代码!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using msWord = Microsoft.Office.Interop.Word;
using System.IO;
using System.Reflection;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
    object path = @"c:\123.docx";
    msWord.Application word;
    msWord.Document doc;
    object nothing = Missing.Value;

    word = new msWord.Application();
    doc = word.Documents.Add(ref nothing, ref nothing, ref nothing, ref nothing);
    msWord.Table table = doc.Tables.Add(word.Selection.Range, 5, 5, nothing, nothing);
    table.Borders.Enable = 1;
    for (int i = 1; i < 6; i++)
    {
        for (int y = 1; y < 6; y++)
        {
            table.Cell(i, y).Range.Text = "" + i + "," + y + "";
        }
    }

    object famote = msWord.WdSaveFormat.wdFormatDocumentDefault;
            //此处的没有SaveAs(),有SaveAs2(),但是提示错误,错误如下面所述。
    doc.SaveAs2( path, ref famote, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing,
        ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing);
    doc.Close(ref nothing, ref nothing, ref nothing);
    word.Quit(ref nothing, ref nothing, ref nothing);

}

}


错误提示如下:
错误 1 “Microsoft.Office.Interop.Word.Document”不包含“SaveAs2”的定义,并且找不到可接受类型为“Microsoft.Office.Interop.Word.Document”的第一个参数的扩展方法“SaveAs2”(是否缺少 using 指令或程序集引用?)

  • 写回答

5条回答

  • zq198972510 2015-07-10 13:43
    关注

    最后还是知道为什么了,因为我在新建网站的时候是新建的ASP.NET空网站,所以没有SaveAs()方法;如果新建的是ASP.NET网站,项目里会有一个引用文件夹,把上述引用添加到引用文件夹里就有SaveAs()方法了。记录下来是希望后来人少走弯路。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况