亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

如何編寫asp.net按指定模板導出word,pdf代碼

發布時間:2021-10-09 11:55:11 來源:億速云 閱讀:192 作者:iii 欄目:開發技術

這篇文章主要介紹“如何編寫asp.net按指定模板導出word,pdf代碼”,在日常操作中,相信很多人在如何編寫asp.net按指定模板導出word,pdf代碼問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”如何編寫asp.net按指定模板導出word,pdf代碼”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!

復制代碼 代碼如下:

/// <summary>
        /// 導出word文件
        /// </summary>
        /// <param name="templateFile">模板路徑</param>
        /// <param name="fileNameWord">導出文件名稱</param>
        /// <param name="fileNamePdf">pdf文件名稱</param>
        /// <param name="bookmarks">模板內書簽集合</param>
        /// <param name="invoiceline">發票條目列表</param>
        public static void GenerateWord(string templateFile, string fileNameWord, string fileNamePdf, Dictionary<string, string> bookmarks, List<InvoiceLineView> invoiceline)
        {
            Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
            File.Copy(templateFile, fileNameWord, true);
            Microsoft.Office.Interop.Word.Document doc = new Microsoft.Office.Interop.Word.Document();
            object Obj_FileName = fileNameWord;
            object Visible = false;
            object ReadOnly = false;
            object missing = System.Reflection.Missing.Value;
            doc = app.Documents.Open(ref Obj_FileName, ref missing, ref ReadOnly, ref missing, ref missing, ref missing, ref missing,
                ref missing, ref missing, ref missing, ref missing, ref Visible, ref missing, ref missing, ref missing, ref missing);
            doc.Activate();
            foreach (string bookmarkName in bookmarks.Keys)
            {

                object BookMarkName = bookmarkName;//獲得書簽名                   
                Range range = doc.Bookmarks.get_Item(ref BookMarkName).Range;//表格插入位置
                range.Text = bookmarks[bookmarkName];
            }        
          object IsSave = true;
            object FileName = fileNamePdf;
            object FileFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF;
            object LockComments = false;
            object AddToRecentFiles = true;
            object ReadOnlyRecommended = false;
            object EmbedTrueTypeFonts = false;
            object SaveNativePictureFormat = true;
            object SaveFormsData = false;
            object SaveAsAOCELetter = false;
            object Encoding = Microsoft.Office.Core.MsoEncoding.msoEncodingSimplifiedChineseGB18030;
            object InsertLineBreaks = false;
            object AllowSubstitutions = false;
            object LineEnding = Microsoft.Office.Interop.Word.WdLineEndingType.wdCRLF;
            object AddBiDiMarks = false;
            doc.SaveAs(ref FileName, ref FileFormat, ref LockComments,
                    ref missing, ref AddToRecentFiles, ref missing,
                    ref ReadOnlyRecommended, ref EmbedTrueTypeFonts,
                    ref SaveNativePictureFormat, ref SaveFormsData,
                    ref SaveAsAOCELetter, ref Encoding, ref InsertLineBreaks,
                    ref AllowSubstitutions, ref LineEnding, ref AddBiDiMarks);
            doc.Close(ref IsSave, ref missing, ref missing);
        }

調用

復制代碼 代碼如下:


Dictionary<string, string> bookmarks = new Dictionary<string, string>();
bookmarks.Add("ContractDueDateTime", invoice.InvoiceTime.AddDays(invoice.ContractDueDate).ToString("D"));
bookmarks.Add("CustomContactEmail", invoice.CustomContactEmail);
bookmarks.Add("CustomContactName", invoice.CustomContactName);
bookmarks.Add("ContractDueDate", invoice.ContractDueDate.ToString());
bookmarks.Add("CustomContactTel", invoice.CustomContactTel);
bookmarks.Add("CustomAddress", invoice.CustomAddress);
bookmarks.Add("InvoiceTime", invoice.InvoiceTime.ToString());
bookmarks.Add("InvoiceID", invoice.InvoiceID);
bookmarks.Add("CustomName", invoice.CustomName);
bookmarks.Add("CustomName2", invoice.CustomName);
bookmarks.Add("total", invoice.TotalPrice.ToString("C"));
bookmarks.Add("total1", invoice.TotalPrice.ToString("C"));
bookmarks.Add("totalTax", invoice.TotalTax.ToString("C"));
bookmarks.Add("totalPrice", (invoice.TotalPrice + invoice.TotalTax).ToString("C"));
bookmarks.Add("totalPrice1", (invoice.TotalPrice + invoice.TotalTax).ToString("C"));
bookmarks.Add("totalPrice2", (invoice.TotalPrice + invoice.TotalTax).ToString("C"));
bookmarks.Add("totalPrice3", (invoice.TotalPrice + invoice.TotalTax).ToString("C"));
bookmarks.Add("totalPrice4", (invoice.TotalPrice + invoice.TotalTax).ToString("C"));
Utility.GenerateWord(templateFile, fileNameWord, fileNamePdf, bookmarks, invoiceline);

新建一個word,在需要替換的位置插入書簽,使用以上方法即可將書簽處替換為指定內容,并且另存為pdf

到此,關于“如何編寫asp.net按指定模板導出word,pdf代碼”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續學習更多相關知識,請繼續關注億速云網站,小編會繼續努力為大家帶來更多實用的文章!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

营口市| 龙海市| 通辽市| 衡东县| 巨鹿县| 广宗县| 金堂县| 承德市| 保亭| 秦安县| 普兰店市| 景谷| 凤庆县| 江安县| 五指山市| 广汉市| 大连市| 康乐县| 十堰市| 河津市| 延长县| 徐汇区| 尼木县| 讷河市| 确山县| 河西区| 嘉祥县| 永寿县| 秦皇岛市| 利辛县| 西充县| 巴里| 新乡市| 项城市| 永福县| 洪雅县| 城口县| 陆丰市| 洛阳市| 大田县| 永安市|