TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Mack S
NA
2
474
WinForm Textbox Values to Ms word template
Sep 21 2020 5:39 AM
using System.IO;
using Spire.Doc;
//initialize word object
document = new Document();
document.LoadFromFile(samplePath);
//get strings to replace
Dictionary<string, string> dictReplace = GetReplaceDictionary();
//Replace text
foreach (KeyValuePair<string, string> kvp in dictReplace)
{
document.Replace(kvp.Key, kvp.Value, true, true);
}
//Save doc file.
document.SaveToFile(docxPath, FileFormat.Docx);
//Convert to PDF
document.SaveToFile(pdfPath, FileFormat.PDF);
MessageBox.Show("All tasks are finished.", "doc processing", MessageBoxButtons.OK, MessageBoxIcon.Information);
document.Close();
In the code above, GetReplaceDictionary() is a custom function predefined as below. By invoking this method, a Dictionary is established in which preset strings are stored as the Key and text box values are stored as the Value.
Dictionary<string, string> GetReplaceDictionary()
{
Dictionary<string, string> replaceDict = new Dictionary<string, string>();
replaceDict.Add("#name#", txtName.Text.Trim());
replaceDict.Add("#age#",txtAge.Text);
replaceDict.Add("#address#", txtAddress.Text.Trim());
replaceDict.Add("#phonenumber#",txtPhonenumber.Text);
replaceDict.Add("#emailaddress#",txtEmailaddress.Text);
replaceDict.Add("#experience#", txtExperience.Text.Trim());
replaceDict.Add("#position#", txtPosition.Text.Trim());
replaceDict.Add("#salary#", txtSalary.Text);
replaceDict.Add("#applydate#",dateTimePicker.Text);
string isEmployed= this.radio_isEmployed_Yes.Checked ? "Yes" : "No";
replaceDict.Add("#isemployed#", isEmployed);
replaceDict.Add("#education#", txtEducation.Text.Trim());
return replaceDict;
}
Coding convert to vb.net
Reply
Answers (
1
)
Linq Query Return zero rows how to make left join with linq
Get ID of recently created User Role using Identity .net core 2.0