In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "how to write asp.net to export word,pdf code according to the specified template". In daily operation, I believe many people have doubts about how to write asp.net to export word,pdf code according to the specified template. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer "how to write asp.net to export word,pdf code according to the specified template". Next, please follow the editor to study!
The copy code is as follows:
/ / /
/ Export word file
/ / /
/ / template path
/ / Export file name
/ pdf file name
/ / A collection of bookmarks in the template
/ / invoice entry list
Public static void GenerateWord (string templateFile, string fileNameWord, string fileNamePdf, Dictionary bookmarks, List 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 Visible, ref missing, ref missing)
Doc.Activate ()
Foreach (string bookmarkName in bookmarks.Keys)
{
Object BookMarkName = bookmarkName;// get the book signature
Range range = doc.Bookmarks.get_Item (ref BookMarkName). Range;// table insertion position
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)
}
Call
The copy code is as follows:
Dictionary bookmarks = new Dictionary ()
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)
Create a new word, insert a bookmark where you need to replace it, use the above method to replace the bookmark with the specified content, and save as pdf
At this point, the study on "how to write asp.net to export word,pdf code according to the specified template" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.