public void ReplaceByModelList() { string TemplateFilePath = "C:\\Users\\歐家豪\\source\\repos\\WordProcessor\\Template\\StudentList7.docx"; string OutputFilePath = "C:\\Users\\歐家豪\\source\\repos\\WordProcessor\\Template\\ReplaceByModelList.docx"; // ModelList List <Student> Datas = new List <Student>(); Datas.Add(new Student()); Datas.Add(new Student()); Datas[0].sbd_1_0_0 = "1232"; Datas[1].sbd_1_0_0 = "1232"; var Replacer = new ReplaceWordTemplate(); FileStream fs = new FileStream(OutputFilePath, FileMode.Create); BinaryWriter bw = new BinaryWriter(fs); bw.Write(Replacer.Replace(TemplateFilePath, Datas)); bw.Close(); fs.Close(); }
public void ReplaceCase1() { string TemplateFilePath = "C:\\Users\\歐家豪\\source\\repos\\WordProcessor\\Template\\StudentList.docx"; string OutputFilePath = "C:\\Users\\歐家豪\\source\\repos\\WordProcessor\\Template\\StudentList2.docx"; Dictionary <string, string> keyValuePairs = new Dictionary <string, string>(); string TestStr = @"1. 符合報名條件及門檻者,依選校登記序號現場分發。 2. 本校升學績效優質,超高國立大學錄取率:109年第17屆畢業班,國立大學錄取率高達96%。 3. 課程以分組教學,並包含多種適性多元課程。擁有全新數位藝術與設計教室,設計與電繪課程、版畫課程、插畫創意風格課程與素描、水彩、水墨書畫等專業課程;設備、師資與課程規劃最健全,教學與輔導最用心! 4. 備有縝密的專車路線與4人一寢冷氣宿舍,優質環境歡迎蒞校參觀或來電詢問(037-868680分機204)。 "; keyValuePairs.Add("#sbd_1_0_0#", TestStr); keyValuePairs.Add("#sbd_1_0_1#", "H12313213221G"); var Replacer = new ReplaceWordTemplate(); FileStream fs = new FileStream(OutputFilePath, FileMode.Create); BinaryWriter bw = new BinaryWriter(fs); bw.Write(Replacer.Replace(TemplateFilePath, keyValuePairs)); bw.Close(); fs.Close(); }
public void ReplaceCase2() { string TemplateFilePath = "C:\\Users\\歐家豪\\source\\repos\\WordProcessor\\Template\\ApplyFromArt.docx"; string OutputFilePath2 = "C:\\Users\\歐家豪\\source\\repos\\WordProcessor\\Template\\testCase2.docx"; Dictionary <string, string> keyValuePairs = new Dictionary <string, string>(); keyValuePairs.Add("#測試#", "替換"); var Replacer = new ReplaceWordTemplate(); Dictionary <string, string> keyValuePairs2 = new Dictionary <string, string>(); keyValuePairs2.Add("#圖片#", "123"); FileStream fs = new FileStream(OutputFilePath2, FileMode.Create); BinaryWriter bw = new BinaryWriter(fs); bw.Write(Replacer.Replace(Replacer.Replace(TemplateFilePath, keyValuePairs), keyValuePairs2)); bw.Close(); fs.Close(); }
public void ReplaceToFile() { string TemplateFilePath = "C:\\Users\\lonye\\Desktop\\SideProject\\WordProcessor\\DocxProcessorTests\\WordTemplate\\test.docx"; string OutputFilePath = "C:\\Users\\lonye\\Desktop\\SideProject\\WordProcessor\\DocxProcessorTests\\WordTemplate\\testCase2.docx"; Dictionary <string, string> keyValuePairs = new Dictionary <string, string>(); string TestStr = @"1. 符合報名條件及門檻者,依選校登記序號現場分發。 2. 本校升學績效優質,超高國立大學錄取率:109年第17屆畢業班,國立大學錄取率高達96%。 3. 課程以分組教學,並包含多種適性多元課程。擁有全新數位藝術與設計教室,設計與電繪課程、版畫課程、插畫創意風格課程與素描、水彩、水墨書畫等專業課程;設備、師資與課程規劃最健全,教學與輔導最用心! 4. 備有縝密的專車路線與4人一寢冷氣宿舍,優質環境歡迎蒞校參觀或來電詢問(037-868680分機204)。 "; keyValuePairs.Add("#1#", TestStr); var Replacer = new ReplaceWordTemplate(); Replacer.Replace(TemplateFilePath, OutputFilePath, keyValuePairs); }
public void ReplaceByModel() { string TemplateFilePath = "C:\\Users\\歐家豪\\source\\repos\\WordProcessor\\Template\\StudentList7.docx"; string OutputFilePath = "C:\\Users\\歐家豪\\source\\repos\\WordProcessor\\Template\\StudentList2.docx"; TestModel test = new TestModel(); test.sbd_1_0_1 = "0905337291"; var Replacer = new ReplaceWordTemplate(); FileStream fs = new FileStream(OutputFilePath, FileMode.Create); BinaryWriter bw = new BinaryWriter(fs); bw.Write(Replacer.Replace(TemplateFilePath, test)); bw.Close(); fs.Close(); }
public void ReplaceByModel() { string TemplateFilePath = "C:\\Users\\lonye\\Desktop\\SideProject\\WordProcessor\\DocxProcessorTests\\WordTemplate\\test.docx"; string OutputFilePath = "C:\\Users\\lonye\\Desktop\\SideProject\\WordProcessor\\DocxProcessorTests\\WordTemplate\\testByModel.docx"; TestModel test = new TestModel(); test.NO = 200; test.Name = "Test"; test.手機 = "0905337291"; test.Date = new DateTime(2020, 01, 28); var Replacer = new ReplaceWordTemplate(); FileStream fs = new FileStream(OutputFilePath, FileMode.Create); BinaryWriter bw = new BinaryWriter(fs); bw.Write(Replacer.Replace(TemplateFilePath, test)); bw.Close(); fs.Close(); }
public void MergeTwoDocx() { string TemplateFilePath = "C:\\Users\\歐家豪\\source\\repos\\WordProcessor\\Template\\StudentList.docx"; string TemplateFilePath2 = "C:\\Users\\歐家豪\\source\\repos\\WordProcessor\\Template\\StudentList2.docx"; string TemplateFilePath3 = "C:\\Users\\歐家豪\\source\\repos\\WordProcessor\\Template\\ReplaceByModelList.docx"; string TemplateFilePath4 = "C:\\Users\\歐家豪\\source\\repos\\WordProcessor\\Template\\StudentList4.docx"; string OutputFilePath = "C:\\Users\\歐家豪\\source\\repos\\WordProcessor\\Template\\MergeOutput.docx"; //FileStream docx1 = new FileStream(TemplateFilePath, FileMode.Open); FileStream docx2 = new FileStream(TemplateFilePath2, FileMode.Open); FileStream docx3 = new FileStream(TemplateFilePath3, FileMode.Open); FileStream docx4 = new FileStream(TemplateFilePath4, FileMode.Open); var Replacer = new ReplaceWordTemplate(); var Merger = new MergeWordTemplate(); List <Stream> Result = new List <Stream>(); Dictionary <string, string> keyValuePairs = new Dictionary <string, string>(); keyValuePairs.Add("#1#", "123"); Result.Add(new MemoryStream(Replacer.Replace(TemplateFilePath, keyValuePairs))); Result.Add(docx2); Result.Add(docx3); Result.Add(docx4); FileStream fs = new FileStream(OutputFilePath, FileMode.Create); BinaryWriter bw = new BinaryWriter(fs); bw.Write(Merger.MergeDocxsIntoOne(Result)); bw.Close(); fs.Close(); }