public void Generate(List <string> listWait4Replace) { if (listWait4Replace.Count > PlaceHolderNum) { MessageBoxEx.Show("数据量多余所选模板占位符数量:" + PlaceHolderNum); return; } var doc = DocComHandler.OpenDocFile(GlobalUtils.AppPath + @"\Word\Templates\" + TemplaceDocFileName); if (doc == null) { MessageBoxEx.Show("打开模板文件失败,请检查文件路径!"); return; } string dstName = GlobalUtils.OpenSaveFileDlg(DefaultName, "Word2003 Doc|*.doc"); // If the file name is not an empty string open it for saving. if (!string.IsNullOrEmpty(dstName)) { if (!DocComHandler.BatchReplaceStringByPlaceHolder(dstName, doc, listWait4Replace, true, PlaceHolderNum)) { MessageBoxEx.Show("生成报表失败,请联系技术人员!"); return; } Process.Start(dstName); } }
public void GenerateBatch(List <List <string> > listListWait4Replace, string outFolder) { int success = 0; for (int i = 0; i < listListWait4Replace.Count; i++) { List <string> listWait4Replace = listListWait4Replace[i]; if (listWait4Replace.Count > PlaceHolderNum) { MessageBoxEx.Show("数据量多余所选模板占位符数量:" + PlaceHolderNum + "\n,将跳过当前文档."); continue; } var doc = DocComHandler.OpenDocFile(GlobalUtils.AppPath + @"\Word\Templates\" + TemplaceDocFileName); if (doc == null) { MessageBoxEx.Show("打开模板文件失败,请检查文件路径!"); continue; } if (!DocComHandler.BatchReplaceStringByPlaceHolder(outFolder + @"\" + DefaultName + "_" + listWait4Replace[0] + ".doc", doc, listWait4Replace, true, PlaceHolderNum)) { MessageBoxEx.Show("生成报表失败,请联系技术人员!"); continue; } ++success; } if ( MessageBoxEx.Show("成功保存报表:" + success + "份,失败:" + (listListWait4Replace.Count - success) + "份.\n是否打开所在文件夹?", "提示", MessageBoxButtons.YesNo) == DialogResult.No) { return; } Process.Start(outFolder); }