Aspose.word在asp.net mvc中如何使用的個人總結

來源:互聯網
上載者:User

標籤:

項目需要匯出資料到word中,因為要匯出的是表格形式,所以先在word中繪製好了表格,然後按照以前的代碼改了改,發現不行。出現的問題如下:

 

這是當時的代碼,問題的癥結所在就是Response上。這段代碼以前是寫在asp.NET中的。在asp.net中,Response使用的是HttpResponse,但是該項目為Mvc架構,Mvc中為HttpResponseBase,二者不能相容,不能強制轉換。問題一直無法得到解決。

所以就改變了代碼:如下。

 

public ActionResult WordExport(TrainingTheoryForSignatureDetailModel aModel)
        {
            string tmppath = Server.MapPath("~/學員報名資訊表.docx");
            Document doc = new Document(tmppath); //載入模板
            if (doc.Range.Bookmarks["Name"] != null)
            {
                Bookmark mark = doc.Range.Bookmarks["name"];
                mark.Text = aModel.Name;               
            }
            
            var docStream = new MemoryStream();
            doc.Save(docStream, SaveFormat.Doc);
            return File(docStream.ToArray(), "application/msword", "Template.doc");
        }

這樣問題就迎刃而解。

 

但是因為事先在word中繪製好了表格,所以就對需要插入資料的地方添加書籤,在代碼中擷取書籤的名字,從而對書籤的文本進行操作。

Aspose.word在asp.net mvc中如何使用的個人總結

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.