/// <summary> /// Add custom properties to a document. /// </summary> public static void AddCustomProperties() { Console.WriteLine("\tAddCustomProperties()"); // Create a new document. using (DocX document = DocX.Create(DocumentSample.DocumentSampleOutputDirectory + @"AddCustomProperties.docx")) { // Add a title document.InsertParagraph("Adding Custom Properties to a document").FontSize(15d).SpacingAfter(50d).Alignment = Alignment.center; //Add custom properties to document. document.AddCustomProperty(new CustomProperty("CompanyName", "Xceed Software inc.")); document.AddCustomProperty(new CustomProperty("Product", "Xceed Words for .NET")); document.AddCustomProperty(new CustomProperty("Address", "10 Boul. de Mortagne")); document.AddCustomProperty(new CustomProperty("Date", DateTime.Now)); // Add a paragraph displaying the number of custom properties. var p = document.InsertParagraph("This document contains ").Append(document.CustomProperties.Count.ToString()).Append(" Custom Properties :"); p.SpacingAfter(30); // Display each propertie's name and value. foreach (var prop in document.CustomProperties) { document.InsertParagraph(prop.Value.Name).Append(" = ").Append(prop.Value.Value.ToString()).AppendLine(); } // Save this document to disk. document.Save(); Console.WriteLine("\tCreated: AddCustomProperties.docx\n"); } }
private DocX CreateInvoiceFromTemplate(DocX template) { template.AddCustomProperty(new CustomProperty("HoTen", this.name)); template.AddCustomProperty(new CustomProperty("DiaChi", this.address)); template.AddCustomProperty(new CustomProperty("Sdt", this.sdt)); //table //var t = template.Tables[0]; //CreateAndInsertInvoiceTableAfter(t, ref template); //t.Remove(); return(template); }
static private DocX CreateInvoiceFromTemplate(DocX template) { template.AddCustomProperty(new CustomProperty("Ngay", DateTime.Today.ToString("yyyy-MM-dd"))); template.AddCustomProperty(new CustomProperty("Lop", "khoi A")); template.AddCustomProperty(new CustomProperty("GiaoVien", LoginUser.UserData()["tennv"].ToString())); //table var t = template.Tables[0]; CreateAndInsertInvoiceTableAfter(t, ref template); t.Remove(); return(template); }
private static void FillAttrVal(Dictionary <string, string> dics, ref DocX document) { foreach (KeyValuePair <string, string> kvp in dics) { document.AddCustomProperty(new CustomProperty(kvp.Key, kvp.Value)); } }
// Create an invoice for a factitious company called "The Happy Builder". private static DocX CreateInvoiceFromTemplate(DocX template) { #region Logo // A quick glance at the template shows us that the logo Paragraph is in row zero cell 1. Paragraph logo_paragraph = template.Tables[0].Rows[0].Cells[1].Paragraphs[0]; // Remove the template Picture that is in this Paragraph. logo_paragraph.Pictures[0].Remove(); // Add the Happy Builders logo to this document. Novacode.Image logo = template.AddImage(@"images\logo_the_happy_builder.png"); // Insert the Happy Builders logo into this Paragraph. logo_paragraph.InsertPicture(logo.CreatePicture()); #endregion #region Set CustomProperty values // Set the value of the custom property 'company_name'. template.AddCustomProperty(new CustomProperty("company_name", "The Happy Builder")); // Set the value of the custom property 'company_slogan'. template.AddCustomProperty(new CustomProperty("company_slogan", "No job too small")); // Set the value of the custom properties 'hired_company_address_line_one', 'hired_company_address_line_two' and 'hired_company_address_line_three'. template.AddCustomProperty(new CustomProperty("hired_company_address_line_one", "The Crooked House,")); template.AddCustomProperty(new CustomProperty("hired_company_address_line_two", "Dublin,")); template.AddCustomProperty(new CustomProperty("hired_company_address_line_three", "12345")); // Set the value of the custom property 'invoice_date'. template.AddCustomProperty(new CustomProperty("invoice_date", DateTime.Today.Date.ToString("d"))); // Set the value of the custom property 'invoice_number'. template.AddCustomProperty(new CustomProperty("invoice_number", 1)); // Set the value of the custom property 'hired_company_details_line_one' and 'hired_company_details_line_two'. template.AddCustomProperty(new CustomProperty("hired_company_details_line_one", "Business Street, Dublin, 12345")); template.AddCustomProperty(new CustomProperty("hired_company_details_line_two", "Phone: 012-345-6789, Fax: 012-345-6789, e-mail: [email protected]")); #endregion /* * InvoiceTemplate.docx contains a blank Table, * we want to replace this with a new Table that * contains all of our invoice data. */ Table t = template.Tables[1]; Table invoice_table = CreateAndInsertInvoiceTableAfter(t, ref template); t.Remove(); // Return the template now that it has been modified to hold all of our custom data. return(template); }
//tạo hóa đơn từ mẫu static private DocX CreateInvoiceFromTemplate(DocX template, string id) { DataTable dt = DataController.ExecTable(" select manv,mathungoai,tenthungoai,tg,sotienthu from thungoai where mathungoai=" + id); DataRow data = dt.Rows[0]; DataTable dt2 = DataController.ExecTable(" select tennv,diachi from nhanvien where manv = " + data["manv"].ToString()); DataRow data2 = dt2.Rows[0]; template.AddCustomProperty(new CustomProperty("angay", Convert.ToDateTime(data["tg"].ToString()).ToString("dd"))); template.AddCustomProperty(new CustomProperty("athang", Convert.ToDateTime(data["tg"].ToString()).ToString("MM"))); template.AddCustomProperty(new CustomProperty("anam", Convert.ToDateTime(data["tg"].ToString()).ToString("yyyy"))); template.AddCustomProperty(new CustomProperty("asotienthu", data["sotienthu"].ToString())); template.AddCustomProperty(new CustomProperty("adiachi", data2["diachi"].ToString())); template.AddCustomProperty(new CustomProperty("atennv", data2["tennv"].ToString())); template.AddCustomProperty(new CustomProperty("anguoilap", LoginUser.UserData()["tennv"].ToString())); template.AddCustomProperty(new CustomProperty("atenthungoai", data["tenthungoai"].ToString())); return(template); // lưu vào template }
//tạo hóa đơn từ mẫu static private DocX CreateInvoiceFromTemplate(DocX template, string id) { DataTable dt = DataController.ExecTable(" select phieuchi.maphieuchi,tenphieuchi,tg,manv,sum(thanhtien) as tongtien from phieuchi,tttienchi where phieuchi.maphieuchi=tttienchi.maphieuchi and phieuchi.maphieuchi = " + id + " group by phieuchi.maphieuchi,tg,manv,tenphieuchi "); DataRow data = dt.Rows[0]; DataTable dt2 = DataController.ExecTable(" select tennv,diachi from nhanvien where manv = " + data["manv"].ToString()); DataRow data2 = dt2.Rows[0]; template.AddCustomProperty(new CustomProperty("angay", Convert.ToDateTime(data["tg"].ToString()).ToString("dd"))); template.AddCustomProperty(new CustomProperty("athang", Convert.ToDateTime(data["tg"].ToString()).ToString("MM"))); template.AddCustomProperty(new CustomProperty("anam", Convert.ToDateTime(data["tg"].ToString()).ToString("yyyy"))); template.AddCustomProperty(new CustomProperty("atongtien", data["tongtien"].ToString())); template.AddCustomProperty(new CustomProperty("adiachi", data2["diachi"].ToString())); template.AddCustomProperty(new CustomProperty("atennhanvien", data2["tennv"].ToString())); template.AddCustomProperty(new CustomProperty("anguoilap", LoginUser.UserData()["tennv"].ToString())); template.AddCustomProperty(new CustomProperty("atenphieuchi", data["tenphieuchi"].ToString())); //table var t = template.Tables[0]; //tạo hóa đơn từ template CreateAndInsertInvoiceTableAfter(t, ref template, id); t.Remove();// xóa giữ liệu table //return template; // lưu vào template // var t2 = template.Tables[1]; //tạo hóa đơn từ template CreateAndInsertInvoiceTableAfter2(t2, ref template, id); t2.Remove();// xóa giữ liệu table var t3 = template.Tables[2]; //tạo hóa đơn từ template CreateAndInsertInvoiceTableAfter3(t3, ref template, id); t3.Remove(); // xóa giữ liệu table return(template); // lưu vào template }
//tạo hóa đơn từ mẫu static private DocX CreateInvoiceFromTemplate(DocX template, string id) { DataTable dt = DataController.ExecTable(" select phieubangiao.maphieubangiao,tenphieubangiao,makhoi,tg,manv from ttbangiao,phieubangiao where phieubangiao.maphieubangiao=ttbangiao.maphieubangiao and phieubangiao.maphieubangiao= " + 1 + " group by phieubangiao.maphieubangiao,tenphieubangiao,makhoi,tg,manv "); DataRow data = dt.Rows[0]; DataTable dt2 = DataController.ExecTable(" select tennv,diachi from nhanvien where manv = " + data["manv"].ToString()); DataRow data2 = dt2.Rows[0]; DataTable dt3 = DataController.ExecTable(" select tenkhoi from khoi where makhoi= " + data["makhoi"].ToString()); DataRow data3 = dt3.Rows[0]; template.AddCustomProperty(new CustomProperty("angay", Convert.ToDateTime(data["tg"].ToString()).ToString("dd"))); template.AddCustomProperty(new CustomProperty("athang", Convert.ToDateTime(data["tg"].ToString()).ToString("MM"))); template.AddCustomProperty(new CustomProperty("anam", Convert.ToDateTime(data["tg"].ToString()).ToString("yyyy"))); template.AddCustomProperty(new CustomProperty("atenkhoi", data3["tenkhoi"].ToString())); template.AddCustomProperty(new CustomProperty("adiachi", data2["diachi"].ToString())); template.AddCustomProperty(new CustomProperty("atennv", data2["tennv"].ToString())); template.AddCustomProperty(new CustomProperty("anguoilap", LoginUser.UserData()["tennv"].ToString())); template.AddCustomProperty(new CustomProperty("atenphieubangiao", data["tenphieubangiao"].ToString())); //table var t = template.Tables[0]; //tạo hóa đơn từ template CreateAndInsertInvoiceTableAfter(t, ref template, id); t.Remove();// xóa giữ liệu table //return template; // lưu vào template // var t2 = template.Tables[1]; //tạo hóa đơn từ template CreateAndInsertInvoiceTableAfter2(t2, ref template, id); t2.Remove(); // xóa giữ liệu table return(template); // lưu vào template }
//tạo hóa đơn từ mẫu static private DocX CreateInvoiceFromTemplate(DocX template, string id) { DataTable dt = DataController.ExecTable(" select tonghocphi,mahocsinh,mabctt from hoadonthang where mahoadonthang= " + id + " group by tonghocphi,mahocsinh,mabctt;"); DataRow data = dt.Rows[0]; string B = "Không có vé tháng của tháng này"; DataTable dt2 = DataController.ExecTable(" select mavethang,maloaivethang,mahocsinh,ngaydangky,mahoadonthang from vethang where vethang.mahoadonthang=" + id + " and mahocsinh= " + data["mahocsinh"].ToString()); if (dt2.Rows.Count > 0) { DataRow data2 = dt2.Rows[0]; DataTable dt3 = DataController.ExecTable(" select tenloaivethang,gia from loaivethang where maloaivethang= " + data2["maloaivethang"].ToString()); DataRow data3 = dt3.Rows[0]; B = data3["gia"].ToString(); } DataTable dt4 = DataController.ExecTable(" select thang,nam from hoadonthang,baocao where hoadonthang.mabctt=baocao.mabctt and mahoadonthang= " + id); DataRow data4 = dt4.Rows[0]; DataTable dt5 = DataController.ExecTable(" select tenkhoi,diachi,tenhocsinh,hocphi from khoi,hocsinh,phanloai where khoi.maphanloai=phanloai.maphanloai and hocsinh.makhoi=khoi.makhoi and mahocsinh=" + data["mahocsinh"].ToString()); DataRow data5 = dt5.Rows[0]; DataTable dt6 = DataController.ExecTable(" select count(*) as sobuoidaydu from theodoixuatan,baocao where baocao.mabctt=" + (int.Parse(data["mabctt"].ToString()) - 1).ToString() + " and mahinhthucan=1 and mahocsinh= " + data["mahocsinh"].ToString()); DataRow data6 = dt6.Rows[0]; DataTable dt7 = DataController.ExecTable(" select count(*) as sobuoikhongdaydu from theodoixuatan,baocao where baocao.mabctt=" + (int.Parse(data["mabctt"].ToString()) - 1).ToString() + " and mahinhthucan=2 and mahocsinh= " + data["mahocsinh"].ToString()); DataRow data7 = dt7.Rows[0]; DataTable dt8 = DataController.ExecTable(" select count(*) as sobuoikhongan from theodoixuatan,baocao where baocao.mabctt=" + (int.Parse(data["mabctt"].ToString()) - 1).ToString() + " and mahinhthucan=3 and mahocsinh= " + data["mahocsinh"].ToString()); DataRow data8 = dt8.Rows[0]; String A; DataTable dt9 = DataController.ExecTable(" select tenloaivethang from loaivethang,vethang where mahoadonthang=(select mahoadonthang from hoadonthang where mahocsinh=" + data["mahocsinh"].ToString() + "and hoadonthang.mabctt=" + (int.Parse(data["mabctt"].ToString()) - 1).ToString() + ") "); if (dt9.Rows.Count == 0) { A = "Không có vé tháng của tháng trước"; } else { DataRow data9 = dt9.Rows[0]; A = data9["tenloaivethang"].ToString(); } template.AddCustomProperty(new CustomProperty("adatenow", DateTime.Today.ToString("dd-MM-yyyy"))); template.AddCustomProperty(new CustomProperty("athang", data4["thang"].ToString())); template.AddCustomProperty(new CustomProperty("anam", data4["nam"].ToString())); template.AddCustomProperty(new CustomProperty("atenkhoi", data5["tenkhoi"].ToString())); template.AddCustomProperty(new CustomProperty("atenhocsinh", data5["tenhocsinh"].ToString())); template.AddCustomProperty(new CustomProperty("adiachi", data5["diachi"].ToString())); template.AddCustomProperty(new CustomProperty("ahocphi", data5["hocphi"].ToString())); template.AddCustomProperty(new CustomProperty("agia", B)); template.AddCustomProperty(new CustomProperty("atongtientru", data5["diachi"].ToString())); template.AddCustomProperty(new CustomProperty("asobuoidaydu", data6["sobuoidaydu"].ToString())); template.AddCustomProperty(new CustomProperty("asobuoikhongdaydu", data7["sobuoikhongdaydu"].ToString())); template.AddCustomProperty(new CustomProperty("asobuoikhongan", data8["sobuoikhongan"].ToString())); template.AddCustomProperty(new CustomProperty("atenvethangtruoc", A)); template.AddCustomProperty(new CustomProperty("atonghocphi", data["tonghocphi"].ToString())); //table var t = template.Tables[0]; //tạo hóa đơn từ template CreateAndInsertInvoiceTableAfter(t, ref template, id); t.Remove(); // xóa giữ liệu table //return template; // lưu vào template // var t2 = template.Tables[1]; //tạo hóa đơn từ template CreateAndInsertInvoiceTableAfter2(t2, ref template, id); t2.Remove(); // xóa giữ liệu table return(template); // lưu vào template }
private DocX CreateInvoiceFromTemplate(DocX template) { template.AddCustomProperty(new Novacode.CustomProperty("DieuTraVien", CommonParam.mSesData.inspectData._Ten)); template.AddCustomProperty(new Novacode.CustomProperty("GiamSatVien1", CommonParam.mSesData.supervisorData1._Ten)); template.AddCustomProperty(new Novacode.CustomProperty("GiamSatVien2", CommonParam.mSesData.supervisorData2._Ten)); template.AddCustomProperty(new Novacode.CustomProperty("ThoiGianDienRa", CommonParam.mSesData.sessBeginTime)); template.AddCustomProperty(new Novacode.CustomProperty("BC_Ten", CommonParam.mSesData.suspectData._Ten)); template.AddCustomProperty(new Novacode.CustomProperty("BC_GioiTinh", CommonParam.mSesData.suspectData._GioiTinh)); template.AddCustomProperty(new Novacode.CustomProperty("BC_QuocTich", CommonParam.mSesData.suspectData._QuocTich)); template.AddCustomProperty(new Novacode.CustomProperty("BC_TenGoiKhac", CommonParam.mSesData.suspectData._TenGoiKhac)); template.AddCustomProperty(new Novacode.CustomProperty("BC_NgaySinh", CommonParam.mSesData.suspectData._NgaySinh)); template.AddCustomProperty(new Novacode.CustomProperty("BC_NoiSinh", CommonParam.mSesData.suspectData._NoiSinh)); template.AddCustomProperty(new Novacode.CustomProperty("BC_DanToc", CommonParam.mSesData.suspectData._DanToc)); template.AddCustomProperty(new Novacode.CustomProperty("BC_TonGiao", CommonParam.mSesData.suspectData._TonGiao)); template.AddCustomProperty(new Novacode.CustomProperty("BC_NgheNghiep", CommonParam.mSesData.suspectData._NgheNghiep)); template.AddCustomProperty(new Novacode.CustomProperty("BC_SoCMND", CommonParam.mSesData.suspectData._CMND)); template.AddCustomProperty(new Novacode.CustomProperty("BC_NgayCapCMND", CommonParam.mSesData.suspectData._NgayCapCMND)); template.AddCustomProperty(new Novacode.CustomProperty("BC_NoiCuTru", CommonParam.mSesData.suspectData._DiaChi)); template.AddCustomProperty(new Novacode.CustomProperty("BC_NoiCapCMND", CommonParam.mSesData.suspectData._NoiCapCMND)); template.AddCustomProperty(new Novacode.CustomProperty("DiaDiemHoiCung", CommonParam.mSesData.sessPlace)); template.AddCustomProperty(new Novacode.CustomProperty("ThoiGianKetThuc", CommonParam.mSesData.sessEndTime)); template.AddCustomProperty(new Novacode.CustomProperty("NgayHoiCung", CommonParam.mSesData.sessCurrDate)); template.AddCustomProperty(new Novacode.CustomProperty("DiaDiemHoiCung", CommonParam.mSesData.sessPlace)); template.AddCustomProperty(new Novacode.CustomProperty("GhiChu", CommonParam.mSesData.sessNotes)); return(template); }
public static DocX CreateDocA(DocX template, SRViewModel model) { //Create Date for Header // string Fdate = model.date.ToString(); //string[] d = Fdate.Split(' '); //Fdate = d[0]; //Fdate = formatdate(Fdate, model); //Create Distrbution for Header string Fdist = distrb(model.Cat); string Folang = "English"; //Session Numer string Fsnum = "[NUMBER]"; if (!String.IsNullOrEmpty(model.sNum)) { Fsnum = Sessionnum(model); } //sYMBOLE string symb = getSym(model.Cat); string[] sym = symb.Split(new string[] { "#" }, StringSplitOptions.None); string x = sym[1]; x = model.Prep.ToString() + x; string Fsym1 = x; string Fmnum = GetOrdinalSuffix(Convert.ToInt32(model.Prep.ToString())); //second page meeting date string Fsodate = ""; if (model.time.ToString() == "at 10 a.m.") { Fsodate = "The meeting was called to order at 10 a.m."; } if (model.time.ToString() == "at 3 p.m.") { Fsodate = "The meeting was called to order at 3 p.m."; } //QR code and Bar code string lang = getlanguageQR(model.lang_ID); string Fsym = getSym(model.Cat); //Fsym = Fsym.Remove(Fsym.Length-1); // Fsym = Fsym + Fsym1; Fsym = Fsym.Replace("#", model.Prep.ToString()); string url = "http://undocs.org/m2/QRCode.ashx?DS=" + Fsym + "&Size=2&Lang=" + lang; using (var client = new WebClient()) { //var content = client.DownloadData("https://api.qrserver.com/v1/create-qr-code/?size=66x66&data=http://undocs.org/fr/A/HRC/70"); //var content = client.DownloadData("http://undocs.org/m2/QRCode.ashx?DS=A/HRC/70&Size=2&Lang=F"); var content = client.DownloadData(url); using (var str1 = new MemoryStream(content)) { Image image = template.AddImage(str1); Picture p = image.CreatePicture(); Footer f = template.Footers.first; Table t = f.Tables[0]; //t.Rows[0].Cells[1].Paragraphs.First().AppendPicture(pR); t.Rows[0].Cells[1].Paragraphs.First().AppendPicture(p); } } string Floc = model.loca.ToString() + ", " + model.locb.ToString(); //string Fvirs = ""; //if (model.ver != null) //{ // Fvirs = getVerisons(model); //} //create barcode & gdoc string Fbar = " "; string gdoc = " "; string Fgdocf = " "; if (!String.IsNullOrEmpty(model.Gdoc)) { gdoc = model.Gdoc.ToString(); Fbar = "*" + gdoc + "*"; Fgdocf = gdoc; gdoc = gdoc.Insert(2, "-"); } string Fdname = ""; if (!String.IsNullOrEmpty(model.Cname)) { Fdname = model.Ctitle.ToString() + model.Cname.ToString(); } if (String.IsNullOrEmpty(model.Cname)) { int deleteStart = 0; int deleteEnd = 0; //Get the array of the paragraphs containing the start and end catches for (int i = 0; i < template.Paragraphs.Count; i++) { if (template.Paragraphs[i].Text.Contains("Chair:")) { deleteStart = i; } if (template.Paragraphs[i].Text.Contains("dname")) { deleteEnd = i; } } if (deleteStart > 0 && deleteEnd > 0) { //delete from the paraIndex as the arrays will shift when a paragraph is deleted int paraIndex = deleteStart; for (int i = deleteStart; i <= deleteEnd; i++) { template.RemoveParagraphAt(paraIndex); } } } string Flname1 = ""; string Flname2 = ""; if (!String.IsNullOrEmpty(model.L1name)) { Flname1 = model.L1title.ToString() + model.L1name.ToString(); } if (!String.IsNullOrEmpty(model.L2name)) { Flname2 = model.L2title.ToString() + model.L2name.ToString(); } if (String.IsNullOrEmpty(model.L1name)) { int deleteStart = 0; int deleteEnd = 0; int deleteStart1 = 0; int deleteEnd1 = 0; for (int i = 0; i < template.Paragraphs.Count; i++) { if (template.Paragraphs[i].Text.Contains("later") && template.Paragraphs[i].Text.Contains("lname2")) { deleteStart1 = i; } if (template.Paragraphs[i].Text.Contains("lname2")) { deleteEnd1 = i; } } //Get the array of the paragraphs containing the start and end catches for (int i = 0; i < template.Paragraphs.Count; i++) { if (template.Paragraphs[i].Text.Contains("later") && template.Paragraphs[i].Text.Contains("lname1")) { deleteStart = i; } if (template.Paragraphs[i].Text.Contains("lname1")) { deleteEnd = i; } } if (deleteStart1 > 0 && deleteEnd1 > 0) { //delete from the paraIndex as the arrays will shift when a paragraph is deleted int paraIndex = deleteStart1; for (int i = deleteStart1; i <= deleteEnd1; i++) { template.RemoveParagraphAt(paraIndex); } } if (deleteStart > 0 && deleteEnd > 0) { //delete from the paraIndex as the arrays will shift when a paragraph is deleted int paraIndex = deleteStart; for (int i = deleteStart; i <= deleteEnd; i++) { template.RemoveParagraphAt(paraIndex); } } //Get the array of the paragraphs containing the start and end catches } if (String.IsNullOrEmpty(model.L2name) && !String.IsNullOrEmpty(model.L1name)) { int deleteStart = 0; int deleteEnd = 0; for (int i = 0; i < template.Paragraphs.Count; i++) { if (template.Paragraphs[i].Text.Contains("later") && template.Paragraphs[i].Text.Contains("lname2")) { deleteStart = i; } if (template.Paragraphs[i].Text.Contains("lname2")) { deleteEnd = i; } } if (deleteStart > 0 && deleteEnd > 0) { //delete from the paraIndex as the arrays will shift when a paragraph is deleted int paraIndex = deleteStart; for (int i = deleteStart; i <= deleteEnd; i++) { template.RemoveParagraphAt(paraIndex); } } } string[] info1 = info(model); string Fldate = formatdate1(model); string xxx = DateTime.Now.ToString(); template.AddCustomProperty(new CustomProperty("gdoc", gdoc)); template.AddCustomProperty(new CustomProperty("gdocf", Fgdocf)); template.AddCustomProperty(new CustomProperty("bar", Fbar)); template.AddCustomProperty(new CustomProperty("osdate", Fsodate)); template.AddCustomProperty(new CustomProperty("sym1", Fsym1)); //template. // template.ReplaceText(Fsym, Fsym, false, RegexOptions.IgnoreCase); template.AddCustomProperty(new CustomProperty("symh", Fsym)); // template.ReplaceText(sym, sym, false, RegexOptions.IgnoreCase); template.AddCustomProperty(new CustomProperty("olang", Folang)); template.AddCustomProperty(new CustomProperty("dist", Fdist)); // template.ReplaceText("dist", Fdist, false, RegexOptions.IgnoreCase); template.AddCustomProperty(new CustomProperty("date", " ")); template.AddCustomProperty(new CustomProperty("ldate", Fldate)); // template.ReplaceText("date", Fdate, false, RegexOptions.IgnoreCase); template.AddCustomProperty(new CustomProperty("dname", Fdname)); // template.ReplaceText("date", Fdate, false, RegexOptions.IgnoreCase); template.AddCustomProperty(new CustomProperty("lname1", Flname1)); template.AddCustomProperty(new CustomProperty("lname2", Flname2)); template.AddCustomProperty(new CustomProperty("loca", Floc)); // template.ReplaceText("date", Fdate, false, RegexOptions.IgnoreCase); //template.AddCustomProperty(new CustomProperty("virs", Fvirs)); // template.ReplaceText("virs", "", false, RegexOptions.IgnoreCase); template.AddCustomProperty(new CustomProperty("snum", Fsnum)); // template.ReplaceText("snum", Fsnum, false, RegexOptions.IgnoreCase); template.AddCustomProperty(new CustomProperty("mnum", Fmnum)); // template.ReplaceText("prep", Fprep, false, RegexOptions.IgnoreCase); template.AddCustomProperty(new CustomProperty("Date-Generated", xxx)); template.AddCustomProperty(new CustomProperty("Org", "SR")); template.AddCustomProperty(new CustomProperty("Entity", info1[0])); template.AddCustomProperty(new CustomProperty("doctype", info1[1])); template.AddCustomProperty(new CustomProperty("category", info1[2])); return(template); }
//tạo hóa đơn từ mẫu static private DocX CreateInvoiceFromTemplate(DocX template, string id) { DataTable dt = DataController.ExecTable("select mabctt,thang,nam from baocao where mabctt=" + id); DataRow data = dt.Rows[0]; template.AddCustomProperty(new CustomProperty("adatenow", DateTime.Today.ToString("dd-MM-yyyy"))); template.AddCustomProperty(new CustomProperty("athang", data["thang"].ToString())); template.AddCustomProperty(new CustomProperty("anam", data["nam"].ToString())); template.AddCustomProperty(new CustomProperty("amabctt", data["mabctt"].ToString())); var t = template.Tables[0]; //tạo hóa đơn từ template CreateAndInsertInvoiceTableAfter(t, ref template, id); t.Remove();// xóa giữ liệu table //return template; // lưu vào template var t1 = template.Tables[1]; //tạo hóa đơn từ template CreateAndInsertInvoiceTableAfter1(t1, ref template, id); t1.Remove(); // xóa giữ liệu table //return template; // lưu vào template var t2 = template.Tables[2]; //tạo hóa đơn từ template CreateAndInsertInvoiceTableAfter2(t2, ref template, id); t2.Remove(); // xóa giữ liệu table //return template; // lưu vào template var t3 = template.Tables[3]; //tạo hóa đơn từ template CreateAndInsertInvoiceTableAfter3(t3, ref template, id); t3.Remove(); // xóa giữ liệu table //return template; // lưu vào template var t4 = template.Tables[4]; //tạo hóa đơn từ template CreateAndInsertInvoiceTableAfter4(t4, ref template, id); t4.Remove(); // xóa giữ liệu table //return template; // lưu vào template var t5 = template.Tables[5]; //tạo hóa đơn từ template CreateAndInsertInvoiceTableAfter5(t5, ref template, id); t5.Remove(); // xóa giữ liệu table //return template; // lưu vào template var t6 = template.Tables[6]; //tạo hóa đơn từ template CreateAndInsertInvoiceTableAfter6(t6, ref template, id); t6.Remove(); // xóa giữ liệu table //return template; // lưu vào template return(template); // lưu vào template }
public static DocX CreateDocA(DocX template, JIUViewModel model, string source) { string sym = model.Sym.ToString(); string[] SymStr = sym.Split('/'); string[] sym1 = SymStr.Skip(1).ToArray(); string Fsym = String.Join("/", sym1); int yearppos = 0; //document Language "Section" string Ftlang = ""; Ftlang = Tlanguage(model.lang_ID); //ORiginal Language string Folang = ""; // Folang = Olanguage1(model.Olang_ID); string FPname = "[Prepared By]"; //Typist if (!String.IsNullOrEmpty(model.Pname)) { //string[] arr = model.Pname.Split(new string[] { "\r\n" }, StringSplitOptions.None); //FPname = ""; //for (int x = 0; x < arr.Length-1; x++) //{ // FPname = FPname+ arr[x] +"\n"; //} //int xs = arr.Length; //FPname = FPname + arr[xs-1]; FPname = model.Pname.ToString(); } //Novacode.Formatting prepared = new Novacode.Formatting(); //prepared.Italic = true; //prepared.Bold = true; //prepared.Size=14; // template.ReplaceText("Pname", FPname,false,RegexOptions.None,prepared); //Agenda Title string FJtitle = "[Title]"; if (!String.IsNullOrEmpty(model.JTitle)) { FJtitle = model.JTitle.ToString(); } /// //Year Jdate string structure = model.structure.ToString(); string[] str = structure.Split('/'); string FJdate = "[YEAR]"; for (int i = 0; i < str.Length; i++) { if (str[i] == "&") { yearppos = i; FJdate = SymStr[i]; } } //create barcode string Fbar = ""; if (!String.IsNullOrEmpty(model.Gdoc)) { Fbar = model.Gdoc.ToString(); Fbar = "*" + Fbar + "*"; } string gdoc = ""; string Fgdocf = ""; if (!String.IsNullOrEmpty(model.Gdoc)) { gdoc = model.Gdoc.ToString(); gdoc = gdoc.Insert(2, "-"); Fgdocf = gdoc; } DateTime xxx = DateTime.Now; template.AddCustomProperty(new CustomProperty("sym1", Fsym)); template.AddCustomProperty(new CustomProperty("symh", sym)); //template.AddCustomProperty(new CustomProperty("symh1", sym)); //template.AddCustomProperty(new CustomProperty("symh2", sym)); // template.ReplaceText(sym, sym, false, RegexOptions.IgnoreCase); template.AddCustomProperty(new CustomProperty("jdate", FJdate)); // template.ReplaceText("sdate", Fsdate, false, RegexOptions.IgnoreCase); template.AddCustomProperty(new CustomProperty("olang", Ftlang)); template.AddCustomProperty(new CustomProperty("gdoc", gdoc)); template.AddCustomProperty(new CustomProperty("gdoc1", gdoc)); // template.ReplaceText("gdoc", gdoc, false, RegexOptions.IgnoreCase); template.AddCustomProperty(new CustomProperty("gdocf", Fgdocf)); template.AddCustomProperty(new CustomProperty("test", Fgdocf)); //template.AddCustomProperty(new CustomProperty("gdocf1", Fgdocf)); //template.AddCustomProperty(new CustomProperty("gdocf2", Fgdocf)); // template.ReplaceText("gdocf", Fgdocf, false, RegexOptions.IgnoreCase); template.AddCustomProperty(new CustomProperty("tlang", "")); // template.ReplaceText("tlang", Ftlang, false, RegexOptions.IgnoreCase); template.AddCustomProperty(new CustomProperty("jtitle", FJtitle)); // template.ReplaceText("atitle", Fatitle, false, RegexOptions.IgnoreCase); template.AddCustomProperty(new CustomProperty("Pname", FPname)); // template.ReplaceText("stitle", Fstitle, false, RegexOptions.IgnoreCase); template.AddCustomProperty(new CustomProperty("bar", Fbar)); // template.ReplaceText("bar", Fbar, false, RegexOptions.IgnoreCase); template.AddCustomProperty(new CustomProperty("Date-Generated", xxx)); template.AddCustomProperty(new CustomProperty("Org", "JIU")); template.AddCustomProperty(new CustomProperty("Entity", "JIU")); template.AddCustomProperty(new CustomProperty("doctype", "Main")); template.AddCustomProperty(new CustomProperty("category", "Report")); using (WordprocessingDocument document = WordprocessingDocument.Open(source, true)) { DocumentSettingsPart settingsPart = document.MainDocumentPart.GetPartsOfType <DocumentSettingsPart>().First(); // Create object to update fields on open UpdateFieldsOnOpen updateFields = new UpdateFieldsOnOpen(); updateFields.Val = new DocumentFormat.OpenXml.OnOffValue(true); // Insert object into settings part. settingsPart.Settings.PrependChild <UpdateFieldsOnOpen>(updateFields); settingsPart.Settings.Save(); document.MainDocumentPart.Document.RemoveAllChildren <BookmarkStart>(); document.MainDocumentPart.Document.RemoveAllChildren <BookmarkEnd>(); } return(template); }
public static void patientPrint(patient pat) { string template = @"TransferbladTemplate.docx"; using (DocX doc = DocX.Load(template)) { doc.AddCustomProperty(new CustomProperty("VolgNr", pat.Id)); doc.AddCustomProperty(new CustomProperty("InschrNR", pat.Inschrijvingsnr)); doc.AddCustomProperty(new CustomProperty("NaaM", pat.Naam)); doc.AddCustomProperty(new CustomProperty("VoorNaaM", pat.Voornaam)); doc.AddCustomProperty(new CustomProperty("gebDatum", pat.Geboortedatum.ToString())); doc.AddCustomProperty(new CustomProperty("opnameDat", pat.TijdOpname.ToString())); doc.AddCustomProperty(new CustomProperty("ontslagDat", pat.TijdOntslag.ToString())); doc.AddCustomProperty(new CustomProperty("Artsen", pat.BehandelArts)); doc.AddCustomProperty(new CustomProperty("AnamNese", pat.Anamnese)); doc.AddCustomProperty(new CustomProperty("thuisMed", pat.ThuisMed)); doc.AddCustomProperty(new CustomProperty("RitMe", pat.Ritme)); doc.AddCustomProperty(new CustomProperty("pP", pat.WhatIsP)); doc.AddCustomProperty(new CustomProperty("BDD", pat.Bd)); doc.AddCustomProperty(new CustomProperty("Dieet", pat.Dieet)); doc.AddCustomProperty(new CustomProperty("SV", pat.Sv)); doc.AddCustomProperty(new CustomProperty("Diagno", pat.Diagnose)); doc.AddCustomProperty(new CustomProperty("ZorGen", pat.Zorgen)); doc.AddCustomProperty(new CustomProperty("Verslag", pat.Verslag)); doc.AddCustomProperty(new CustomProperty("teleMetrie", pat.Telemetrie.ToString())); doc.AddCustomProperty(new CustomProperty("ZalVing", pat.Zalving)); doc.AddCustomProperty(new CustomProperty("KinE", pat.Kine)); doc.SaveAs("printPat.docx"); } Process.Start("WINWORD.EXE", "printPat.docx"); }
/// <summary> /// 產生制式化文件 /// </summary> public static void CreateDocX_FormulatedDocument(FileInfo fi) { // 參數。應該自外帶入。此處為測試,寫在裡面。 var info = new { postDate = "2015/12/07", custName = "歐陽重天", custAddr1 = "11265台北市北投區", custAddr2 = "沒這條路三段66號2樓之1", caseNo = "201205-990137", disputeAmt = 7530, flag1 = false, flag2 = true, flag3 = false, flag4 = true, otherDesc = "沒錢可付只好洗碗" }; using (DocX doc = DocX.Create(fi.FullName)) { //Add custom properties to document. doc.AddCustomProperty(new CustomProperty("CompanyName", "亞洲志遠科技")); doc.AddCustomProperty(new CustomProperty("Product", "DocX練習")); doc.AddCustomProperty(new CustomProperty("Address", "新北市中正路755號7樓")); doc.AddCustomProperty(new CustomProperty("Date", DateTime.Now)); // resource Font fontC = new Font("標楷體"); Font fontE = new Font("Tahoma"); Font fontN = new Font("Verdana"); Font fontG = new Font("微軟正黑體"); // banner Image image = doc.AddImage("Image2.png"); Picture pic = image.CreatePicture(); doc.InsertParagraph() .AppendPicture(pic) .Alignment = Alignment.right; // prefix header doc.InsertParagraph() .Append(info.postDate).Font(fontE) .AppendLine() .AppendLine(info.custName).Font(fontC) .AppendLine() .AppendLine(info.custAddr1).Font(fontC) .AppendLine(info.custAddr2).Font(fontC) .AppendLine() .AppendLine(); // title doc.InsertParagraph("爭議款結案通知書") .Font(fontC) .FontSize(20d) .SpacingAfter(10d) .Alignment = Alignment.center; // paragraph 1 Paragraph p1 = doc.InsertParagraph(); p1.Append("案件編號:").Append(info.caseNo).Font(fontN) .AppendLine("爭議金額:").Append(string.Format("NTD${0:N0}元", info.disputeAmt)).Font(fontN) .AppendLine(); // paragraph 2 Paragraph p2 = doc.InsertParagraph(); p2.IndentationFirstLine = 1.0f; // 第一行縮排1公分 p2.Append("台端於日前致電本行要求處理之爭議款項,已因下列原因結案,特發此函通知。") .AppendLine(); // item 1 Paragraph p2a = doc.InsertParagraph(); p2a.IndentationBefore = 1.0f; // 凸排一公分 p2a.IndentationFirstLine = -1.0f; p2a.Append(info.flag1 ? "■" : "□") .Append(" 1.\t商店同意退回上述爭議款款項,因本行於您提出爭議時即以「帳務調整爭議款」之科目先行調整您的信用卡帳務,現爭議款確定無須支付,本行將逕做結案處理。") .SpacingAfter(10d); // item 2 Paragraph p2b = doc.InsertParagraph(); p2b.IndentationBefore = 1.0f; // 凸排一公分 p2b.IndentationFirstLine = -1.0f; p2b.Append(info.flag2 ? "■" : "□") .Append(" 2.\t商店主動退回上述爭議款款項,此筆退款將出現於您近期帳單中,敬請查核。") .AppendLine() .SpacingAfter(10d); // item 3 Paragraph p2c = doc.InsertParagraph(); p2c.IndentationBefore = 1.0f; // 凸排一公分 p2c.IndentationFirstLine = -1.0f; p2c.Append(info.flag3 ? "■" : "□") .Append(" 3.\t商店同意退回上述爭議款款項,本行已於近期帳單中以「帳務調整爭議款」科目退款給您。") .SpacingAfter(10d); // item 4 Paragraph p2d = doc.InsertParagraph(); p2d.IndentationBefore = 1.0f; // 凸排一公分 p2d.IndentationFirstLine = -1.0f; p2d.Append(info.flag4 ? "■" : "□") .Append(" 4.\t其他:") .Append(info.otherDesc + new string(' ', 30 - info.otherDesc.Length) + ".").UnderlineStyle(UnderlineStyle.singleLine) .SpacingAfter(10d); // tail doc.InsertParagraph().AppendLine("謹祝 商祺") .Font(fontG); doc.InsertParagraph().AppendLine("千陽號銀行信用卡爭議帳款小組 敬上") .Font(fontG) .Alignment = Alignment.right; // Save this document. doc.Save(); } }
public static DocX CreateDocA(DocX template, UnogViewModel model) { string sym = model.Sym.ToString(); string[] SymStr = sym.Split('/'); string[] sym1 = SymStr.Skip(1).ToArray(); string Fsym = String.Join("/", sym1); int reppos = 0; int repposcom = 0; int countpos = 0; //Create Date for Header string Fdate = model.date.ToString(); string[] d = Fdate.Split(' '); Fdate = d[0]; Fdate = formatdate(Fdate, model); //Create Distrbution for Header string Fdist = getDist(model); //document Language "Section" string Ftlang = ""; Ftlang = Tlanguage(model.lang_ID); //ORiginal Language string Folang = ""; Folang = Olanguage1(model.Olang_ID); string FAuthor = ""; //Typist if (!String.IsNullOrEmpty(model.Author)) { FAuthor = model.Author.ToString(); } //Agenda Title string Fatitle = ""; if (!String.IsNullOrEmpty(model.AgendaItem)) { Fatitle = model.AgendaItem.ToString(); } //Session Title string Fstitle = ""; if (!String.IsNullOrEmpty(model.STitle)) { Fstitle = model.STitle.ToString(); } //Session Dates string Fsdate = ""; if (model.Sdate != null & model.Edate != null) { string sdate = model.Sdate.ToString(); string[] sd = sdate.Split(' '); sdate = sd[0]; sdate = formatdate(sdate, model); string edate = model.Edate.ToString(); string[] ed = edate.Split(' '); edate = ed[0]; edate = formatdate(edate, model); Fsdate = SessionDate(sdate, edate, model); } //Agenda Number string Fanum = ""; if (!String.IsNullOrEmpty(model.AgendaNum)) { Fanum = model.AgendaNum.ToString(); } //Session Numer string Fsnum = ""; if (!String.IsNullOrEmpty(model.SNum)) { Fsnum = Sessionnum(model); } /// //Report num and count string structure = model.structure.ToString(); string[] str = structure.Split('/'); for (int i = 0; i < str.Length; i++) { if (str[i] == "#") { reppos = i; } if (str[i] == "ISO") { countpos = i; } if (str[i] == "R.#") { repposcom = i; } } string Fprep = ""; if (reppos != 0 && countpos != 0) { Fprep = Reportnumber(model, SymStr[reppos], model.lang_ID, SymStr[countpos]); } if (repposcom != 0 && countpos != 0) { string x = SymStr[repposcom]; int start = x.IndexOf('.'); string prep = x.Substring(start, x.Count() - 1); Fprep = Reportnumber(model, prep, model.lang_ID, SymStr[countpos]); } string fCount = ""; if (countpos != 0) { fCount = getCount(SymStr[countpos], model); } //QR code and Bar code string lang = getlanguageQR(model.lang_ID); string url = "http://undocs.org/m2/QRCode.ashx?DS=" + Fsym + "&Size=2&Lang=" + lang; using (var client = new WebClient()) { //var content = client.DownloadData("https://api.qrserver.com/v1/create-qr-code/?size=66x66&data=http://undocs.org/fr/A/HRC/70"); //var content = client.DownloadData("http://undocs.org/m2/QRCode.ashx?DS=A/HRC/70&Size=2&Lang=F"); var content = client.DownloadData(url); using (var str1 = new MemoryStream(content)) { Image image = template.AddImage(str1); Picture p = image.CreatePicture(); Footer f = template.Footers.first; Table t = f.Tables[0]; //t.Rows[0].Cells[1].Paragraphs.First().AppendPicture(pR); t.Rows[0].Cells[1].Paragraphs.First().AppendPicture(p); } } //create barcode string Fbar = ""; Fbar = model.Gdoc.ToString(); Fbar = "*" + Fbar + "*"; //creat gdoc string gdoc = model.Gdoc.ToString(); gdoc = gdoc.Insert(2, "-"); //creat gdoc footer string Fgdocf = gdoc; DateTime xxx = DateTime.Now; template.AddCustomProperty(new CustomProperty("sym1", Fsym)); template.AddCustomProperty(new CustomProperty("symh", sym)); template.AddCustomProperty(new CustomProperty("dist", Fdist)); template.AddCustomProperty(new CustomProperty("date", Fdate)); template.AddCustomProperty(new CustomProperty("sdate", Fsdate)); template.AddCustomProperty(new CustomProperty("virs", "")); template.AddCustomProperty(new CustomProperty("snum", Fsnum)); template.AddCustomProperty(new CustomProperty("anum", Fanum)); template.AddCustomProperty(new CustomProperty("count", fCount)); template.AddCustomProperty(new CustomProperty("gdoc", gdoc)); template.AddCustomProperty(new CustomProperty("gdocf", Fgdocf)); template.AddCustomProperty(new CustomProperty("tlang", Ftlang)); template.AddCustomProperty(new CustomProperty("atitle", Fatitle)); template.AddCustomProperty(new CustomProperty("stitle", Fstitle)); template.AddCustomProperty(new CustomProperty("prep", Fprep)); template.AddCustomProperty(new CustomProperty("olang", Folang)); template.AddCustomProperty(new CustomProperty("Author", FAuthor)); template.AddCustomProperty(new CustomProperty("bar", Fbar)); template.AddCustomProperty(new CustomProperty("Date-Generated", xxx)); // template.AddCoreProperty("dc:title", sym); return(template); }
private static DocX CreateInvoiceFromTemplate(DocX templateDoc) { // Fill in the document custom properties. templateDoc.AddCustomProperty(new CustomProperty("InvoiceNumber", 1355)); templateDoc.AddCustomProperty(new CustomProperty("InvoiceDate", new DateTime(2016, 10, 15).ToShortDateString())); templateDoc.AddCustomProperty(new CustomProperty("CompanyName", "Toms Telecoms")); templateDoc.AddCustomProperty(new CustomProperty("CompanySlogan", "Always with you")); templateDoc.AddCustomProperty(new CustomProperty("ClientName", "James Doh")); templateDoc.AddCustomProperty(new CustomProperty("ClientStreetName", "123 Main street")); templateDoc.AddCustomProperty(new CustomProperty("ClientCity", "Springfield, Ohio")); templateDoc.AddCustomProperty(new CustomProperty("ClientZipCode", "54789")); templateDoc.AddCustomProperty(new CustomProperty("ClientPhone", "438-585-9636")); templateDoc.AddCustomProperty(new CustomProperty("ClientMail", "*****@*****.**")); templateDoc.AddCustomProperty(new CustomProperty("CompanyStreetName", "1458 Thompson Road")); templateDoc.AddCustomProperty(new CustomProperty("CompanyCity", "Los Angeles, California")); templateDoc.AddCustomProperty(new CustomProperty("CompanyZipCode", "90210")); templateDoc.AddCustomProperty(new CustomProperty("CompanyPhone", "1-965-434-5786")); templateDoc.AddCustomProperty(new CustomProperty("CompanySupport", "*****@*****.**")); // Remove the default logo and add the new one. var paragraphWithDefaultLogo = MiscellaneousSample.GetParagraphContainingPicture(templateDoc); if (paragraphWithDefaultLogo != null) { paragraphWithDefaultLogo.Pictures.First().Remove(); var newLogo = templateDoc.AddImage(MiscellaneousSample.MiscellaneousSampleResourcesDirectory + @"Phone.png"); paragraphWithDefaultLogo.AppendPicture(newLogo.CreatePicture(60, 180)); } // Fill the details table. MiscellaneousSample.FillDetailsTable(ref templateDoc); return(templateDoc); }
public ActionResult Download(int id) { InitiatedProjectViewModel proposal = _proposalctx.GetProposalById(id); string templateName = "External_Project_Proposal.docx"; string path = Path.Combine(environment.ContentRootPath, "~/App_Data/Generated", templateName); string downloadPath = string.Format(@"{0}{1}.docx", path, "-" + proposal.Title); DateTime currentDt = DateTime.Now; DateTime Sem1Start = new DateTime(currentDt.Year, 4, 20); DateTime Sem2Start = new DateTime(currentDt.Year, 10, 19); string semester = ""; if (DateHelper.Between(currentDt, Sem1Start, Sem2Start)) { semester = "1"; } else { semester = "2"; } DocX document = new DocxFormatter().GetInitiatedProjectProposal(currentDt, semester); document.SaveAs(path); using (DocX doc = DocX.Load(path)) { doc.AddCustomProperty(new Xceed.Words.NET.CustomProperty("ProjectTitle", proposal.Title)); doc.AddCustomProperty(new Xceed.Words.NET.CustomProperty("ProjectOverview", proposal.ProjectOverview)); doc.AddCustomProperty(new Xceed.Words.NET.CustomProperty("IntroBackground", proposal.IntroBackground)); doc.AddCustomProperty(new Xceed.Words.NET.CustomProperty("Approach", proposal.KeyInnovationAndResearchGoals)); doc.AddCustomProperty(new Xceed.Words.NET.CustomProperty("ComparisonMerits", proposal.ComparisonOfTheMerits)); doc.AddCustomProperty(new Xceed.Words.NET.CustomProperty("TargetAudience", proposal.TargetAudience)); doc.AddCustomProperty(new Xceed.Words.NET.CustomProperty("BusinessModel", proposal.BusinessModelAndMarketPotential)); doc.AddCustomProperty(new Xceed.Words.NET.CustomProperty("MainFunction", proposal.MainFunction)); doc.AddCustomProperty(new Xceed.Words.NET.CustomProperty("ProjectPlan", proposal.ProjectPlan)); doc.AddCustomProperty(new Xceed.Words.NET.CustomProperty("HardwareAndSoftwareRequirements", proposal.HardwareAndSoftwareRequirements)); doc.AddCustomProperty(new Xceed.Words.NET.CustomProperty("ProblemsAndCountermeasures", proposal.ProblemsAndCountermeasures)); doc.SaveAs(downloadPath); } return(File(downloadPath, System.Net.Mime.MediaTypeNames.Application.Octet, Path.GetFileName(downloadPath))); }
public ActionResult Generate(int Id) { dynamic proposal = _proposalctx.GetProposalById(Id); string templateName = "External_Project_Proposal.docx"; string path = Path.Combine(environment.ContentRootPath, "/App_Data/Generated", templateName); string downloadPath = string.Format(@"{0}{1}.docx", path, "-" + proposal.Title); if (proposal.ProjectType == "External") { DocX document = new DocxFormatter().GetExternalProjectProposalTemplate(); document.SaveAs(path); } if (proposal.ProjectType == "Student") { DateTime currentDt = DateTime.Now; DateTime Sem1Start = new DateTime(currentDt.Year, 4, 20); DateTime Sem2Start = new DateTime(currentDt.Year, 10, 19); string semester = ""; if (DateHelper.Between(currentDt, Sem1Start, Sem2Start)) { semester = "1"; } else { semester = "2"; } DocX document = new DocxFormatter().GetInitiatedProjectProposal(currentDt, semester); document.SaveAs(path); } using (DocX doc = DocX.Load(path)) { //if (doc == null) //{ //DocX document = new DocxFormatter().GetExternalProjectProposalTemplate(); //document.SaveAs(path); //} doc.AddCustomProperty(new CustomProperty("ProjectTitle", proposal.Title)); if (proposal.ProjectType == "External") { doc.AddCustomProperty(new CustomProperty("CompanyName", proposal.CompanyName)); doc.AddCustomProperty(new CustomProperty("Address", proposal.Address)); doc.AddCustomProperty(new CustomProperty("Tel", proposal.Tel)); doc.AddCustomProperty(new CustomProperty("Fax", proposal.Fax)); doc.AddCustomProperty(new CustomProperty("Email", proposal.Email)); doc.AddCustomProperty(new CustomProperty("LiaisonOfficer", proposal.LiaisonOfficer)); string WillingToSponsor = "No"; if (proposal.WillingToSponsor == true) { WillingToSponsor = "Yes"; } doc.AddCustomProperty(new CustomProperty("WillingToSponsor", WillingToSponsor)); doc.AddCustomProperty(new CustomProperty("ProjectAims", proposal.Aims)); doc.AddCustomProperty(new CustomProperty("ProjectObjectives", proposal.Objectives)); doc.AddCustomProperty(new CustomProperty("ProjectSchedule", proposal.Schedule)); doc.AddCustomProperty(new CustomProperty("ProjectAudience", proposal.TargetAudience)); doc.AddCustomProperty(new CustomProperty("ProjectMainFunction", proposal.MainFunction)); doc.AddCustomProperty(new CustomProperty("ProjectRequirements", proposal.HardwareAndSoftwareConfiguration)); } if (proposal.ProjectType == "Student") { doc.AddCustomProperty(new CustomProperty("ProjectOverview", proposal.ProjectOverview)); doc.AddCustomProperty(new CustomProperty("IntroBackground", proposal.IntroBackground)); doc.AddCustomProperty(new CustomProperty("Approach", proposal.KeyInnovationAndResearchGoals)); doc.AddCustomProperty(new CustomProperty("ComparisonMerits", proposal.ComparisonOfTheMerits)); doc.AddCustomProperty(new CustomProperty("TargetAudience", proposal.TargetAudience)); doc.AddCustomProperty(new CustomProperty("BusinessModel", proposal.BusinessModelAndMarketPotential)); doc.AddCustomProperty(new CustomProperty("MainFunction", proposal.MainFunction)); doc.AddCustomProperty(new CustomProperty("ProjectPlan", proposal.ProjectPlan)); doc.AddCustomProperty(new CustomProperty("HardwareAndSoftwareRequirements", proposal.HardwareAndSoftwareRequirements)); doc.AddCustomProperty(new CustomProperty("ProblemsAndCountermeasures", proposal.ProblemsAndCountermeasures)); } doc.SaveAs(downloadPath); } return(File(downloadPath, System.Net.Mime.MediaTypeNames.Application.Octet, Path.GetFileName(downloadPath))); }
public static DocX CreateDocA(DocX template, ECEViewModel model, string source, bool cprvalue) { bool addcor = false; string Fadcorr = ""; bool special = false; string Fsnum = "[NUMBER]"; string sym = getSym(model); if (!String.IsNullOrEmpty(model.Prep)) { sym = sym.Replace("#", model.Prep.ToString()); } if (cprvalue == true) { sym = sym + "/CRP." + model.cprnum.ToString(); } if (!String.IsNullOrEmpty(model.Add) && model.cAdd == true && model.cCor == false) { sym = sym + "/Add." + model.Add.ToString(); Fadcorr = "Addendum"; addcor = true; } if (!String.IsNullOrEmpty(model.Cor) && model.cCor == true && model.cAdd == false) { sym = sym + "/Corr." + model.Cor.ToString(); Fadcorr = "Corrigendum"; addcor = true; } if (!String.IsNullOrEmpty(model.Cor) && !String.IsNullOrEmpty(model.Add) && model.cCor == true && model.cAdd == true) { sym = sym + "/Add." + model.Add.ToString() + "/Corr." + model.Cor.ToString(); Fadcorr = "Addendum Corrigendum"; addcor = true; } if (String.IsNullOrEmpty(model.Cor) && String.IsNullOrEmpty(model.Add)) { addcor = false; } if (String.IsNullOrEmpty(model.CaseYear)) { sym = sym.Replace("&", DateTime.Now.Year.ToString()); } if (!String.IsNullOrEmpty(model.CaseYear)) { sym = sym.Replace("&", model.CaseYear.ToString()); } model.tsym = sym; string[] SymStr = sym.Split('/'); string[] sym1 = SymStr.Skip(1).ToArray(); string Fsym = String.Join("/", sym1); if (Fsym.Contains("/S/")) { special = true; Fsnum = "special"; } //Create Date for Header string Fdate = model.date.ToString(); string[] d = Fdate.Split(' '); Fdate = d[0]; Fdate = formatdate(Fdate, model); //Create Distribution for Header string Fdist = getDist(model); //Create Virsions for Header string Fvirs = ""; //if (model.version1 != null) //{ // int deleteStart = 0; // int deleteEnd = 0; // //Get the array of the paragraphs containing the start and end catches // for (int i = 0; i < template.Paragraphs.Count; i++) // { // if (template.Paragraphs[i].Text.Contains("Original")) // deleteStart = i; // if (template.Paragraphs[i].Text.Contains("olang")) // deleteEnd = i; // } // if (deleteStart > 0 && deleteEnd > 0) // { // //delete from the paraIndex as the arrays will shift when a paragraph is deleted // int paraIndex = deleteStart; // for (int i = deleteStart; i <= deleteEnd; i++) // { // template.RemoveParagraphAt(paraIndex); // } // } //} //Fvirs = getVerisons(model); string Folang = ""; Folang = Olanguage(model.lang_ID); string Fatitle = "[Title]"; if (!String.IsNullOrEmpty(model.AgendaItem)) { Fatitle = model.AgendaItem.ToString(); } string Fsdate = "[Start-End Dates ]"; if (model.Sdate != null & model.Edate != null) { string sdate = model.Sdate.ToString(); string[] sd = sdate.Split(' '); sdate = sd[0]; sdate = formatdate(sdate, model); string edate = model.Edate.ToString(); string[] ed = edate.Split(' '); edate = ed[0]; edate = formatdate(edate, model); Fsdate = SessionDate(sdate, edate, model); } string Fldate = "[Start Date]"; if (model.Sdate != null & model.Edate != null) { string ldate = model.Sdate.ToString(); string[] ld = ldate.Split(' '); ldate = ld[0]; string dldate = System.Threading.Thread.CurrentThread.CurrentUICulture.DateTimeFormat.GetDayName(DateTime.Parse(ldate).DayOfWeek); ldate = formatdate(ldate, model); //Regex rx = new Regex(@"^\d+\p{Zs}", RegexOptions.Compiled); //ldate = rx.Replace(ldate, dldate+" "); ldate = dldate + " " + ldate; Fldate = ldate; } string Fanum = "[NUMBER]"; if (!String.IsNullOrEmpty(model.AgendaNum)) { Fanum = model.AgendaNum.ToString(); } if (special == false) { if (!String.IsNullOrEmpty(model.SNum)) { Fsnum = Sessionnum(model); } } if (model.qrcode == true) { string lang = language(model.lang_ID); lang = lang.Substring(0, 1); string url = "http://undocs.org/m2/QRCode.ashx?DS=" + Fsym + "&Size=2&Lang=" + lang; using (var client = new WebClient()) { //var content = client.DownloadData("https://api.qrserver.com/v1/create-qr-code/?size=66x66&data=http://undocs.org/fr/A/HRC/70"); //var content = client.DownloadData("http://undocs.org/m2/QRCode.ashx?DS=A/HRC/70&Size=2&Lang=F"); var content = client.DownloadData(url); using (var str = new MemoryStream(content)) { if (lang == "A") { Image image = template.AddImage(str); NVPicture p = image.CreatePicture(); NVFooter f = template.Footers.first; NVTable t = f.Tables[0]; //t.Rows[0].Cells[1].Paragraphs.First().AppendPicture(pR); t.Rows[0].Cells[0].Paragraphs.First().AppendPicture(p); } else { NVImage image = template.AddImage(str); NVPicture p = image.CreatePicture(); NVFooter f = template.Footers.first; NVTable t = f.Tables[0]; //t.Rows[0].Cells[1].Paragraphs.First().AppendPicture(pR); t.Rows[0].Cells[1].Paragraphs.First().AppendPicture(p); } } } } string Fcategory = ""; Fcategory = getCat(model.Cat); string FSubcategory = ""; if (model.SCat != "Not Applicable" || model.SCat != "Special Session") { FSubcategory = model.SCat.ToString(); } if (model.SCat == "Not Applicable" || model.SCat == "Special Session") { int deleteStart = 0; int deleteEnd = 0; //Get the array of the paragraphs containing the start and end catches for (int i = 0; i < template.Paragraphs.Count; i++) { if (template.Paragraphs[i].Text.Contains("subcategory")) { deleteStart = i; } if (template.Paragraphs[i].Text.Contains("subcategory")) { deleteEnd = i; } } if (deleteStart > 0 && deleteEnd > 0) { //delete from the paraIndex as the arrays will shift when a paragraph is deleted int paraIndex = deleteStart; for (int i = deleteStart; i <= deleteEnd; i++) { template.RemoveParagraphAt(paraIndex); } } } if (addcor == false) { int deleteStart = 0; int deleteEnd = 0; //Get the array of the paragraphs containing the start and end catches for (int i = 0; i < template.Paragraphs.Count; i++) { if (template.Paragraphs[i].Text.Contains("adcorr")) { deleteStart = i; } if (template.Paragraphs[i].Text.Contains("adcorr")) { deleteEnd = i; } } if (deleteStart > 0 && deleteEnd > 0) { //delete from the paraIndex as the arrays will shift when a paragraph is deleted int paraIndex = deleteStart; for (int i = deleteStart; i <= deleteEnd; i++) { template.RemoveParagraphAt(paraIndex); } } } string Fsplace = "[Session City]"; if (!String.IsNullOrEmpty(model.splace)) { Fsplace = model.splace.ToString(); } string Floca = "[Session Location]"; if (!String.IsNullOrEmpty(model.loca)) { Floca = model.loca.ToString() + ", " + Fsplace; } DateTime x = DateTime.Now; string[] info1 = info(model); template.AddCustomProperty(new CustomProperty("sym1", Fsym)); template.AddCustomProperty(new CustomProperty("symh", sym)); template.AddCustomProperty(new CustomProperty("dist", Fdist)); template.AddCustomProperty(new CustomProperty("date", Fdate)); template.AddCustomProperty(new CustomProperty("sdate", Fsdate)); template.AddCustomProperty(new CustomProperty("virs", Fvirs)); template.AddCustomProperty(new CustomProperty("snum", Fsnum)); template.AddCustomProperty(new CustomProperty("anum", Fanum)); template.AddCustomProperty(new CustomProperty("adcorr", Fadcorr)); template.AddCustomProperty(new CustomProperty("gdoc", "")); template.AddCustomProperty(new CustomProperty("gdocf", "")); template.AddCustomProperty(new CustomProperty("tlang", "")); template.AddCustomProperty(new CustomProperty("atitle", Fatitle)); template.AddCustomProperty(new CustomProperty("ldate", Fldate)); template.AddCustomProperty(new CustomProperty("loca", Floca)); template.AddCustomProperty(new CustomProperty("categ", Fcategory)); template.AddCustomProperty(new CustomProperty("subcategory", FSubcategory)); template.AddCustomProperty(new CustomProperty("splace", Fsplace)); template.AddCustomProperty(new CustomProperty("olang", Folang)); template.AddCustomProperty(new CustomProperty("Date-Generated", x)); template.AddCustomProperty(new CustomProperty("Org", "ECE")); template.AddCustomProperty(new CustomProperty("Entity", info1[0])); template.AddCustomProperty(new CustomProperty("doctype", info1[1])); template.AddCustomProperty(new CustomProperty("category", info1[2])); template.AddCustomProperty(new CustomProperty("bar", "")); for (int i = 0; i < template.Paragraphs.Count; i++) { if (template.Paragraphs[i].Text.Contains(Fsnum)) { string Fsnum1 = char.ToUpper(Fsnum[0]) + Fsnum.Substring(1); template.Paragraphs[i].ReplaceText(Fsnum, Fsnum1); break; } } if (addcor == true && cprvalue == false) { int deleteStart = 0; int deleteEnd = 0; //Get the array of the paragraphs containing the start and end catches for (int i = 0; i < template.Paragraphs.Count; i++) { if (template.Paragraphs[i].Text.Contains("*")) { deleteStart = i; } if (template.Paragraphs[i].Text.Contains(Fadcorr)) { deleteEnd = i; } } if (deleteStart > 0 && deleteEnd > 0) { //delete from the paraIndex as the arrays will shift when a paragraph is deleted int paraIndex = deleteEnd - deleteStart; paraIndex = deleteStart + paraIndex - 1; template.RemoveParagraphAt(paraIndex); } //List <string> replace = template.FindUniqueByPattern("*", RegexOptions.None); //foreach (string s in replace) //{ // if (!s.Equals("")) template.ReplaceText((s, ""); //} template.ReplaceText("*", ""); List <string> repl = template.FindUniqueByPattern(",\\s", RegexOptions.None); foreach (string rep in repl) { if (!String.IsNullOrEmpty(rep)) { template.ReplaceText(rep, ""); } } //bool flag = false; //List<List<string>> list1 = new List<List<string>>(); //List<string> list2 = new List<string>(); //foreach (Novacode.Paragraph item in template.Paragraphs) //{ // //use this if you need whole text of a paragraph // string paraText = item.Text; // var result = paraText.Split(' '); // int count = 0; // list2 = new List<string>(); // //use this if you need word by word // foreach (var data in result) // { // string word = data.ToString(); // if (word.Contains(Fsnum)) flag = true; // if (word.Contains("session")) // { // flag = false; // // list2.Add(word); // } // if (flag) // list2.Add(word); // count++; // } // // list2.RemoveAt(0); // list1.Add(list2); //} //// list1[0].Replace(list1[0], "*"); //for (int i = 0; i < list1.Count(); i++) //{ // string temp = ""; // for (int y = 0; y < list1[i].Count(); y++) // { // if (y == 0) // { // temp = list1[i][y]; // continue; // } // temp += " " + list1[i][y]; // // temp = temp.Remove(temp.IndexOf(',')-1, temp.Length); // } // int ind = temp.IndexOf("*"); // // temp = temp.Substring(ind, temp.Length - ind); // if (!temp.Equals("")) template.ReplaceText("Done", ""); //} } //using (WordprocessingDocument // document = WordprocessingDocument.Open(source, true)) //{ // var bookMarks = FindBookmarks(document.MainDocumentPart.Document); //} // Return the template now that it has been modified to hold all of our custom data. return(template); }