public void LoadWordChecked()
{
if (templateType.GetN_Name(T_id, 1) == "")
{
MessageBox.Show(" 操作失败,没有相应的模板!"); // 判断是否有word模板
return;
}
string P_path = Pathq + templateType.GetN_Name(T_id,1) + ".docx";//获取到模板路径
File.Copy(P_path, newfilename);//复制一个模板到另一个路径中,newfilename是另一个路径值
Object filename = newfilename;
Object oMissing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Application wordapp = new Microsoft.Office.Interop.Word.Application();// word对象
Microsoft.Office.Interop.Word.Document doc = new Document();//Document 对象
doc = wordapp.Documents.Open(ref filename, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing);
try
{
DataSet ds = templateType.GetDateSet(T_id, E_xtena, 0);//业务方法,按个人需要 可有可无
foreach (InlineShape shape in doc.InlineShapes)
{
object groupName = shape.OLEFormat.Object.GetType().InvokeMember("GroupName", System.Reflection.BindingFlags.GetProperty, null, shape.OLEFormat.Object, null);//找到 checkBox分组的值
//找到checkBox的名字
object name = shape.OLEFormat.Object.GetType().InvokeMember("Name", System.Reflection.BindingFlags.GetProperty, null, shape.OLEFormat.Object, null);
//看 checkbox是否选择
object value = shape.OLEFormat.Object.GetType().InvokeMember("Value", System.Reflection.BindingFlags.GetProperty, null, shape.OLEFormat.Object, null);
#region 勾选Checkbox
try
{
if (ds.Tables[0].Rows.Count != 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
if (name.ToString().Equals(ds.Tables[0].Rows[i][5].ToString()))
break;
}
else if (ds.Tables[0].Rows[i][5].ToString().Contains(name.ToString()))
break;
}
}
}
else
{
}
}
catch (Exception ex)
{
throw ex;
}
#endregion
}
doc.Save();
doc.Close();
wordapp.Quit();
}
catch (Exception ex)
{
throw ex;
}
finally
{
foreach (System.Diagnostics.Process p in System.Diagnostics.Process.GetProcessesByName("WINWORD"))
{
p.Kill();
}
}
}
{
if (templateType.GetN_Name(T_id, 1) == "")
{
MessageBox.Show(" 操作失败,没有相应的模板!"); // 判断是否有word模板
return;
}
string P_path = Pathq + templateType.GetN_Name(T_id,1) + ".docx";//获取到模板路径
File.Copy(P_path, newfilename);//复制一个模板到另一个路径中,newfilename是另一个路径值
Object filename = newfilename;
Object oMissing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Application wordapp = new Microsoft.Office.Interop.Word.Application();// word对象
Microsoft.Office.Interop.Word.Document doc = new Document();//Document 对象
doc = wordapp.Documents.Open(ref filename, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing);
try
{
DataSet ds = templateType.GetDateSet(T_id, E_xtena, 0);//业务方法,按个人需要 可有可无
foreach (InlineShape shape in doc.InlineShapes)
{
object groupName = shape.OLEFormat.Object.GetType().InvokeMember("GroupName", System.Reflection.BindingFlags.GetProperty, null, shape.OLEFormat.Object, null);//找到 checkBox分组的值
//找到checkBox的名字
object name = shape.OLEFormat.Object.GetType().InvokeMember("Name", System.Reflection.BindingFlags.GetProperty, null, shape.OLEFormat.Object, null);
//看 checkbox是否选择
object value = shape.OLEFormat.Object.GetType().InvokeMember("Value", System.Reflection.BindingFlags.GetProperty, null, shape.OLEFormat.Object, null);
#region 勾选Checkbox
try
{
if (ds.Tables[0].Rows.Count != 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
if (name.ToString().Equals(ds.Tables[0].Rows[i][5].ToString()))
{
//如果上述条件成功 那么把这个checkBox控件选中 也是就是等于true
shape.OLEFormat.Object.GetType().InvokeMember("Value", System.Reflection.BindingFlags.SetProperty, null, shape.OLEFormat.Object, new object[] { "True" });break;
}
else if (ds.Tables[0].Rows[i][5].ToString().Contains(name.ToString()))
{
// 同上
shape.OLEFormat.Object.GetType().InvokeMember("Value", System.Reflection.BindingFlags.SetProperty, null, shape.OLEFormat.Object, new object[] { "True" });break;
}
}
}
else
{
}
}
catch (Exception ex)
{
throw ex;
}
#endregion
}
doc.Save();
doc.Close();
wordapp.Quit();
}
catch (Exception ex)
{
throw ex;
}
finally
{
foreach (System.Diagnostics.Process p in System.Diagnostics.Process.GetProcessesByName("WINWORD"))
{
p.Kill();
}
}
}