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条)

报告相同问题?

悬赏问题

  • ¥15 (关键词-电路设计)
  • ¥15 如何解决MIPS计算是否溢出
  • ¥15 vue中我代理了iframe,iframe却走的是路由,没有显示该显示的网站,这个该如何处理
  • ¥15 操作系统相关算法中while();的含义
  • ¥15 CNVcaller安装后无法找到文件
  • ¥15 visual studio2022中文乱码无法解决
  • ¥15 关于华为5g模块mh5000-31接线问题
  • ¥15 keil L6007U报错
  • ¥15 webapi 发布到iis后无法访问
  • ¥15 初学者如何快速上手学习stm32?