c# 通过界面上填写的信息输出到对应的word中,并另存为一个新的文件
c# 通过界面上填写的信息输出到对应的word中,并另存为一个新的文件
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using MSWord = Microsoft.Office.Interop.Word;
using System.IO;
using System.Runtime.InteropServices;
using System.Reflection;
using Microsoft.Office.Interop.Word;
namespace _10_输出房地一体资料
{
public partial class Form1 : Form
{
public Form1(){InitializeComponent();bdcdyh.Text = "";zl.Text = "";qlrmc.Text = "";dhhm.Text = "";zjh.Text = "";zcs.Text = "3";zdmj.Text = "160.62";jzzdmj.Text = "160.62";jzmj.Text = "425.42";cwh.Text = "";szb.Text = "";szd.Text = "";szn.Text = "空地";szx.Text = "空地";txdz.Text = "";fwjg.Text = "钢筋混凝土";jgsj.Text = "2008年07月09日";zjsj.Text = "2008年07月09日";}private void button1_Click(object sender, EventArgs e){string bdcdyh1 = bdcdyh.Text;string zl1 = zl.Text;string qlrmc1 = qlrmc.Text;string dhhm1 = dhhm.Text;string zjh1 = zjh.Text;string zcs1 = zcs.Text;string zdmj1 = zdmj.Text;string jzzdmj1 = jzzdmj.Text;string jzmj1 = jzmj.Text;string cwh1 = cwh.Text;string szb1 = szb.Text;string szd1 = szd.Text;string szn1 = szn.Text;string szx1 = szx.Text;string txdz1 = txdz.Text;string fwjg1 = fwjg.Text;string jgsj1 = jgsj.Text;string zjsj1 = zjsj.Text;output_sqb(bdcdyh1, qlrmc1, zl1, dhhm1, zjh1, jgsj1, zdmj1);}private void output_sqb(string bdcdyh1, string qlrmc1, string zl1, string dhhm1, string zjh1, string jgsj1, string zdmj1){bdcdyh.Text = bdcdyh1 + "ye";object path;string strContent;MSWord.Application wordApp;MSWord.Document wordDoc;path = @"D:\2-python\10-精测房地数据转换程序\源代码\temp\updatefdyt\不动产调查登记申请表 - 副本.docx";wordApp = new MSWord.Application(); //初始化wordApp.Visible = false;//使文档可见Object Nothing = Missing.Value;wordDoc = wordApp.Documents.Add(path);var table = wordDoc.Tables[3] as Table;table.Cell(1,2).Range.Text = bdcdyh1.Substring(0,19);table.Cell(1,4).Range.Text = bdcdyh1.Substring(0, 19);table.Cell(2, 2).Range.Text = bdcdyh1;table.Cell(6, 4).Range.Text = dhhm1;table.Cell(11, 2).Range.Text = zl1;//写入权利人信息string[] list_qlrmc = qlrmc1.Split('、');string[] list_zjh = zjh1.Split('、');for (int i = 0; i < list_qlrmc.Length; i++){if (i == 4) break;if (i==0){table.Cell(3, 2).Range.Text = list_qlrmc[i];table.Cell(5, 4).Range.Text = list_zjh[i];}else{table.Cell(15 + i, 2).Range.Text = list_qlrmc[i];table.Cell(15 + i, 3).Range.Text = "个人";table.Cell(15 + i, 4).Range.Text = "身份证";table.Cell(15 + i, 5).Range.Text = list_zjh[i];}}table.Cell(21, 4).Range.Text = zdmj1;table.Cell(21, 6).Range.Text = jgsj1;wordDoc.SaveAs("D:\\2-python\\10-精测房地数据转换程序\\源代码\\temp\\updatefdyt\\Test.docx");wordApp.Quit();//bdcdyh.Text = str1;}private void button2_Click(object sender, EventArgs e){}private void dhhm_TextChanged(object sender, EventArgs e){}
}
}