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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog