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 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?