コード例 #1
0
ファイル: CarExamControl.cs プロジェクト: junbao520/DXA
        public string  GenerateWordAndPrint(PrintScoreModel model)
        {
            WriteIntoWord wiw = null;

            wiw = new WriteIntoWord();
            var path = System.IO.Directory.GetCurrentDirectory() + "\\" + "PrintTemplate.dotx";

            wiw.CreateNewDocument(path);


            wiw.WriteIntoDocument(TemplateBookMarkName.name, model.Name);
            wiw.WriteIntoDocument(TemplateBookMarkName.IdCard, model.IDCard);
            // wiw.WriteIntoDocument(TemplateBookMarkName.businessType, model.BusinessType);
            wiw.WriteIntoDocument(TemplateBookMarkName.examDate, model.ExamDate);
            // wiw.WriteIntoDocument(TemplateBookMarkName.examAddress, "华山驾校十区一号线");
            wiw.WriteIntoDocument(TemplateBookMarkName.firstExamTime, model.FirstExam.ExamTime);
            wiw.WriteIntoDocument(TemplateBookMarkName.firstExamBreakeRule, model.FirstExam.DedictionRules);
            wiw.WriteIntoDocument(TemplateBookMarkName.firstExamScore, model.FirstExam.Score.ToString());

            wiw.WritePicIntoDocument(TemplateBookMarkName.IDCardImage, model.IDCardPath);
            wiw.WritePicIntoDocument(TemplateBookMarkName.firstExamFirstCapturePhoto, model.FirstExam.CaptureImageFirstPath);
            wiw.WritePicIntoDocument(TemplateBookMarkName.firstExamSecondCapturePhoto, model.FirstExam.CaptureImageSecondPath);
            wiw.WritePicIntoDocument(TemplateBookMarkName.firstExamThirdCapturePhoto, model.FirstExam.CaptureImageThirdPath);

            if (model.SecondExam != null)
            {
                wiw.WriteIntoDocument(TemplateBookMarkName.SecondExamTime, model.SecondExam.ExamTime);
                wiw.WriteIntoDocument(TemplateBookMarkName.SecondExamBreakeRule, model.SecondExam.DedictionRules);
                wiw.WriteIntoDocument(TemplateBookMarkName.SecondExamScore, model.SecondExam.Score.ToString());
                wiw.WritePicIntoDocument(TemplateBookMarkName.SecondExamFirstCapturePhoto, model.SecondExam.CaptureImageFirstPath);
                wiw.WritePicIntoDocument(TemplateBookMarkName.SecondExamSecondCapturePhoto, model.SecondExam.CaptureImageSecondPath);
                wiw.WritePicIntoDocument(TemplateBookMarkName.SecondExamThirdCapturePhoto, model.SecondExam.CaptureImageThirdPath);
            }

            //图片写入指定路径
            path = ReportCardPath + "\\" + model.IDCard + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".doc";
            wiw.Save_CloseDocument(path);

            if (IsPrint)
            {
                wiw.PrintWorld(path);
            }
            //Image=wiw.WordtoImage(path)[0];
            //ImagePath = ReportCardPath + "\\" + model.IDCard + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".jpg";
            // Image.Save(ImagePath, ImageFormat.Jpeg);
            return(path);
        }
コード例 #2
0
ファイル: FormTest.cs プロジェクト: junbao520/DXA_HSJX
        private void button2_Click(object sender, EventArgs e)
        {
            //ceshi
            var             picpath    = System.IO.Directory.GetCurrentDirectory() + "\\" + "capture.jpg";
            var             IdCardPath = System.IO.Directory.GetCurrentDirectory() + "\\" + "zp.bmp";
            PrintScoreModel model      = new PrintScoreModel();

            model.Name         = "鲍君";
            model.BusinessType = "初次申请";
            model.CarType      = "C1";
            model.ExamDate     = "2018-08-20";
            model.IDCard       = "5000227119111294612";
            model.IDCardPath   = IdCardPath;
            model.FirstExam    = new ExamMode();
            model.FirstExam.CaptureImageFirstPath = picpath;

            model.FirstExam.CaptureImageSecondPath = picpath;
            model.FirstExam.CaptureImageThirdPath  = picpath;
            model.FirstExam.DedictionRules         = "倒库不入";
            model.FirstExam.Score    = 0;
            model.FirstExam.ExamTime = "19:46:00-20:20:00";

            model.SecondExam = new ExamMode();
            model.SecondExam.CaptureImageFirstPath  = picpath;
            model.SecondExam.CaptureImageSecondPath = picpath;
            model.SecondExam.CaptureImageThirdPath  = picpath;
            model.SecondExam.Score          = 100;
            model.SecondExam.ExamTime       = "19:46:00-20:20:00";
            model.SecondExam.DedictionRules = "倒车前前保险杠未至于终端线上,不超过50厘米";


            model.SecondExam.CaptureImageSecondPath = picpath;
            WriteIntoWord wiw = null;

            wiw = new WriteIntoWord();
            var path = System.IO.Directory.GetCurrentDirectory() + "\\" + "PrintTemplate.dotx";

            wiw.CreateNewDocument(path);


            wiw.WriteIntoDocument(TemplateBookMarkName.name, model.Name);
            wiw.WriteIntoDocument(TemplateBookMarkName.IdCard, model.IDCard);
            wiw.WriteIntoDocument(TemplateBookMarkName.businessType, model.BusinessType);
            wiw.WriteIntoDocument(TemplateBookMarkName.examDate, model.ExamDate);
            wiw.WriteIntoDocument(TemplateBookMarkName.examAddress, "华山驾校十区一号线");
            wiw.WriteIntoDocument(TemplateBookMarkName.firstExamTime, model.FirstExam.ExamTime);
            wiw.WriteIntoDocument(TemplateBookMarkName.firstExamBreakeRule, model.FirstExam.DedictionRules);
            wiw.WriteIntoDocument(TemplateBookMarkName.firstExamScore, model.FirstExam.Score.ToString());

            wiw.WritePicIntoDocument(TemplateBookMarkName.IDCardImage, model.IDCardPath);
            wiw.WritePicIntoDocument(TemplateBookMarkName.firstExamFirstCapturePhoto, model.SecondExam.CaptureImageFirstPath);
            wiw.WritePicIntoDocument(TemplateBookMarkName.firstExamSecondCapturePhoto, model.SecondExam.CaptureImageSecondPath);
            wiw.WritePicIntoDocument(TemplateBookMarkName.firstExamThirdCapturePhoto, model.SecondExam.CaptureImageThirdPath);

            wiw.WriteIntoDocument(TemplateBookMarkName.SecondExamTime, model.SecondExam.ExamTime);
            wiw.WriteIntoDocument(TemplateBookMarkName.SecondExamBreakeRule, model.SecondExam.DedictionRules);
            wiw.WriteIntoDocument(TemplateBookMarkName.SecondExamScore, model.SecondExam.Score.ToString());


            wiw.WritePicIntoDocument(TemplateBookMarkName.SecondExamFirstCapturePhoto, model.SecondExam.CaptureImageFirstPath);
            wiw.WritePicIntoDocument(TemplateBookMarkName.SecondExamSecondCapturePhoto, model.SecondExam.CaptureImageSecondPath);
            wiw.WritePicIntoDocument(TemplateBookMarkName.SecondExamThirdCapturePhoto, model.SecondExam.CaptureImageThirdPath);
            path = System.IO.Directory.GetCurrentDirectory() + "\\" + "print" + ".doc";
            wiw.Save_CloseDocument(path);

            Document doc = new Document();

            doc.LoadFromFile(path);
            //convert to image
            //doc.BuiltinDocumentProperties.PageCount  word的页数,这个属性找了好久才找到啊,官方的demo没看到使用过这个属性。
            for (int i = 0; i < doc.BuiltinDocumentProperties.PageCount; i++)
            {
                System.Drawing.Image image = doc.SaveToImages(i, Spire.Doc.Documents.ImageType.Metafile);
                image.Save(i.ToString() + ".jpg", ImageFormat.Jpeg);
            }
            MessageBox.Show("成功");

            //然后 开始 打印
        }