using System.Windows.Forms;
using System.Xml;
using Msword = Microsoft.Office.Interop.Word;
private void dy_Click(object sender, EventArgs e)
{
Form f1 = dy.FindForm();
int gx = f1.Location.X;
int gy = f1.Location.Y;
int gw = f1.Width;
int gh = f1.Height;
int gleft = f1.Location.X;
// MessageBox.Show(gx.ToString() + ";" + gy.ToString() + ";" + gw.ToString() + ";" + gh.ToString() + ";" + gleft.ToString() + ";");
screenshut(0, 0, gw, gh, 0, 0);
string pname = "项目名称:" + label4.Text;
string cname = "单位名称:"+dw.Text;
string lx = "抽取类型:" + label8.Text;
string xm = "抽取人姓名:"+label5.Text;
string dh = "联系电话:"+label6.Text;
string pid ="身份证号:" +label7.Text;
string time1 = "抽取时间:"+label15.Text;
string jg = "抽取结果:"+label2.Text;
wordapp = new Msword.Application();
wordapp.DisplayAlerts = Msword.WdAlertLevel.wdAlertsNone;
wordapp.Visible = true;
object missing = System.Reflection.Missing.Value;
string path = System.AppDomain.CurrentDomain.BaseDirectory + "2020.doc"; ///???
object templatename = path;
// MessageBox.Show(path);
object dir = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\"+dw.Text+".doc";
object format = Msword.WdSaveFormat.wdFormatDocument;
worddoc = wordapp.Documents.Add(ref templatename, ref missing, ref missing, ref missing);
// PromptSelectionOptions pso = new PromptSelectionOptions();
string strcon = "抽取结果确认表\n";
worddoc.Paragraphs.Last.Range.Font.Name = "黑体";
worddoc.Paragraphs.Last.Range.Font.Bold = 1;
worddoc.Paragraphs.Last.Range.Font.Size = 18;
wordapp.Selection.ParagraphFormat.LineSpacingRule = Microsoft.Office.Interop.Word.WdLineSpacing.wdLineSpaceDouble;
worddoc.Paragraphs.Alignment = Msword.WdParagraphAlignment.wdAlignParagraphLeft;
worddoc.Paragraphs.Last.Range.Text = strcon;
object unit = Msword.WdUnits.wdStory;
object count = 2;
wordapp.Selection.ParagraphFormat.Alignment = Msword.WdParagraphAlignment.wdAlignParagraphCenter;
wordapp.Selection.EndKey(ref unit, ref missing);
wordapp.Selection.MoveEnd(unit, missing);
wordapp.Selection.Font.Size = 11;
wordapp.Selection.Font.Bold = 0;
wordapp.Selection.Font.Name = "宋体";
wordapp.Selection.TypeText(lx);
wordapp.Selection.TypeText("\n");
wordapp.Selection.TypeText(pname);
wordapp.Selection.TypeText("\n");
wordapp.Selection.TypeText(cname);
wordapp.Selection.TypeText("\n");
wordapp.Selection.TypeText(xm);
wordapp.Selection.TypeText("\n");
wordapp.Selection.TypeText(pid);
wordapp.Selection.TypeText("\n");
wordapp.Selection.TypeText(dh);
wordapp.Selection.TypeText("\n");
wordapp.Selection.TypeText(time1);
wordapp.Selection.TypeText("\n");
wordapp.Selection.TypeText(jg);
wordapp.Selection.TypeText("\n");
wordapp.Selection.ParagraphFormat.Alignment = Msword.WdParagraphAlignment.wdAlignParagraphRight;
wordapp.Selection.TypeText("抽取人签字:____________________");
wordapp.Selection.TypeText("\n");
wordapp.Selection.TypeText("日期:____________________");
wordapp.Selection.TypeText("\n");
wordapp.Selection.ParagraphFormat.Alignment = Msword.WdParagraphAlignment.wdAlignParagraphLeft;
wordapp.Selection.TypeText("抽取结果截图:");
wordapp.Selection.TypeText("\n");
object rang2 = worddoc.Paragraphs.Last.Range;
object linktofile = false;
object savewdoc = true;
worddoc.InlineShapes.AddPicture(filepath, ref linktofile, ref savewdoc, ref rang2);
worddoc.SaveAs(ref dir, ref format, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
qr.Visible = true;
}