//string docxSource = filename with path private void GenerateReportFromDocxToDocX(string docxSource, string docxTarget, Placeholders rep) { var docx = new DocXHandler(docxSource, rep); var ms = docx.ReplaceAll(); StreamHandler.WriteMemoryStreamToDisk(ms, docxTarget); }
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; } if (!DocXHandler.BatchReplaceStringByPlaceHolder(GlobalUtils.AppPath + @"\Word\Templates\" + TemplaceDocFileName, outFolder + @"\" + DefaultName + "_" + listWait4Replace[0] + ".docx", listWait4Replace, true, PlaceHolderNum)) { MessageBoxEx.Show("生成报表失败,请联系技术人员!"); continue; } ++success; } if ( MessageBoxEx.Show("成功保存报表:" + success + "份,失败:" + (listListWait4Replace.Count - success) + "份.\n是否打开所在文件夹?", "提示", MessageBoxButtons.YesNo) == DialogResult.No) { return; } Process.Start(outFolder); }
private void PrintDocx(string templateFile, string printername, Placeholders rep) { var docx = new DocXHandler(templateFile, rep); var ms = docx.ReplaceAll(); var tempFileToPrint = Path.ChangeExtension(Path.GetTempFileName(), ".docx"); StreamHandler.WriteMemoryStreamToDisk(ms, tempFileToPrint); LibreOfficeWrapper.Print(tempFileToPrint, printername, _locationOfLibreOfficeSoffice); File.Delete(tempFileToPrint); }
private void GenerateReportFromDocxToHtml(string docxSource, string htmlTarget, Placeholders rep) { var docx = new DocXHandler(docxSource, rep); var ms = docx.ReplaceAll(); var tmpFile = Path.Combine(Path.GetDirectoryName(htmlTarget), Path.GetFileNameWithoutExtension(docxSource) + Guid.NewGuid().ToString().Substring(0, 10) + ".docx"); StreamHandler.WriteMemoryStreamToDisk(ms, tmpFile); LibreOfficeWrapper.Convert(tmpFile, htmlTarget, _locationOfLibreOfficeSoffice); File.Delete(tmpFile); }
public void Generate(List <string> listWait4Replace) { if (listWait4Replace.Count > PlaceHolderNum) { MessageBoxEx.Show("数据量多余所选模板占位符数量:" + PlaceHolderNum); return; } string dstName = GlobalUtils.OpenSaveFileDlg(DefaultName, "Word文档|*.docx"); // If the file name is not an empty string open it for saving. if (!string.IsNullOrEmpty(dstName)) { if (!DocXHandler.BatchReplaceStringByPlaceHolder(GlobalUtils.AppPath + @"\Word\Templates\" + TemplaceDocFileName, dstName, listWait4Replace, true, PlaceHolderNum)) { MessageBoxEx.Show("生成报表失败,请联系技术人员!"); return; } Process.Start(dstName); } }