public void CreateWord(string fullFileName) { WordHelper wordHelper = new WordHelper(); wordHelper.killWinWordProcess(); if (System.IO.File.Exists(fullFileName)) { System.IO.File.Delete(fullFileName); } wordHelper.CreateNewDocument(); wordHelper.SetFont(20f, Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter); wordHelper.InsertText("公交表结构文档"); wordHelper.SaveDocument(fullFileName); }
//生成Word private static string createTempWord(string templateFilePath, Dictionary <string, string> dic, System.Data.DataTable dt) { WordHelper wordBuilder = new WordHelper(); wordBuilder.CreateNewDocument(templateFilePath); foreach (var item in dic) { wordBuilder.InsertReplaceText(item.Key, item.Value); } Microsoft.Office.Interop.Word.Table table = wordBuilder.InsertTable("BOOKMARK_TABLE", dt.Rows.Count + 1, 12, 0); wordBuilder.SetParagraph_Table(table, 0, 0); wordBuilder.SetFont_Table(table, string.Empty, 10); wordBuilder.InsertCell(table, 1, 1, "序号"); wordBuilder.InsertCell(table, 1, 2, "汽车生产企业"); wordBuilder.InsertCell(table, 1, 3, "车辆型号"); wordBuilder.InsertCell(table, 1, 4, "燃料种类"); wordBuilder.InsertCell(table, 1, 5, "整车整备质量"); wordBuilder.InsertCell(table, 1, 6, "变速器型式"); wordBuilder.InsertCell(table, 1, 7, "座位排数"); wordBuilder.InsertCell(table, 1, 8, "纯电动驱动模式综合工况续驶里程"); wordBuilder.InsertCell(table, 1, 9, "车型燃料消耗量目标值①"); wordBuilder.InsertCell(table, 1, 10, "综合工况燃烧消耗量实际值②"); wordBuilder.InsertCell(table, 1, 11, "实际生产/进口量③"); wordBuilder.InsertCell(table, 1, 12, "备注"); for (int i = 0; i < dt.Rows.Count; i++) { table.Cell(i + 2, 1).Range.Text = (i + 1).ToString(); table.Cell(i + 2, 2).Range.Text = dt.Rows[i]["Qcscqy"].ToString(); table.Cell(i + 2, 3).Range.Text = dt.Rows[i]["Clxh"].ToString(); table.Cell(i + 2, 4).Range.Text = dt.Rows[i]["Rllx"].ToString(); table.Cell(i + 2, 5).Range.Text = dt.Rows[i]["Zczbzl"].ToString(); table.Cell(i + 2, 6).Range.Text = dt.Rows[i]["Bsqxs"].ToString(); table.Cell(i + 2, 7).Range.Text = dt.Rows[i]["Zwps"].ToString(); table.Cell(i + 2, 8).Range.Text = dt.Rows[i]["Zhgkxslc"].ToString(); table.Cell(i + 2, 9).Range.Text = dt.Rows[i]["TgtZhgkrlxhl"].ToString(); table.Cell(i + 2, 10).Range.Text = dt.Rows[i]["ActZhgkrlxhl"].ToString(); table.Cell(i + 2, 11).Range.Text = dt.Rows[i]["Sl_act"].ToString(); } string tempWordName = String.Format("{0}\\tempYear1.doc", DefaultDirectory.TempDoc); wordBuilder.SaveDocument(tempWordName); return(tempWordName); }
//弹出提示框,给工作人员名单 public WordHelper SetReportBasicInfo(bool isManul) { Dictionary <string, string> dict = new Dictionary <string, string>(); helper.CreateNewDocument(this.模板路径); string 人员名字 = "我是谁"; if (isManul) { //窗口获取实验人员信息 GetInformation Inf = new GetInformation("请输入实验人员的姓名"); 人员名字 = Inf.ShowDialog() == DialogResult.OK && Inf.Value.Length > 0 ? Inf.Value : "XXXX"; } dict.Add("$人员$", 人员名字); dict.Add("$日期$", DateTime.Now.ToLongDateString()); dict.Add("$试验持续时间$", this.测试试验时间.ToString() + "s"); dict.Add("$试验最大压力$", this.试验最大压力.ToString() + "MPa"); helper.InserttextValue(dict); return(helper); }
//生成Word private static void createWord(string TemplatePath, string imagePath, Dictionary <string, string> dic, string SavePath, System.Data.DataTable dt) { WordHelper wordBuilder = new WordHelper(); wordBuilder.CreateNewDocument(TemplatePath); foreach (var item in dic) { wordBuilder.InsertReplaceText(item.Key, item.Value); } if (!string.IsNullOrEmpty(imagePath)) { wordBuilder.InsertPicture("BOOKMARK_SIGNATURE", imagePath, 100, 100); } Microsoft.Office.Interop.Word.Table table = wordBuilder.InsertTable("BOOKMARK_TABLE", dt.Rows.Count + 1, 10, 0); wordBuilder.SetParagraph_Table(table, 0, 0); wordBuilder.SetFont_Table(table, string.Empty, 10, 0); table.Cell(1, 1).Range.Text = "序号"; table.Cell(1, 2).Range.Text = "备案号(VIN)"; table.Cell(1, 3).Range.Text = "车辆型号"; table.Cell(1, 4).Range.Text = "通用名称"; table.Cell(1, 5).Range.Text = "燃料种类"; table.Cell(1, 6).Range.Text = "综合工况燃料消耗量"; table.Cell(1, 7).Range.Text = "整车整备质量"; table.Cell(1, 8).Range.Text = "变速器型式"; table.Cell(1, 9).Range.Text = "座位排数"; table.Cell(1, 10).Range.Text = "操作类型"; for (int i = 0; i < dt.Rows.Count; i++) { wordBuilder.InsertCell(table, i + 2, 1, (i + 1).ToString()); for (int j = 2; j < 10; j++) { wordBuilder.InsertCell(table, i + 2, j, dt.Rows[i][j - 1].ToString()); } wordBuilder.InsertCell(table, i + 2, 10, dt.Rows[i][12].ToString()); } wordBuilder.SaveDocument(SavePath); }
//生成预报告 private void btnProduce_ItemClick(object sender, ItemClickEventArgs e) { DataTable dt = (DataTable)this.gcParam.DataSource; if (dt == null) { MessageBox.Show("无核算结果", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (dt.Rows.Count > 0) { // SaveFileDialog saveFileDialog = new SaveFileDialog() { Title = "生成Word", Filter = "Word文件(*.doc)|*.docx" }; DialogResult dialogResult = saveFileDialog.ShowDialog(this); if (dialogResult == DialogResult.OK) { try { SplashScreenManager.ShowForm(typeof(DevWaitForm)); List <CafcService.FuelCafcAndTcafc> cafcData = new List <CafcService.FuelCafcAndTcafc>(); if (Convert.ToInt32(this.comboBoxEdit1.Text) > 2015) { var data = Utils.serviceCafc.QueryForeCastNECafc(Utils.userId, Utils.password, "prj_" + Utils.userId); if (data != null && data.Length > 0) { cafcData = data.ToList(); } } else { var data = Utils.serviceCafc.QueryForeCastTECafc(Utils.userId, Utils.password, "prj_" + Utils.userId); if (data != null && data.Length > 0) { cafcData = data.ToList(); } } if (cafcData.Count > 0) { Dictionary <string, string> datas = new Dictionary <string, string>(); datas.Add("{qymc}", Utils.qymc); datas.Add("{year}", comboBoxEdit1.Text); datas.Add("{count}", cafcData[0].Sl_act.ToString()); datas.Add("{tcafc}", cafcData[0].Tcafc.ToString()); datas.Add("{cafc}", cafcData[0].Cafc.ToString()); decimal percent = (cafcData[0].Tcafc - cafcData[0].Cafc) / cafcData[0].Tcafc; percent = percent * 10; percent = Math.Round(percent, 1, MidpointRounding.ToEven); datas.Add("{percent}", percent.ToString()); WordHelper wordBuilder = new WordHelper(); wordBuilder.CreateNewDocument(forecast); foreach (var item in datas) { wordBuilder.InsertReplaceText(item.Key, item.Value); } wordBuilder.SaveDocument(saveFileDialog.FileName); if (MessageBox.Show("生成成功,是否打开文件?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { System.Diagnostics.Process.Start(saveFileDialog.FileName); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } finally { SplashScreenManager.CloseForm(); } } } else { MessageBox.Show("请导入预测车型", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
public override void SaveReportToDB() { WordHelper wordh = new WordHelper(); wordh.CreateNewDocument(模板路径); 保存路径 = 路径 + "\\report\\机动换向阀试验报告.doc"; Dict.Add("$项目$", "机动换向阀试验"); Dict.Add("$人员$", "章晓伟"); Dict.Add("$日期$", "12月19日"); wordh.InserttextValue(Dict);//写入文本 foreach (TestType tt in 实验类型) { if (tt == TestType.耐压试验) { Dict.Add("$P$", "20"); Dict.Add("$T$", "20"); Dict.Add("$A$", "20"); Dict.Add("$B$", "20"); wordh.InserttextValue(Dict);//写入文本 } if (tt == TestType.稳态压差流量特性试验) { 图片路径 = 路径 + "\\report\\机动换向阀稳态压差流量特性试验曲线.bmp"; Pict.Add("$稳态压差流量特性曲线$", 图片路径); 稳态流量1d = Array.ConvertAll(稳态流量1.ToArray(), new Converter <float, double>(FloatToDouble)); 稳态压力1d = Array.ConvertAll(稳态压力1.ToArray(), new Converter <float, double>(FloatToDouble)); 稳态流量2d = Array.ConvertAll(稳态流量2.ToArray(), new Converter <float, double>(FloatToDouble)); 稳态压力2d = Array.ConvertAll(稳态压力2.ToArray(), new Converter <float, double>(FloatToDouble)); double 最大值x = (稳态流量1d.Max()) > (稳态流量2d.Max()) ? (稳态流量1d.Max()) : (稳态流量2d.Max()); double 最大值y = (稳态压力1d.Max()) > (稳态压力2d.Max()) ? (稳态压力1d.Max()) : (稳态压力2d.Max()); List <double[]> args = new List <double[]> { 稳态流量1d, 稳态压力1d, 稳态流量2d, 稳态压力2d }; List <string> Curname = new List <string>() { "曲线1", "曲线2" }; ZedSave.SavePic(图片路径, "稳态压差流量特性试验", "流量(L/min)", "压力(MPa)", 0, 最大值x, 0, 最大值y, args, Curname, true); 稳态压力1.Clear(); 稳态流量1.Clear(); 稳态压力2.Clear(); 稳态流量2.Clear(); Array.Clear(稳态流量1d, 0, 稳态流量1d.Length); Array.Clear(稳态压力1d, 0, 稳态压力1d.Length); Array.Clear(稳态流量2d, 0, 稳态流量2d.Length); Array.Clear(稳态压力2d, 0, 稳态压力2d.Length); } else if (tt == TestType.内部泄漏试验) { 图片路径 = 路径 + "\\report\\机动换向阀内部泄漏试验曲线.bmp"; Pict.Add("$内部泄漏试验曲线$", 图片路径); 泄露流量1d = Array.ConvertAll(泄露流量1.ToArray(), new Converter <float, double>(FloatToDouble)); 泄露压力1d = Array.ConvertAll(泄露压力1.ToArray(), new Converter <float, double>(FloatToDouble)); double 最大值x = 泄露流量1d.Max(); double 最大值y = 泄露压力1d.Max(); List <double[]> args = new List <double[]> { 泄露流量1d, 泄露压力1d }; List <string> Curname = new List <string>() { "曲线1" }; ZedSave.SavePic(图片路径, "内部泄漏试验", "流量(L/min)", "压力(MPa)", 0, 最大值x, 0, 最大值y, args, Curname, true); 泄露流量1.Clear(); 泄露压力1.Clear(); Array.Clear(泄露流量1d, 0, 泄露流量1d.Length); Array.Clear(泄露压力1d, 0, 泄露压力1d.Length); } } wordh.Insertpicture(Pict);//写入图片 wordh.SaveDocument(保存路径); MessageBox.Show("报告已生成"); }